From: Karel Zak Date: Fri, 29 Jun 2007 00:27:27 +0000 (+0200) Subject: agetty: check gethostname() return value X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d1a3470951bf7b34d79444047381d9ed4d09db39;p=util-linux agetty: check gethostname() return value Signed-off-by: Karel Zak --- diff --git a/login-utils/agetty.c b/login-utils/agetty.c index c8271039..b7ae536f 100644 --- a/login-utils/agetty.c +++ b/login-utils/agetty.c @@ -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 */ }