diff --git a/usr.bin/newsyslog/newsyslog.8 b/usr.bin/newsyslog/newsyslog.8 index 821cedfecb06..91df2fb77db8 100644 --- a/usr.bin/newsyslog/newsyslog.8 +++ b/usr.bin/newsyslog/newsyslog.8 @@ -3,7 +3,7 @@ .\" This file contains changes from the Open Software Foundation. .\" .\" from: @(#)newsyslog.8 -.\" $NetBSD: newsyslog.8,v 1.9 1999/10/05 12:11:27 ad Exp $ +.\" $NetBSD: newsyslog.8,v 1.10 1999/10/06 13:26:28 ad Exp $ .\" .\" Copyright 1988, 1989 by the Massachusetts Institute of Technology .\" @@ -77,6 +77,8 @@ follows: archive interval .br flags (optional) +.br + path to pid file (optional) .PP The .I logfile name @@ -126,6 +128,13 @@ means that the file is a binary file, and so the ascii message which inserts to indicate the fact that the logs have been turned over should not be included. .PP +The +.I path to pid file +entry specifies a file to read to obtain the daemon process ID. If found, a +hang-up (SIGHUP) signal will be sent to this process after the log file is +trimmed. By default the signal is sent to +.IR syslogd . +.PP .SH OPTIONS The following options can be used with newsyslog: .TP @@ -152,7 +161,8 @@ removes the restriction that must be running as root. Of course, .I newsyslog will not be able to send a HUP signal to -.IR syslogd , +.IR syslogd +(or other daemons not owned by the user), so this option should only be used in debugging. .SH FILES /etc/newsyslog.conf diff --git a/usr.bin/newsyslog/newsyslog.c b/usr.bin/newsyslog/newsyslog.c index ebb838652316..cdf5b934bd4a 100644 --- a/usr.bin/newsyslog/newsyslog.c +++ b/usr.bin/newsyslog/newsyslog.c @@ -1,4 +1,4 @@ -/* $NetBSD: newsyslog.c,v 1.19 1999/10/05 12:11:28 ad Exp $ */ +/* $NetBSD: newsyslog.c,v 1.20 1999/10/06 13:26:28 ad Exp $ */ /* * This file contains changes from the Open Software Foundation. @@ -29,7 +29,7 @@ provided "as is" without express or implied warranty. #include #ifndef lint -__RCSID("$NetBSD: newsyslog.c,v 1.19 1999/10/05 12:11:28 ad Exp $"); +__RCSID("$NetBSD: newsyslog.c,v 1.20 1999/10/06 13:26:28 ad Exp $"); #endif /* not lint */ #ifndef CONF @@ -81,7 +81,8 @@ struct conf_entry { int size; /* Size cutoff to trigger trimming the log */ int hours; /* Hours between log trimming */ int permissions; /* File permissions on the log */ - int flags; /* Flags (CE_COMPACT & CE_BINARY) */ + int flags; /* Flags (CE_COMPACT & CE_BINARY) */ + char *pidfile; /* Name of file containing PID to signal */ struct conf_entry *next; /* Linked list pointer */ }; @@ -101,7 +102,7 @@ char *daytime; /* timenow in human readable form */ void PRS __P((int, char **)); int age_old_log __P((char *)); void compress_log __P((char *)); -void dotrim __P((char *, int, int, int, int, int)); +void dotrim __P((char *, int, int, int, int, int, char *)); void do_entry __P((struct conf_entry *)); int isnumber __P((char *)); int log_trim __P((char *)); @@ -171,7 +172,8 @@ do_entry(ent) ent->log,ent->numlogs); } dotrim(ent->log, ent->numlogs, ent->flags, - ent->permissions, ent->uid, ent->gid); + ent->permissions, ent->uid, ent->gid, + ent->pidfile); } else { if (verbose) printf("--> skipping\n"); @@ -364,6 +366,12 @@ parse_file() } q++; } + + if ((q = parse = sob(++parse)) != NULL && q[0] != '\0') { + *(parse = son(parse)) = '\0'; + working->pidfile = strdup(q); + } else + working->pidfile = NULL; free(errline); } @@ -386,19 +394,23 @@ missing_field(p,errline) } void -dotrim(log,numdays,flags,perm,owner_uid,group_gid) +dotrim(log,numdays,flags,perm,owner_uid,group_gid,pidfile) char *log; int numdays; int flags; int perm; int owner_uid; int group_gid; + char *pidfile; { char file1[128], file2[128]; char zfile1[128], zfile2[128]; + char line[BUFSIZ]; int fd; struct stat st; int ngen = numdays; + FILE *f; + pid_t pid; #ifdef _IBMR2 /* AIX 3.1 has a broken fchown- if the owner_uid is -1, it will actually */ @@ -408,6 +420,20 @@ dotrim(log,numdays,flags,perm,owner_uid,group_gid) owner_uid = geteuid(); #endif + if (pidfile != NULL && pidfile[0] != '\0') { + if ((f = fopen(pidfile,"r")) == NULL) { + (void) fprintf(stderr,"%s: ",progname); + perror(conf); + return; + } + + if (fgets(line,BUFSIZ,f)) + pid = atoi(line); + if (f) + (void)fclose(f); + } else + pid = syslog_pid; + /* Remove oldest log */ (void) sprintf(file1,"%s.%d",log,numdays); (void) strcpy(zfile1, file1); @@ -481,14 +507,14 @@ dotrim(log,numdays,flags,perm,owner_uid,group_gid) else (void) chmod(log,perm); if (noaction) - printf("kill -HUP %d (syslogd)\n",syslog_pid); + printf("kill -HUP %d\n",pid); else - if (syslog_pid < MIN_PID || syslog_pid > MAX_PID) { + if (pid < MIN_PID || pid > MAX_PID) { fprintf(stderr,"%s: preposterous process number: %d\n", - progname, syslog_pid); - } else if (kill(syslog_pid,SIGHUP)) { + progname, pid); + } else if (kill(pid,SIGHUP)) { fprintf(stderr,"%s: ",progname); - perror("warning - could not restart syslogd"); + perror("warning - could not restart daemon"); } if (flags & CE_COMPACT) { if (noaction)