From owner-freebsd-current Sat Jan 20 17: 2:25 2001 Delivered-To: freebsd-current@freebsd.org Received: from mailhost01.reflexnet.net (mailhost01.reflexnet.net [64.6.192.82]) by hub.freebsd.org (Postfix) with ESMTP id 8332A37B400; Sat, 20 Jan 2001 17:02:04 -0800 (PST) Received: from rfx-216-196-73-168.users.reflexcom.com ([216.196.73.168]) by mailhost01.reflexnet.net with Microsoft SMTPSVC(5.5.1877.197.19); Sat, 20 Jan 2001 17:00:17 -0800 Received: (from cjc@localhost) by rfx-216-196-73-168.users.reflexcom.com (8.11.1/8.11.0) id f0L11u923321; Sat, 20 Jan 2001 17:01:56 -0800 (PST) (envelope-from cjc) Date: Sat, 20 Jan 2001 17:01:55 -0800 From: "Crist J. Clark" To: Dag-Erling Smorgrav 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> Reply-To: cjclark@alum.mit.edu References: <200101190330.f0J3UPa75677@rfx-216-196-73-168.users.reflexcom.com> <20010119110341.A7958@rfx-216-196-73-168.users.reflex> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: ; from des@ofug.org on Fri, Jan 19, 2001 at 11:09:24PM +0100 Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Fri, Jan 19, 2001 at 11:09:24PM +0100, Dag-Erling Smorgrav wrote: > "Crist J. Clark" 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