diff options
author | Garance A Drosehn <gad@FreeBSD.org> | 2003-09-09 02:50:25 +0000 |
---|---|---|
committer | Garance A Drosehn <gad@FreeBSD.org> | 2003-09-09 02:50:25 +0000 |
commit | 32734b8a2f7d3f5a7f74c885dfc2ed9622410a74 (patch) | |
tree | 6bd8b7d3d461f1abc092d62f0b9e31a6f4f7cb01 /usr.sbin/newsyslog | |
parent | 6cee741b2b70be09fbd1c69a0ec39822a45e3944 (diff) | |
download | src-32734b8a2f7d3f5a7f74c885dfc2ed9622410a74.tar.gz src-32734b8a2f7d3f5a7f74c885dfc2ed9622410a74.zip |
Change parse8601 and parseDWM so they return an alternate error value
for invalid times, and have the caller print the error message.
MFC after: 23 days
Notes
Notes:
svn path=/head/; revision=119899
Diffstat (limited to 'usr.sbin/newsyslog')
-rw-r--r-- | usr.sbin/newsyslog/newsyslog.c | 43 |
1 files changed, 29 insertions, 14 deletions
diff --git a/usr.sbin/newsyslog/newsyslog.c b/usr.sbin/newsyslog/newsyslog.c index c79269b5a1ac..4294fd30dbd6 100644 --- a/usr.sbin/newsyslog/newsyslog.c +++ b/usr.sbin/newsyslog/newsyslog.c @@ -148,8 +148,8 @@ static void movefile(char *from, char *to, int perm, uid_t owner_uid, gid_t group_gid); static void createdir(const struct conf_entry *ent, char *dirpart); static void createlog(const struct conf_entry *ent); -static time_t parse8601(char *s, char *errline); -static time_t parseDWM(char *s, char *errline); +static time_t parse8601(char *s); +static time_t parseDWM(char *s); /* * All the following are defined to work on an 'int', in the @@ -984,16 +984,19 @@ parse_file(FILE *cf, const char *cfname, struct conf_entry **work_p, *ep != '$') errx(1, "malformed interval/at:\n%s", errline); if (*ep == '@') { - if ((working->trim_at = parse8601(ep + 1, errline)) - == (time_t) - 1) - errx(1, "malformed at:\n%s", errline); + working->trim_at = parse8601(ep + 1); working->flags |= CE_TRIMAT; } else if (*ep == '$') { - if ((working->trim_at = parseDWM(ep + 1, errline)) - == (time_t) - 1) - errx(1, "malformed at:\n%s", errline); + working->trim_at = parseDWM(ep + 1); working->flags |= CE_TRIMAT; } + if (ent->flags & CE_TRIMAT) { + if (working->trim_at == (time_t)-1) + errx(1, "malformed at:\n%s", errline); + if (working->trim_at == (time_t)-2) + errx(1, "nonexistent time:\n%s", + errline); + } } if (eol) @@ -1729,7 +1732,7 @@ createlog(const struct conf_entry *ent) * are defaulted to the current date but time zero. */ static time_t -parse8601(char *s, char *errline) +parse8601(char *s) { char *t; time_t tsecs; @@ -1800,8 +1803,14 @@ parse8601(char *s, char *errline) || tm.tm_min > 59 || tm.tm_hour < 0 || tm.tm_hour > 23) return (-1); } - if ((tsecs = mktime(&tm)) == -1) - errx(1, "nonexistent time:\n%s", errline); + + tsecs = mktime(&tm); + /* + * Check for invalid times, including things like the missing + * hour when switching from "daylight savings" to "standard". + */ + if (tsecs == (time_t)-1) + tsecs = (time_t)-2; return (tsecs); } @@ -1820,7 +1829,7 @@ parse8601(char *s, char *errline) * are defaulted to the current date but time zero. */ static time_t -parseDWM(char *s, char *errline) +parseDWM(char *s) { char *t; time_t tsecs; @@ -1917,7 +1926,13 @@ parseDWM(char *s, char *errline) else s = t; } - if ((tsecs = mktime(&tm)) == -1) - errx(1, "nonexistent time:\n%s", errline); + + tsecs = mktime(&tm); + /* + * Check for invalid times, including things like the missing + * hour when switching from "daylight savings" to "standard". + */ + if (tsecs == (time_t)-1) + tsecs = (time_t)-2; return (tsecs); } |