On Fri, Jan 19, 2001 at 11:09:24PM +0100, Dag-Erling Smorgrav wrote:
> "Crist J. Clark" <[EMAIL PROTECTED]> 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 [EMAIL PROTECTED]
To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-current" in the body of the message