From d1a3470951bf7b34d79444047381d9ed4d09db39 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 29 Jun 2007 02:27:27 +0200 Subject: [PATCH] agetty: check gethostname() return value Signed-off-by: Karel Zak --- login-utils/agetty.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) 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 */ } -- 2.39.5