]> err.no Git - util-linux/commitdiff
agetty: check gethostname() return value
authorKarel Zak <kzak@redhat.com>
Fri, 29 Jun 2007 00:27:27 +0000 (02:27 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 29 Jun 2007 00:27:27 +0000 (02:27 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
login-utils/agetty.c

index c827103947f86458d98b79579ae968b0248ebc2e..b7ae536f0e397f774d0ce5f593757aafcc9382ff 100644 (file)
@@ -880,12 +880,11 @@ do_prompt(op, tp)
 
                  case 'o':
                   {
-                    char domainname[256];
+                    char domainname[HOST_NAME_MAX+1];
 #ifdef HAVE_GETDOMAINNAME
-                    getdomainname(domainname, sizeof(domainname));
-#else
-                    strcpy(domainname, "unknown_domain");
+                    if (getdomainname(domainname, sizeof(domainname)))
 #endif
+                        strcpy(domainname, "unknown_domain");
                     domainname[sizeof(domainname)-1] = '\0';
                     printf ("%s", domainname);
                   }
@@ -988,14 +987,11 @@ do_prompt(op, tp)
        (void) fclose(fd);
     }
 #endif
-#ifdef __linux__
-       {
-               char hn[MAXHOSTNAMELEN+1];
-
-               (void) gethostname(hn, MAXHOSTNAMELEN);
-               write(1, hn, strlen(hn));
-       }
-#endif         
+    {
+       char hn[HOST_NAME_MAX+1];
+       if (gethostname(hn, sizeof(hn)) == 0)
+           write(1, hn, strlen(hn));
+    }
     (void) write(1, LOGIN, sizeof(LOGIN) - 1); /* always show login prompt */
 }