summaryrefslogtreecommitdiffstats
path: root/usr.sbin/newsyslog/newsyslog.c
diff options
context:
space:
mode:
authordelphij <delphij@FreeBSD.org>2010-01-20 01:07:38 +0000
committerdelphij <delphij@FreeBSD.org>2010-01-20 01:07:38 +0000
commitbf268284cce6c4d1d3fbd8d52be2340ef8d83629 (patch)
tree42f173683fe839ebb472b360d41a674fbe56fe26 /usr.sbin/newsyslog/newsyslog.c
parent863d5d126e582a5f41a69792ba1240089f22d17e (diff)
downloadFreeBSD-src-bf268284cce6c4d1d3fbd8d52be2340ef8d83629.zip
FreeBSD-src-bf268284cce6c4d1d3fbd8d52be2340ef8d83629.tar.gz
Add a new option, -P, which reverts newsyslog(8) to the old behavior,
which stops to proceed further, as it is possible that processes which fails to create PID file get screwed by rotation. Requested by: stas MFC after: 2 weeks X-MFC with: r200806
Diffstat (limited to 'usr.sbin/newsyslog/newsyslog.c')
-rw-r--r--usr.sbin/newsyslog/newsyslog.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c
index 0878978..4cadda4 100644
--- a/usr.sbin/newsyslog/newsyslog.c
+++ b/usr.sbin/newsyslog/newsyslog.c
@@ -167,6 +167,7 @@ int needroot = 1; /* Root privs are necessary */
int noaction = 0; /* Don't do anything, just show it */
int norotate = 0; /* Don't rotate */
int nosignal; /* Do not send any signals */
+int enforcepid = 0; /* If PID file does not exist or empty, do nothing */
int force = 0; /* Force the trim no matter what */
int rotatereq = 0; /* -R = Always rotate the file(s) as given */
/* on the command (this also requires */
@@ -580,7 +581,7 @@ parse_args(int argc, char **argv)
*p = '\0';
/* Parse command line options. */
- while ((ch = getopt(argc, argv, "a:d:f:nrsvCD:FNR:")) != -1)
+ while ((ch = getopt(argc, argv, "a:d:f:nrsvCD:FNPR:")) != -1)
switch (ch) {
case 'a':
archtodir++;
@@ -624,6 +625,9 @@ parse_args(int argc, char **argv)
case 'N':
norotate++;
break;
+ case 'P':
+ enforcepid++;
+ break;
case 'R':
rotatereq++;
requestor = strdup(optarg);
@@ -1779,7 +1783,7 @@ set_swpid(struct sigwork_entry *swork, const struct conf_entry *ent)
f = fopen(ent->pid_file, "r");
if (f == NULL) {
- if (errno == ENOENT) {
+ if (errno == ENOENT && enforcepid == 0) {
/*
* Warn if the PID file doesn't exist, but do
* not consider it an error. Most likely it
@@ -1801,7 +1805,7 @@ set_swpid(struct sigwork_entry *swork, const struct conf_entry *ent)
* has terminated, so it should be safe to rotate any
* log files that the process would have been using.
*/
- if (feof(f)) {
+ if (feof(f) && enforcepid == 0) {
swork->sw_pidok = 1;
warnx("pid file is empty: %s", ent->pid_file);
} else
OpenPOWER on IntegriCloud