From f951ee4fbb0a0c110c0f3777dfc6c3e118bdc37b Mon Sep 17 00:00:00 2001 From: markj Date: Thu, 3 Jan 2013 16:11:24 +0000 Subject: Fix a typo in an error message. Approved by: rstone (co-mentor) MFC after: 1 week --- usr.sbin/newsyslog/newsyslog.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'usr.sbin/newsyslog') diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c index 875f911..654021f 100644 --- a/usr.sbin/newsyslog/newsyslog.c +++ b/usr.sbin/newsyslog/newsyslog.c @@ -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); } -- cgit v1.1 From e8588e6c07393ac104cb6bf5e726e1dea408f9aa Mon Sep 17 00:00:00 2001 From: markj Date: Thu, 3 Jan 2013 16:12:48 +0000 Subject: Have -n imply -r, since dry-run mode obviously doesn't require root privileges. Approved by: rstone (co-mentor) MFC after: 1 week --- usr.sbin/newsyslog/newsyslog.8 | 4 +++- usr.sbin/newsyslog/newsyslog.c | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'usr.sbin/newsyslog') 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 654021f..ee90b99 100644 --- a/usr.sbin/newsyslog/newsyslog.c +++ b/usr.sbin/newsyslog/newsyslog.c @@ -644,7 +644,7 @@ parse_args(int argc, char **argv) break; case 'n': noaction++; - break; + /* FALLTHROUGH */ case 'r': needroot = 0; break; -- cgit v1.1 From fe63c3a52ae03ef9724b8d4af06597b8a77e7064 Mon Sep 17 00:00:00 2001 From: markj Date: Thu, 3 Jan 2013 16:14:51 +0000 Subject: Make sure to update the mtime of a logfile after archiving it. This ensures that the next rotation happens at the correct time when using interval-based rotations. PR: bin/174438 Reviewed by: gad Approved by: rstone (co-mentor) MFC after: 1 week --- usr.sbin/newsyslog/newsyslog.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'usr.sbin/newsyslog') diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c index ee90b99..42cc013 100644 --- a/usr.sbin/newsyslog/newsyslog.c +++ b/usr.sbin/newsyslog/newsyslog.c @@ -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); } -- cgit v1.1 From eb5455fa48e6e07315efde38fa7c532224892515 Mon Sep 17 00:00:00 2001 From: markj Date: Sun, 27 Jan 2013 06:01:35 +0000 Subject: When the 'R' flag is used with a newsyslog.conf entry, some fields of the corresponding struct sigwork_entry were left uninitialized, potentially causing an early return from do_sigwork(). Ensure that these fields are initialized, and handle the 'R' flag properly in do_sigwork(). PR: bin/175330 Reviewed by: gad Approved by: rstone (co-mentor) MFC after: 1 week --- usr.sbin/newsyslog/newsyslog.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'usr.sbin/newsyslog') diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c index 42cc013..2bfdfd1 100644 --- a/usr.sbin/newsyslog/newsyslog.c +++ b/usr.sbin/newsyslog/newsyslog.c @@ -1866,7 +1866,7 @@ do_sigwork(struct sigwork_entry *swork) int kres, secs; char *tmp; - if (!(swork->sw_pidok) || swork->sw_pid == 0) + if (swork->run_cmd == 0 && (!(swork->sw_pidok) || swork->sw_pid == 0)) return; /* no work to do... */ /* @@ -2078,6 +2078,8 @@ save_sigwork(const struct conf_entry *ent) stmp->run_cmd = 0; /* If this is a command to run we just set the flag and run command */ if (ent->flags & CE_PID2CMD) { + stmp->sw_pid = -1; + stmp->sw_pidok = 0; stmp->run_cmd = 1; } else { set_swpid(stmp, ent); -- cgit v1.1 From 6491a8b5991985e7ef0979e248b1f54555b5e997 Mon Sep 17 00:00:00 2001 From: markj Date: Sun, 27 Jan 2013 06:02:38 +0000 Subject: Ensure that newsyslog -n prints the correct message for a rotation rule that uses the 'R' flag. Reviewed by: gad Approved by: rstone (co-mentor) MFC after: 1 week --- usr.sbin/newsyslog/newsyslog.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'usr.sbin/newsyslog') diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c index 2bfdfd1..dd48dfe 100644 --- a/usr.sbin/newsyslog/newsyslog.c +++ b/usr.sbin/newsyslog/newsyslog.c @@ -1900,10 +1900,15 @@ 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->run_cmd) + 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; } -- cgit v1.1 From d68a3343d31b1149ae1176d0f0b5f8c92408461a Mon Sep 17 00:00:00 2001 From: markj Date: Sun, 27 Jan 2013 06:03:57 +0000 Subject: Rename the run_cmd field to sw_runcmd to make it consistent with the other fields in struct sigwork_entry. Approved by: rstone (co-mentor) MFC after: 1 week --- usr.sbin/newsyslog/newsyslog.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'usr.sbin/newsyslog') diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c index dd48dfe..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 */ }; @@ -1866,7 +1866,7 @@ do_sigwork(struct sigwork_entry *swork) int kres, secs; char *tmp; - if (swork->run_cmd == 0 && (!(swork->sw_pidok) || swork->sw_pid == 0)) + if (swork->sw_runcmd == 0 && (!(swork->sw_pidok) || swork->sw_pid == 0)) return; /* no work to do... */ /* @@ -1900,7 +1900,7 @@ do_sigwork(struct sigwork_entry *swork) } if (noaction) { - if (swork->run_cmd) + if (swork->sw_runcmd) printf("\tsh -c '%s %d'\n", swork->sw_fname, swork->sw_signum); else { @@ -1912,7 +1912,7 @@ do_sigwork(struct sigwork_entry *swork) 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", @@ -1988,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", @@ -2080,12 +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->sw_pid = -1; stmp->sw_pidok = 0; - stmp->run_cmd = 1; + stmp->sw_runcmd = 1; } else { set_swpid(stmp, ent); } -- cgit v1.1