Implement 'E' flag that prevents newsyslog from rotating empty log files.
This commit is contained in:
parent
9c8ef71e39
commit
3128aa54a9
|
@ -1,4 +1,4 @@
|
|||
.\" $NetBSD: newsyslog.8,v 1.41 2017/10/23 01:06:52 wiz Exp $
|
||||
.\" $NetBSD: newsyslog.8,v 1.42 2021/03/01 21:37:10 otis Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 1999, 2000 Andrew Doran <ad@NetBSD.org>
|
||||
.\" All rights reserved.
|
||||
|
@ -40,7 +40,7 @@
|
|||
.\"
|
||||
.\" from FreeBSD: newsyslog.8,v 1.14.2.1 1999/02/25 18:38:33 wollman Exp
|
||||
.\"
|
||||
.Dd June 16, 2012
|
||||
.Dd March 1, 2021
|
||||
.Dt NEWSYSLOG 8
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
@ -313,6 +313,13 @@ format: the ASCII message which
|
|||
inserts to indicate that the logs have been trimmed should not be included.
|
||||
.It Sy c
|
||||
Create an empty log file if none currently exists.
|
||||
.It Sy e
|
||||
Do not rotate log file with zero size (empty).
|
||||
This flag is mostly usable in conjunction with
|
||||
.Ar b
|
||||
flag that prevents
|
||||
.Nm
|
||||
from inserting an ASCII informational message.
|
||||
.It Sy n
|
||||
No signal should be sent when the log is trimmed.
|
||||
.It Sy p
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: newsyslog.c,v 1.61 2013/09/05 11:34:40 prlw1 Exp $ */
|
||||
/* $NetBSD: newsyslog.c,v 1.62 2021/03/01 21:37:10 otis Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999, 2000 Andrew Doran <ad@NetBSD.org>
|
||||
|
@ -55,7 +55,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: newsyslog.c,v 1.61 2013/09/05 11:34:40 prlw1 Exp $");
|
||||
__RCSID("$NetBSD: newsyslog.c,v 1.62 2021/03/01 21:37:10 otis Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <sys/types.h>
|
||||
|
@ -94,6 +94,7 @@ __RCSID("$NetBSD: newsyslog.c,v 1.61 2013/09/05 11:34:40 prlw1 Exp $");
|
|||
#define CE_PLAIN0 0x10 /* Do not compress zero'th history file */
|
||||
#define CE_SYSLPROTOCOL 0x20 /* log in syslog-protocol format,
|
||||
not configurable but detected at runtime */
|
||||
#define CE_NOEMPTY 0x40 /* Do not rotate empty log file */
|
||||
|
||||
struct conf_entry {
|
||||
uid_t uid; /* Owner of log */
|
||||
|
@ -372,6 +373,9 @@ parse_cfgline(struct conf_entry *log, FILE *fd, size_t *_lineno)
|
|||
case 'C':
|
||||
log->flags |= CE_CREATE;
|
||||
break;
|
||||
case 'E':
|
||||
log->flags |= CE_NOEMPTY;
|
||||
break;
|
||||
case 'N':
|
||||
log->flags |= CE_NOSIGNAL;
|
||||
break;
|
||||
|
@ -462,6 +466,14 @@ log_examine(struct conf_entry *log, int force)
|
|||
return;
|
||||
}
|
||||
|
||||
/* Skip rotation of empty log file when flag
|
||||
* E is specified
|
||||
*/
|
||||
if (sb.st_size == 0 && (log->flags & CE_NOEMPTY) != 0) {
|
||||
PRHDRINFO(("empty file --> skip log\n"));
|
||||
return;
|
||||
}
|
||||
|
||||
/* Size of the log file in kB. */
|
||||
size = ((size_t)sb.st_blocks * S_BLKSIZE) >> 10;
|
||||
|
||||
|
|
Loading…
Reference in New Issue