Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 20 Jan 2001 17:01:55 -0800
From:      "Crist J. Clark" <cjclark@reflexnet.net>
To:        Dag-Erling Smorgrav <des@ofug.org>
Cc:        FreeBSD-gnats-submit@FreeBSD.ORG, current@FreeBSD.ORG
Subject:   Re: bin/24444: syslogd(8) does not update hostname
Message-ID:  <20010120170155.K10761@rfx-216-196-73-168.users.reflex>
In-Reply-To: <xzp4ryvtcrv.fsf@flood.ping.uio.no>; from des@ofug.org on Fri, Jan 19, 2001 at 11:09:24PM %2B0100
References:  <200101190330.f0J3UPa75677@rfx-216-196-73-168.users.reflexcom.com> <xzphf2v22vu.fsf@flood.ping.uio.no> <20010119110341.A7958@rfx-216-196-73-168.users.reflex> <xzp4ryvtcrv.fsf@flood.ping.uio.no>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, Jan 19, 2001 at 11:09:24PM +0100, Dag-Erling Smorgrav wrote:
> "Crist J. Clark" <cjclark@reflexnet.net> writes:
> > On Fri, Jan 19, 2001 at 12:32:53PM +0100, Dag-Erling Smorgrav wrote:
> > > It should also log a message if the hostname changes.
> > Should that be a responsibility of syslogd(8) or hostname(1)?
> 
> I meant syslogd(8), but putting it in hostname(1) might makes sense,
> except that hostname(1) is not the only way to set the hostname
> ('sysctl -w kern.hostname=foo' is another)

How about just logging a sethostname(3) call?

But anyway, syslogd(8) does not track the state of any other system
parameters, I think asking syslogd(8) to notice a change in the
hostname on its own in a real-time fashion is beyond its scope.

That said, I agree that syslogd(8) making a note when its own idea of
the hostname changes would be useful. If one is analyzing logs, an
entry indicating that messages from a given machine no longer will be
labeled as coming from 'foo' but 'foobar' would be very helpful.

Patches, patches, patches:

--- usr.sbin/syslogd/syslogd.c	2001/01/18 08:06:34	1.1
+++ usr.sbin/syslogd/syslogd.c	2001/01/21 00:55:53	1.3
@@ -318,7 +318,7 @@
 	struct sockaddr_un sunx, fromunix;
 	struct sockaddr_storage frominet;
 	FILE *fp;
-	char *p, *hname, line[MAXLINE + 1];
+	char *hname, line[MAXLINE + 1];
 	struct timeval tv, *tvp;
 	struct sigaction sact;
 	sigset_t mask;
@@ -395,12 +395,6 @@
 
 	consfile.f_type = F_CONSOLE;
 	(void)strcpy(consfile.f_un.f_fname, ctty + sizeof _PATH_DEV - 1);
-	(void)gethostname(LocalHostName, sizeof(LocalHostName));
-	if ((p = strchr(LocalHostName, '.')) != NULL) {
-		*p++ = '\0';
-		LocalDomain = p;
-	} else
-		LocalDomain = "";
 	(void)strcpy(bootfile, getbootfile());
 	(void)signal(SIGTERM, die);
 	(void)signal(SIGINT, Debug ? die : SIG_IGN);
@@ -1340,10 +1334,23 @@
 	char cline[LINE_MAX];
  	char prog[NAME_MAX+1];
 	char host[MAXHOSTNAMELEN+1];
+	char oldLocalHostName[MAXHOSTNAMELEN+1];
+	char hostMsg[2*(MAXHOSTNAMELEN+1)+40];
 
 	dprintf("init\n");
 
 	/*
+	 * Load hostname (may have changed)
+	 */
+	strncpy(oldLocalHostName, LocalHostName, sizeof(LocalHostName));
+	(void)gethostname(LocalHostName, sizeof(LocalHostName));
+	if ((p = strchr(LocalHostName, '.')) != NULL) {
+		*p++ = '\0';
+		LocalDomain = p;
+	} else
+		LocalDomain = "";
+
+	/*
 	 *  Close all open log files.
 	 */
 	Initialized = 0;
@@ -1492,6 +1499,17 @@
 
 	logmsg(LOG_SYSLOG|LOG_INFO, "syslogd: restart", LocalHostName, ADDDATE);
 	dprintf("syslogd: restarted\n");
+	/*
+	 * Log a change in hostname, but only on a restart
+	 */
+	if ((signo != 0) &&
+	    (strncmp(oldLocalHostName, LocalHostName, sizeof(LocalHostName)) != 0)) {
+		snprintf(hostMsg, sizeof(hostMsg),
+			 "syslogd: hostname changed, \"%s\" to \"%s\"", 
+			 oldLocalHostName, LocalHostName);
+		logmsg(LOG_SYSLOG|LOG_INFO, hostMsg, LocalHostName, ADDDATE);
+		dprintf("%s\n", hostMsg);
+	}
 }
 
 /*


-- 
Crist J. Clark                           cjclark@alum.mit.edu


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010120170155.K10761>