summaryrefslogtreecommitdiffstats
path: root/usr.sbin/newsyslog
diff options
context:
space:
mode:
authorobrien <obrien@FreeBSD.org>2013-02-08 16:10:16 +0000
committerobrien <obrien@FreeBSD.org>2013-02-08 16:10:16 +0000
commit3028e3f8aba938dfd0bf9fda987b8a72140b8027 (patch)
treeb2f038222ff8a70f687652441df00d2b564c8abe /usr.sbin/newsyslog
parent952a6d5a7cd3d3f9007acfa06805262fc04a105f (diff)
parent1d08d5f677c1dfa810e381073590adbae19cc69f (diff)
downloadFreeBSD-src-3028e3f8aba938dfd0bf9fda987b8a72140b8027.zip
FreeBSD-src-3028e3f8aba938dfd0bf9fda987b8a72140b8027.tar.gz
Sync with HEAD.
Diffstat (limited to 'usr.sbin/newsyslog')
-rw-r--r--usr.sbin/newsyslog/newsyslog.84
-rw-r--r--usr.sbin/newsyslog/newsyslog.c40
2 files changed, 31 insertions, 13 deletions
diff --git a/usr.sbin/newsyslog/newsyslog.8 b/usr.sbin/newsyslog/newsyslog.8
index 82fe5b7..87f60ac 100644
--- a/usr.sbin/newsyslog/newsyslog.8
+++ b/usr.sbin/newsyslog/newsyslog.8
@@ -125,7 +125,9 @@ reasons for either trimming that log or skipping it.
Cause
.Nm
not to trim the logs, but to print out what it would do if this option
-were not specified.
+were not specified. This option implies the
+.Fl r
+option.
.It Fl r
Remove the restriction that
.Nm
diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c
index 875f911..d0ef3d3 100644
--- a/usr.sbin/newsyslog/newsyslog.c
+++ b/usr.sbin/newsyslog/newsyslog.c
@@ -179,7 +179,7 @@ struct sigwork_entry {
int sw_pidok; /* true if pid value is valid */
pid_t sw_pid; /* the process id from the PID file */
const char *sw_pidtype; /* "daemon" or "process group" */
- int run_cmd; /* run command or send PID to signal */
+ int sw_runcmd; /* run command or send PID to signal */
char sw_fname[1]; /* file the PID was read from or shell cmd */
};
@@ -644,7 +644,7 @@ parse_args(int argc, char **argv)
break;
case 'n':
noaction++;
- break;
+ /* FALLTHROUGH */
case 'r':
needroot = 0;
break;
@@ -1582,7 +1582,7 @@ delete_oldest_timelog(const struct conf_entry *ent, const char *archive_dir)
oldlogs[i].fname);
else if (unlinkat(dir_fd, oldlogs[i].fname, 0) != 0) {
snprintf(errbuf, sizeof(errbuf),
- "Could not delet old logfile '%s'",
+ "Could not delete old logfile '%s'",
oldlogs[i].fname);
perror(errbuf);
}
@@ -1814,12 +1814,21 @@ do_rotate(const struct conf_entry *ent)
printf("\tcp %s %s\n", ent->log, file1);
else
printf("\tln %s %s\n", ent->log, file1);
+ printf("\ttouch %s\t\t"
+ "# Update mtime for 'when'-interval processing\n",
+ file1);
} else {
if (!(flags & CE_BINARY)) {
/* Report the trimming to the old log */
log_trim(ent->log, ent);
}
savelog(ent->log, file1);
+ /*
+ * Interval-based rotations are done using the mtime of
+ * the most recently archived log, so make sure it gets
+ * updated during a rotation.
+ */
+ utimes(file1, NULL);
}
change_attrs(file1, ent);
}
@@ -1857,7 +1866,7 @@ do_sigwork(struct sigwork_entry *swork)
int kres, secs;
char *tmp;
- if (!(swork->sw_pidok) || swork->sw_pid == 0)
+ if (swork->sw_runcmd == 0 && (!(swork->sw_pidok) || swork->sw_pid == 0))
return; /* no work to do... */
/*
@@ -1891,14 +1900,19 @@ do_sigwork(struct sigwork_entry *swork)
}
if (noaction) {
- printf("\tkill -%d %d \t\t# %s\n", swork->sw_signum,
- (int)swork->sw_pid, swork->sw_fname);
- if (secs > 0)
- printf("\tsleep %d\n", secs);
+ if (swork->sw_runcmd)
+ printf("\tsh -c '%s %d'\n", swork->sw_fname,
+ swork->sw_signum);
+ else {
+ printf("\tkill -%d %d \t\t# %s\n", swork->sw_signum,
+ (int)swork->sw_pid, swork->sw_fname);
+ if (secs > 0)
+ printf("\tsleep %d\n", secs);
+ }
return;
}
- if (swork->run_cmd) {
+ if (swork->sw_runcmd) {
asprintf(&tmp, "%s %d", swork->sw_fname, swork->sw_signum);
if (tmp == NULL) {
warn("can't allocate memory to run %s",
@@ -1974,7 +1988,7 @@ do_zipwork(struct zipwork_entry *zwork)
else
pgm_name++;
- if (zwork->zw_swork != NULL && zwork->zw_swork->run_cmd == 0 &&
+ if (zwork->zw_swork != NULL && zwork->zw_swork->sw_runcmd == 0 &&
zwork->zw_swork->sw_pidok <= 0) {
warnx(
"log %s not compressed because daemon(s) not notified",
@@ -2066,10 +2080,12 @@ save_sigwork(const struct conf_entry *ent)
tmpsiz = sizeof(struct sigwork_entry) + strlen(ent->pid_cmd_file) + 1;
stmp = malloc(tmpsiz);
- stmp->run_cmd = 0;
+ stmp->sw_runcmd = 0;
/* If this is a command to run we just set the flag and run command */
if (ent->flags & CE_PID2CMD) {
- stmp->run_cmd = 1;
+ stmp->sw_pid = -1;
+ stmp->sw_pidok = 0;
+ stmp->sw_runcmd = 1;
} else {
set_swpid(stmp, ent);
}
OpenPOWER on IntegriCloud