[PATCH 02/19] login: stop using MAXHOSTNAMELEN

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use the sysconf(_SC_HOST_NAME_MAX) to determine maximum length of a
hostname.

Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 login-utils/login.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/login-utils/login.c b/login-utils/login.c
index 8ae5266..8cf6865 100644
--- a/login-utils/login.c
+++ b/login-utils/login.c
@@ -109,7 +109,7 @@ struct login_context {
 	char		vcsan[VCS_PATH_MAX];
 #endif
 
-	char		thishost[MAXHOSTNAMELEN + 1];	/* this machine */
+	char		*thishost;			/* this machine */
 	char		*thisdomain;			/* this machine domain */
 	char		*hostname;			/* remote machine */
 	char		hostaddress[16];		/* remote address */
@@ -209,13 +209,13 @@ static void __attribute__ ((__noreturn__)) sleepexit(int eval)
 
 static const char *get_thishost(struct login_context *cxt, const char **domain)
 {
-	if (!*cxt->thishost) {
-		if (gethostname(cxt->thishost, sizeof(cxt->thishost))) {
+	if (!cxt->thishost) {
+		cxt->thishost = xmalloc(sizeof(char) * (sysconf(_SC_HOST_NAME_MAX) + 1));
+		if (gethostname(cxt->thishost, sysconf(_SC_HOST_NAME_MAX))) {
 			if (domain)
 				*domain = NULL;
 			return NULL;
 		}
-		cxt->thishost[sizeof(cxt->thishost) -1] = '\0';
 		cxt->thisdomain = strchr(cxt->thishost, '.');
 		if (cxt->thisdomain)
 			*cxt->thisdomain++ = '\0';
-- 
1.7.12.2

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux