Date: Thu, 1 May 2003 10:40:16 -0700 (PDT) From: Lukas Ertl <l.ertl@univie.ac.at> To: freebsd-bugs@FreeBSD.org Subject: Re: bin/51519: newsyslog handles bzip2-compressed files incorrectly Message-ID: <200305011740.h41HeGuO018351@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/51519; it has been noted by GNATS. From: Lukas Ertl <l.ertl@univie.ac.at> To: freebsd-gnats-submit@FreeBSD.org, peter@tesseract.demon.co.uk Cc: Subject: Re: bin/51519: newsyslog handles bzip2-compressed files incorrectly Date: Thu, 1 May 2003 19:36:28 +0200 (CEST) Hi Peter, could you try this patch? It is against rev. 1.67 of newsyslog.c. --- newsyslog.c.diff begins here --- Index: usr.sbin/newsyslog/newsyslog.c =================================================================== RCS file: /u/cvs/cvs/src/usr.sbin/newsyslog/newsyslog.c,v retrieving revision 1.67 diff -u -r1.67 newsyslog.c --- usr.sbin/newsyslog/newsyslog.c 27 Apr 2003 23:37:31 -0000 1.67 +++ usr.sbin/newsyslog/newsyslog.c 1 May 2003 17:30:25 -0000 @@ -143,7 +143,7 @@ static void compress_log(char *log, int dowait); static void bzcompress_log(char *log, int dowait); static int sizefile(char *file); -static int age_old_log(char *file); +static int age_old_log(char *file, int flags); static int send_signal(const struct conf_entry *ent); static time_t parse8601(char *s, char *errline); static void movefile(char *from, char *to, int perm, uid_t owner_uid, @@ -301,7 +301,7 @@ printf("%s <%d>: ", ent->log, ent->numlogs); } size = sizefile(ent->log); - modtime = age_old_log(ent->log); + modtime = age_old_log(ent->log, ent->flags); ent->rotate = 0; ent->firstcreate = 0; if (size < 0) { @@ -1461,40 +1461,53 @@ /* Return the age of old log file (file.0) */ static int -age_old_log(char *file) +age_old_log(char *file, int flags) { struct stat sb; - char tmp[MAXPATHLEN + sizeof(".0") + sizeof(COMPRESS_POSTFIX) + 1]; + char *suffix, *tmp; + int size; + + if (flags & CE_COMPACT) + suffix = COMPRESS_POSTFIX; + else if (flags & CE_BZCOMPACT) + suffix = BZCOMPRESS_POSTFIX; + else + suffix = ""; + + size = MAXPATHLEN + sizeof(".0") + sizeof(suffix) + 1; + + if ((tmp = (char *) malloc(size)) == NULL) + err(1, "malloc failed"); if (archtodir) { char *p; /* build name of archive directory into tmp */ if (*archdirname == '/') { /* absolute */ - strlcpy(tmp, archdirname, sizeof(tmp)); + strlcpy(tmp, archdirname, size); } else { /* relative */ /* get directory part of logfile */ - strlcpy(tmp, file, sizeof(tmp)); + strlcpy(tmp, file, size); if ((p = rindex(tmp, '/')) == NULL) tmp[0] = '\0'; else *(p + 1) = '\0'; - strlcat(tmp, archdirname, sizeof(tmp)); + strlcat(tmp, archdirname, size); } - strlcat(tmp, "/", sizeof(tmp)); + strlcat(tmp, "/", size); /* get filename part of logfile */ if ((p = rindex(file, '/')) == NULL) - strlcat(tmp, file, sizeof(tmp)); + strlcat(tmp, file, size); else - strlcat(tmp, p + 1, sizeof(tmp)); + strlcat(tmp, p + 1, size); } else { - (void) strlcpy(tmp, file, sizeof(tmp)); + (void) strlcpy(tmp, file, size); } if (stat(strcat(tmp, ".0"), &sb) < 0) - if (stat(strcat(tmp, COMPRESS_POSTFIX), &sb) < 0) + if (stat(strcat(tmp, suffix), &sb) < 0) return (-1); return ((int)(timenow - sb.st_mtime + 1800) / 3600); } --- newsyslog.c.diff ends here ---
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200305011740.h41HeGuO018351>