Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 17 Jan 1998 13:06:43 +1100 (EST)
From:      "Daniel O'Callaghan" <danny@panda.hilink.com.au>
To:        freebsd-hackers@FreeBSD.ORG
Subject:   2nd call for comments: New option for newsyslog
Message-ID:  <Pine.BSF.3.91.980117130322.29251K-100000@panda.hilink.com.au>

next in thread | raw e-mail | index | archive | help

I'm added a '-m' option to newsyslog which will allow it to process log 
files on a monthly basis.  The idea is that 'newsyslog -m' is run from 
/etc/monthly (or the periodic file which supersedes /etc/monthly).  
Putting an 'M' in the Interval field of a newsyslog.conf entry will cause 
it to be processed when newsyslog is run with '-m'.

This will allow PRs such as 1708 (1996/10/02) to be closed.

Does anyone have any comments, positive or negative, about this extension 
to newsyslog?  I'd like to get this reviewed and into 2.2.6.

Danny

/*  Daniel O'Callaghan                                                     */
/*  HiLink Internet <http://www.hilink.com.au/>;       danny@hilink.com.au  */
/*  FreeBSD - works hard, plays hard...                 danny@freebsd.org  */


--- newsyslog.c.orig	Wed Jan 14 15:47:26 1998
+++ newsyslog.c	Thu Jan 15 08:58:02 1998
@@ -22,7 +22,7 @@
 
 /*
  *      newsyslog - roll over selected logs at the appropriate time,
- *              keeping the a specified number of backup files around.
+ *              keeping the specified number of backup files around.
  */
 
 #ifndef lint
@@ -71,8 +71,9 @@
 #define CE_COMPACT 1            /* Compact the achived log files */
 #define CE_BINARY  2            /* Logfile is in binary, don't add */
                                 /* status messages */
-#define NONE -1
-        
+#define NONE    -1
+#define MONTHLY -2        
+
 struct conf_entry {
         char    *log;           /* Name of the log */
         int     uid;            /* Owner of log */
@@ -85,6 +86,7 @@
         struct conf_entry       *next; /* Linked list pointer */
 };
 
+int     do_monthly = 0;		/* Do monthly rollover */
 int     verbose = 0;            /* Print out what's going on */
 int     needroot = 1;           /* Root privs are necessary */
 int     noaction = 0;           /* Don't do anything, just show it */
@@ -155,8 +157,9 @@
                 if (verbose && (ent->hours > 0))
                         printf(" age (hr): %d [%d] ", modtime, ent->hours);
                 if (((ent->size > 0) && (size >= ent->size)) ||
-                    ((ent->hours > 0) && ((modtime >= ent->hours)
-                                        || (modtime < 0)))) {
+                    ((ent->hours > 0) && ((modtime >= ent->hours) || 
+			(modtime < 0))) ||
+		    (ent->hours == MONTHLY && do_monthly) ) {
                         if (verbose)
                                 printf("--> trimming log....\n");
                         if (noaction && !verbose) {
@@ -206,8 +209,11 @@
 	}
 
         optind = 1;             /* Start options parsing */
-        while ((c=getopt(argc,argv,"nrvf:t:")) !=  -1)
+        while ((c=getopt(argc,argv,"mnrvf:t:")) !=  -1)
                 switch (c) {
+		case 'm':
+			do_monthly++;	/* do monthly rollover */
+			break;
                 case 'n':
                         noaction++; /* This implies needroot as off */
                         /* fall through */
@@ -227,7 +233,7 @@
 
 static void usage()
 {
-        fprintf(stderr, "usage: newsyslog [-nrv] [-f config-file]\n");
+        fprintf(stderr, "usage: newsyslog [-mnrv] [-f config-file]\n");
         exit(1);
 }
 
@@ -316,14 +322,16 @@
                 if (isdigit(*q))
                         working->size = atoi(q);
                 else
-                        working->size = -1;
+                        working->size = NONE;
                 
                 q = parse = missing_field(sob(++parse),errline);
                 *(parse = son(parse)) = '\0';
                 if (isdigit(*q))
                         working->hours = atoi(q);
-                else
-                        working->hours = -1;
+                else if ( *q == 'M' || *q == 'm' )
+                        working->hours = MONTHLY;
+                else
+                        working->hours = NONE;
 
                 q = parse = sob(++parse); /* Optional field */
                 *(parse = son(parse)) = '\0';
@@ -473,7 +481,7 @@
         return(0);
 }
 
-/* Fork of /usr/ucb/compress to compress the old log file */
+/* Fork off COMPRESS_PROG to compress the old log file */
 static void compress_log(log)
         char    *log;
 {
--- newsyslog.8.orig	Wed Jan 14 15:47:34 1998
+++ newsyslog.8	Wed Jan 14 22:57:56 1998
@@ -25,7 +25,7 @@
 .Nd maintain system log files to manageable sizes
 .Sh SYNOPSIS
 .Nm newsyslog
-.Op Fl rnv
+.Op Fl mnrv
 .Op Fl f Ar config_file
 .Sh DESCRIPTION
 .Nm Newsyslog
@@ -89,7 +89,6 @@
 .Ar * ,
 then the size of the log file is not taken into account
 when determining when to trim the log file.
-of archives
 .It Ar interval
 When 
 .Ar interval
@@ -97,7 +96,14 @@
 replaced by a
 .Ar * ,
 then the number of hours since the last time the log was
-trimmed will not be taken into consideration.
+trimmed will not be taken into consideration.  If this field is 
+replaced by the letter 
+.Ar M ,
+then the log will be trimmed when 
+.Nm
+is run with the
+.Ar m 
+option.
 .It Ar flags
 This optional field specifies if the archive should have any
 special processing done to the archived log files.
@@ -124,11 +130,15 @@
 instead of
 .Pa /etc/newsyslog.conf
 for its configuration file.
-.It Fl v
-Place 
+.It Fl m
+Process logs with
+.Ar M
+in the 
+.Ar interval
+field.  
 .Nm
-in verbose mode.  In this mode it will print out each log and its
-reasons for either trimming that log or skipping it.
+should be run at the start of each month with this option, to
+perform monthly logfile trimming.
 .It Fl n
 Cause
 .Nm
@@ -142,6 +152,11 @@
 will not be able to send a HUP signal to
 .Xr syslogd 8
 so this option should only be used in debugging.
+.It Fl v
+Place 
+.Nm
+in verbose mode.  In this mode it will print out each log and its
+reasons for either trimming that log or skipping it.
 .El
 .Sh FILES
 .Bl -tag -width /etc/newsyslog.confxxxx -compact




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.3.91.980117130322.29251K-100000>