summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2002-09-13 18:50:10 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2002-09-13 18:50:10 +0000
commit154d3c88f59c0493d48f24ed65e19d1c799e98eb (patch)
tree46ec84aa79aba72d7a83ac5081b1c5cfe23dd389
parent803f977c6adddf1a87eb6ec3bc3902aff175a071 (diff)
Don't rotate log files < 512 bytes unless in binary mode. This
prevents newsyslog from rotating a file that only contains the messages that the log file was turned over. deraadt@ OK
-rw-r--r--usr.bin/newsyslog/newsyslog.813
-rw-r--r--usr.bin/newsyslog/newsyslog.c14
2 files changed, 18 insertions, 9 deletions
diff --git a/usr.bin/newsyslog/newsyslog.8 b/usr.bin/newsyslog/newsyslog.8
index d105b3bfde2..eaa3ed33407 100644
--- a/usr.bin/newsyslog/newsyslog.8
+++ b/usr.bin/newsyslog/newsyslog.8
@@ -1,4 +1,4 @@
-.\" $OpenBSD: newsyslog.8,v 1.23 2002/09/13 01:12:55 millert Exp $
+.\" $OpenBSD: newsyslog.8,v 1.24 2002/09/13 18:50:09 millert Exp $
.\"
.\" Copyright (c) 1997, Jason Downs. All rights reserved.
.\"
@@ -157,13 +157,20 @@ Octal mode of created log files and archives.
.It number of archives
Specify the number of archives to be kept besides the log file itself.
.It size of archives
-When the size of the log file reaches this point, the log file becomes trimmed
-as described above.
+When the size of the log file (in kilobytes) reaches this point, the log
+file is trimmed as described above.
If this field is replaced by a
.Ql * ,
then the size of
the log file is not taken into account when determining when to trim the
log file.
+By default, files smaller than 512 bytes are not rotated unless the
+.Sq B
+(binary) flag is set.
+This prevents
+.Nm
+from rotating files consisting solely of a message indicating
+that the log file has been turned over.
.It archive interval
Specify the time separation between the trimming of the log file.
If this field is replaced by a
diff --git a/usr.bin/newsyslog/newsyslog.c b/usr.bin/newsyslog/newsyslog.c
index 81dbaaa7f08..5d846503851 100644
--- a/usr.bin/newsyslog/newsyslog.c
+++ b/usr.bin/newsyslog/newsyslog.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: newsyslog.c,v 1.48 2002/09/13 00:16:13 millert Exp $ */
+/* $OpenBSD: newsyslog.c,v 1.49 2002/09/13 18:50:09 millert Exp $ */
/*
* Copyright (c) 1999, 2002 Todd C. Miller <Todd.Miller@courtesan.com>
@@ -88,7 +88,7 @@ provided "as is" without express or implied warranty.
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: newsyslog.c,v 1.48 2002/09/13 00:16:13 millert Exp $";
+static const char rcsid[] = "$OpenBSD: newsyslog.c,v 1.49 2002/09/13 18:50:09 millert Exp $";
#endif /* not lint */
#ifndef CONF
@@ -136,6 +136,9 @@ static const char rcsid[] = "$OpenBSD: newsyslog.c,v 1.48 2002/09/13 00:16:13 mi
#define CE_FOLLOW 0x10 /* Follow symbolic links */
#define NONE -1
+#define MIN_PID 4 /* Don't touch pids lower than this */
+#define MIN_SIZE 512 /* Don't rotate if smaller than this */
+
struct conf_entry {
char *log; /* Name of the log */
uid_t uid; /* Owner of log */
@@ -163,7 +166,6 @@ int noaction = 0; /* Don't do anything, just show it */
int monitormode = 0; /* Don't do monitoring by default */
char *conf = CONF; /* Configuration file to use */
time_t timenow;
-#define MIN_PID 4
char hostname[MAXHOSTNAMELEN]; /* hostname */
char *daytime; /* timenow in human readable form */
@@ -292,9 +294,9 @@ do_entry(struct conf_entry *ent)
printf(" age (hr): %d [%d] ", modtime, ent->hours);
if (monitormode && ent->flags & CE_MONITOR)
domonitor(ent->log, ent->whom);
- if (!monitormode && (((ent->size > 0) && (size >= ent->size)) ||
- ((ent->hours > 0) && ((modtime >= ent->hours) ||
- (modtime < 0))))) {
+ if (!monitormode && ((ent->size > 0 && size >= ent->size) ||
+ (ent->hours > 0 && (modtime >= ent->hours || modtime < 0)
+ && ((ent->flags & CE_BINARY) || size >= MIN_SIZE)))) {
if (verbose)
printf("--> trimming log....\n");
if (noaction && !verbose)