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
This commit is contained in:
parent
7000c58871
commit
df76ac9951
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=327451
@ -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 @@ parse_file(FILE *cf, struct cflist *work_p, struct cflist *glob_p,
|
||||
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 @@ parse_file(FILE *cf, struct cflist *work_p, struct cflist *glob_p,
|
||||
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);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user