From owner-freebsd-bugs@FreeBSD.ORG Thu May 1 10:40:17 2003 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 992C037B401 for ; Thu, 1 May 2003 10:40:17 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 1B3DC43FAF for ; Thu, 1 May 2003 10:40:17 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.9/8.12.9) with ESMTP id h41HeGUp018352 for ; Thu, 1 May 2003 10:40:16 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.9/8.12.9/Submit) id h41HeGuO018351; Thu, 1 May 2003 10:40:16 -0700 (PDT) Date: Thu, 1 May 2003 10:40:16 -0700 (PDT) Message-Id: <200305011740.h41HeGuO018351@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: Lukas Ertl Subject: Re: bin/51519: newsyslog handles bzip2-compressed files incorrectly X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: Lukas Ertl List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 May 2003 17:40:18 -0000 The following reply was made to PR bin/51519; it has been noted by GNATS. From: Lukas Ertl 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 ---