From 91ba008fc5d755c689431f25a67d7003b1db6146 Mon Sep 17 00:00:00 2001 From: Mark Johnston Date: Tue, 26 Mar 2013 23:11:30 +0000 Subject: [PATCH] Fix interval-based rotations when the -t flag is used. In this case, find the most-recently archived logfile and use its mtime to determine whether or not to rotate, as in the non-timestamped case. Previously we would just try to use the mtime of .0, which always results in a rotation since it generally doesn't exist in the -t case. PR: bin/166448 Approved by: emaste (co-mentor) Tested by: Marco Steinbach MFC after: 2 weeks --- usr.sbin/newsyslog/newsyslog.c | 192 +++++++++++++++++++++++---------- 1 file changed, 134 insertions(+), 58 deletions(-) diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c index d0ef3d3e9640..08598acd8182 100644 --- a/usr.sbin/newsyslog/newsyslog.c +++ b/usr.sbin/newsyslog/newsyslog.c @@ -276,7 +276,7 @@ static void parse_args(int argc, char **argv); static int parse_doption(const char *doption); static void usage(void); static int log_trim(const char *logname, const struct conf_entry *log_ent); -static int age_old_log(char *file); +static int age_old_log(const char *file); static void savelog(char *from, char *to); static void createdir(const struct conf_entry *ent, char *dirpart); static void createlog(const struct conf_entry *ent); @@ -1446,6 +1446,66 @@ oldlog_entry_compare(const void *a, const void *b) return (0); } +/* + * Check whether the file corresponding to dp is an archive of the logfile + * logfname, based on the timefnamefmt format string. Return true and fill out + * tm if this is the case; otherwise return false. + */ +static int +validate_old_timelog(const struct dirent *dp, const char *logfname, struct tm *tm) +{ + size_t logfname_len; + char *s; + int c; + + logfname_len = strlen(logfname); + + if (dp->d_type != DT_REG) + return (0); + /* Ignore everything but files with our logfile prefix. */ + if (strncmp(dp->d_name, logfname, logfname_len) != 0) + return (0); + /* Ignore the actual non-rotated logfile. */ + if (dp->d_namlen == logfname_len) + return (0); + + /* + * Make sure we created have found a logfile, so the + * postfix is valid, IE format is: '.