Hello,
I add script call features to newsyslog. This adds a one field to
newsyslog.conf. When newsyslog processed log file, this can execute
arbitrary program.
Situation to assume:
* For the log file which cannot use signal.
* Cases to do statistical application for log file.
A sample entry of newsylog.conf:
# logfilename [owner:group] mode count size when [ZB] [/pid_file] [sig_num] [/program]
/var/log/foo.log bar:baz640 1 100 * Z - - /etc/foo.sh
'-' is usable as a filler of null field.
I used similar enhanced function from the past. I think that you can
apply this patch for 5-current. In addition, I can prepare a patch
for 4-stable if it is necessary.
I ask for testing and a review of the following patches.
Thanks.
--
Toshihiko ARAI
Index: newsyslog.8
===
RCS file: /home/ncvs/src/usr.sbin/newsyslog/newsyslog.8,v
retrieving revision 1.32
diff -u -r1.32 newsyslog.8
--- newsyslog.8 2001/07/30 15:17:17 1.32
+++ newsyslog.8 2001/09/30 08:54:07
@@ -76,7 +76,7 @@
Each line of the file contains information about a particular log file
that should be handled by
.Nm .
-Each line has five mandatory fields and four optional fields, with
+Each line has five mandatory fields and five optional fields, with
whitespace separating each field. Blank lines or lines beginning with
``#'' are ignored. The fields of the configuration file are as
follows:
@@ -294,12 +294,28 @@
.Ar signal_number
is sent the process id contained in this
file. This field must start with "/" in order to be recognized
-properly.
+properly. Same as
+.Ar flags
+field, you can use "-" for null field.
.It Ar signal_number
This optional field specifies
-the signal number will be sent to the daemon process.
+the signal number or signal name will be sent to the daemon process.
By default
-a SIGHUP will be sent.
+a SIGHUP will be sent. Same as
+.Ar flags
+field, you can use "-" for null field.
+.It Ar path_to_program
+This optional field specifies
+the path name of a script for postprocessing of log file.
+This field must be specified with full path.
+And a file must be execute permission by specified
+.Ar owner
+and
+.Ar group .
+When
+.Ar path_to_program
+is called, new log file is given to the first argument, and old
+log file is given to the second argument.
.El
.Sh OPTIONS
The following options can be used with
Index: newsyslog.c
===
RCS file: /home/ncvs/src/usr.sbin/newsyslog/newsyslog.c,v
retrieving revision 1.37
diff -u -r1.37 newsyslog.c
--- newsyslog.c 2001/07/31 16:25:55 1.37
+++ newsyslog.c 2001/10/08 14:09:19
@@ -38,6 +38,7 @@
#include
#include
+#include
#include
#include
#include
@@ -73,6 +74,7 @@
struct conf_entry {
char *log; /* Name of the log */
char *pid_file; /* PID file */
+ char *prog; /* Program for postprocessing */
int uid;/* Owner of log */
int gid;/* Group of log */
int numlogs;/* Number of logs to keep */
@@ -106,11 +108,13 @@
static void do_entry(struct conf_entry * ent);
static void PRS(int argc, char **argv);
static void usage(void);
-static void dotrim(char *log, const char *pid_file, int numdays, int falgs,
- int perm, int owner_uid, int group_gid, int sig);
+static void dotrim(char *log, const char *pid_file, const char *prog,
+ int numdays, int falgs, int perm, int owner_uid,
+ int group_gid, int sig);
static int log_trim(char *log);
static void compress_log(char *log);
static void bzcompress_log(char *log);
+static int post_prog(const char *prog, char *log, int owner_uid, int group_gid);
static int sizefile(char *file);
static int age_old_log(char *file);
static pid_t get_pid(const char *pid_file);
@@ -119,6 +123,7 @@
int group_gid);
static void createdir(char *dirpart);
static time_t parseDWM(char *s);
+static int signame_to_signum(char *sig);
int
main(int argc, char **argv)
@@ -200,7 +205,7 @@
else
pid_file = NULL;
}
- dotrim(ent->log, pid_file, ent->numlogs,
+ dotrim(ent->log, pid_file, ent->prog, ent->numlogs,
ent->flags, ent->permissions, ent->uid, ent->gid,
ent->sig);
} else {
@@ -460,34 +465,52 @@
if (q && *q) {
if (*q == '/')
working->pid_file = strdup(q);
- else if (isdigit(*q))
+ else if (isalnum(*q))
goto got_sig;
- else
-