From owner-svn-src-head@freebsd.org Sun Jul 8 10:08:25 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 8CFA810319BB; Sun, 8 Jul 2018 10:08:25 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3E86F8D0C9; Sun, 8 Jul 2018 10:08:25 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 1B52B248F8; Sun, 8 Jul 2018 10:08:25 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w68A8OWD066860; Sun, 8 Jul 2018 10:08:24 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w68A8Oc7066859; Sun, 8 Jul 2018 10:08:24 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201807081008.w68A8Oc7066859@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Sun, 8 Jul 2018 10:08:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r336086 - head/usr.sbin/newsyslog X-SVN-Group: head X-SVN-Commit-Author: ed X-SVN-Commit-Paths: head/usr.sbin/newsyslog X-SVN-Commit-Revision: 336086 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 08 Jul 2018 10:08:25 -0000 Author: ed Date: Sun Jul 8 10:08:24 2018 New Revision: 336086 URL: https://svnweb.freebsd.org/changeset/base/336086 Log: 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. MFC after: 1 month Modified: head/usr.sbin/newsyslog/newsyslog.c Modified: head/usr.sbin/newsyslog/newsyslog.c ============================================================================== --- head/usr.sbin/newsyslog/newsyslog.c Sun Jul 8 07:42:58 2018 (r336085) +++ head/usr.sbin/newsyslog/newsyslog.c Sun Jul 8 10:08:24 2018 (r336086) @@ -271,6 +271,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; @@ -657,11 +658,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) { @@ -2349,14 +2347,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");