Date: Sun, 31 Dec 2017 22:01:36 +0000 (UTC) From: Eitan Adler <eadler@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r327451 - head/usr.sbin/newsyslog Message-ID: <201712312201.vBVM1aUW064353@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: eadler Date: Sun Dec 31 22:01:36 2017 New Revision: 327451 URL: https://svnweb.freebsd.org/changeset/base/327451 Log: newsyslog: implement 'p' flag Implement the 'p' flag for newsyslog from NetBSD. This flag results in the first log file for a given file to not be compressed. While here, don't change file attributes during a no-op run PR: 162798 Submitted by: heas@shrubbery.net MFC After: 1 month Modified: head/usr.sbin/newsyslog/newsyslog.c head/usr.sbin/newsyslog/newsyslog.conf.5 Modified: head/usr.sbin/newsyslog/newsyslog.c ============================================================================== --- head/usr.sbin/newsyslog/newsyslog.c Sun Dec 31 21:36:42 2017 (r327450) +++ head/usr.sbin/newsyslog/newsyslog.c Sun Dec 31 22:01:36 2017 (r327451) @@ -132,6 +132,7 @@ __FBSDID("$FreeBSD$"); #define CE_CREATE 0x0100 /* Create the log file if it does not exist. */ #define CE_NODUMP 0x0200 /* Set 'nodump' on newly created log file. */ #define CE_PID2CMD 0x0400 /* Replace PID file with a shell command.*/ +#define CE_PLAIN0 0x0800 /* Do not compress zero'th history file */ #define CE_RFC5424 0x0800 /* Use RFC5424 format rotation message */ @@ -1316,6 +1317,9 @@ no_trimat: case 'n': working->flags |= CE_NOSIGNAL; break; + case 'p': + working->flags |= CE_PLAIN0; + break; case 'r': working->flags |= CE_PID2CMD; break; @@ -1341,7 +1345,6 @@ no_trimat: break; case 'f': /* Used by OpenBSD for "CE_FOLLOW" */ case 'm': /* Used by OpenBSD for "CE_MONITOR" */ - case 'p': /* Used by NetBSD for "CE_PLAIN0" */ default: errx(1, "illegal flag in config file -- %c", *q); @@ -1846,8 +1849,18 @@ do_rotate(const struct conf_entry *ent) else { /* XXX - Ought to be checking for failure! */ (void)rename(zfile1, zfile2); + change_attrs(zfile2, ent); + if (ent->compress && !strlen(logfile_suffix)) { + /* compress old rotation */ + struct zipwork_entry zwork; + + memset(&zwork, 0, sizeof(zwork)); + zwork.zw_conf = ent; + zwork.zw_fsize = sizefile(zfile2); + strcpy(zwork.zw_fname, zfile2); + do_zipwork(&zwork); + } } - change_attrs(zfile2, ent); } if (ent->numlogs > 0) { @@ -1896,12 +1909,15 @@ do_rotate(const struct conf_entry *ent) if (ent->pid_cmd_file != NULL) swork = save_sigwork(ent); if (ent->numlogs > 0 && ent->compress > COMPRESS_NONE) { - /* - * The zipwork_entry will include a pointer to this - * conf_entry, so the conf_entry should not be freed. - */ - free_or_keep = KEEP_ENT; - save_zipwork(ent, swork, ent->fsize, file1); + if (!(ent->flags & CE_PLAIN0) || + strcmp(&file1[strlen(file1) - 2], ".0") != 0) { + /* + * The zipwork_entry will include a pointer to this + * conf_entry, so the conf_entry should not be freed. + */ + free_or_keep = KEEP_ENT; + save_zipwork(ent, swork, ent->fsize, file1); + } } return (free_or_keep); Modified: head/usr.sbin/newsyslog/newsyslog.conf.5 ============================================================================== --- head/usr.sbin/newsyslog/newsyslog.conf.5 Sun Dec 31 21:36:42 2017 (r327450) +++ head/usr.sbin/newsyslog/newsyslog.conf.5 Sun Dec 31 22:01:36 2017 (r327451) @@ -21,7 +21,7 @@ .\" the suitability of this software for any purpose. It is .\" provided "as is" without express or implied warranty. .\" -.Dd May 19, 2017 +.Dd Dec 31, 2017 .Dt NEWSYSLOG.CONF 5 .Os .Sh NAME @@ -312,6 +312,8 @@ log file using .It Cm N indicates that there is no process which needs to be signaled when this log file is rotated. +.It Cm p +indicates that the zero-th rotated file should not be compressed. .It Cm R if this flag is set the .Xr newsyslog 8
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201712312201.vBVM1aUW064353>