From owner-svn-src-stable@freebsd.org Mon Aug 27 07:32:42 2018 Return-Path: Delivered-To: svn-src-stable@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 976C1108F89D; Mon, 27 Aug 2018 07:32:42 +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 44E7E827BB; Mon, 27 Aug 2018 07:32:42 +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 24D9A1A9FB; Mon, 27 Aug 2018 07:32:42 +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 w7R7Wgqs010909; Mon, 27 Aug 2018 07:32:42 GMT (envelope-from ed@FreeBSD.org) Received: (from ed@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w7R7WgjN010908; Mon, 27 Aug 2018 07:32:42 GMT (envelope-from ed@FreeBSD.org) Message-Id: <201808270732.w7R7WgjN010908@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ed set sender to ed@FreeBSD.org using -f From: Ed Schouten Date: Mon, 27 Aug 2018 07:32:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r338334 - stable/11/usr.sbin/newsyslog X-SVN-Group: stable-11 X-SVN-Commit-Author: ed X-SVN-Commit-Paths: stable/11/usr.sbin/newsyslog X-SVN-Commit-Revision: 338334 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 27 Aug 2018 07:32:42 -0000 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");