Author: ed
Date: Mon Aug 27 07:32:41 2018
New Revision: 338334
URL: https://svnweb.freebsd.org/changeset/base/338334

Log:
  MFC r336086:
  
    Use the FQDN in the newsyslog log message when RFC 5424 is enabled.
  
    The RFC 5424 spec mentions that logging FQDNs over short hostnames is
    preferred. Alter this code, so that the hostname doesn't get truncated
    on startup. Keep track of the length of the short hostname, so that
    fprintf() can do the truncation where necessary.

Modified:
  stable/11/usr.sbin/newsyslog/newsyslog.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/usr.sbin/newsyslog/newsyslog.c
==============================================================================
--- stable/11/usr.sbin/newsyslog/newsyslog.c    Mon Aug 27 03:42:19 2018        
(r338333)
+++ stable/11/usr.sbin/newsyslog/newsyslog.c    Mon Aug 27 07:32:41 2018        
(r338334)
@@ -254,6 +254,7 @@ static char daytime[DAYTIME_LEN];/* The current time i
 static char daytime_rfc5424[DAYTIME_RFC5424_LEN];
 
 static char hostname[MAXHOSTNAMELEN]; /* hostname */
+static size_t hostname_shortlen;
 
 static const char *path_syslogpid = _PATH_SYSLOGPID;
 
@@ -640,11 +641,8 @@ parse_args(int argc, char **argv)
 
        /* Let's get our hostname */
        (void)gethostname(hostname, sizeof(hostname));
+       hostname_shortlen = strcspn(hostname, ".");
 
-       /* Truncate domain */
-       if ((p = strchr(hostname, '.')) != NULL)
-               *p = '\0';
-
        /* Parse command line options. */
        while ((ch = getopt(argc, argv, "a:d:f:nrst:vCD:FNPR:S:")) != -1)
                switch (ch) {
@@ -2298,14 +2296,20 @@ log_trim(const char *logname, const struct conf_entry 
                }
        } else {
                if (log_ent->firstcreate)
-                       fprintf(f, "%s %s newsyslog[%d]: logfile first 
created%s\n",
-                           daytime, hostname, getpid(), xtra);
+                       fprintf(f,
+                           "%s %.*s newsyslog[%d]: logfile first created%s\n",
+                           daytime, (int)hostname_shortlen, hostname, getpid(),
+                           xtra);
                else if (log_ent->r_reason != NULL)
-                       fprintf(f, "%s %s newsyslog[%d]: logfile turned 
over%s%s\n",
-                           daytime, hostname, getpid(), log_ent->r_reason, 
xtra);
+                       fprintf(f,
+                           "%s %.*s newsyslog[%d]: logfile turned over%s%s\n",
+                           daytime, (int)hostname_shortlen, hostname, getpid(),
+                           log_ent->r_reason, xtra);
                else
-                       fprintf(f, "%s %s newsyslog[%d]: logfile turned 
over%s\n",
-                           daytime, hostname, getpid(), xtra);
+                       fprintf(f,
+                           "%s %.*s newsyslog[%d]: logfile turned over%s\n",
+                           daytime, (int)hostname_shortlen, hostname, getpid(),
+                           xtra);
        }
        if (fclose(f) == EOF)
                err(1, "log_trim: fclose");
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to