From owner-freebsd-bugs@FreeBSD.ORG Tue Mar 27 18:10:12 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 34B9F10656D0 for ; Tue, 27 Mar 2012 18:10:12 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 9F2158FC1A for ; Tue, 27 Mar 2012 18:10:11 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q2RIABuc081997 for ; Tue, 27 Mar 2012 18:10:11 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q2RIABjJ081996; Tue, 27 Mar 2012 18:10:11 GMT (envelope-from gnats) Resent-Date: Tue, 27 Mar 2012 18:10:11 GMT Resent-Message-Id: <201203271810.q2RIABjJ081996@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Eugene Grosbein Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id C9666106566C for ; Tue, 27 Mar 2012 18:07:31 +0000 (UTC) (envelope-from eugen@grosbein.pp.ru) Received: from grosbein.pp.ru (grosbein.pp.ru [89.189.172.146]) by mx1.freebsd.org (Postfix) with ESMTP id 767238FC14 for ; Tue, 27 Mar 2012 18:07:29 +0000 (UTC) Received: from grosbein.pp.ru (localhost [127.0.0.1]) by grosbein.pp.ru (8.14.5/8.14.5) with ESMTP id q2RI3MPV003026 for ; Wed, 28 Mar 2012 01:03:22 +0700 (NOVT) (envelope-from eugen@grosbein.pp.ru) Received: (from eugen@localhost) by grosbein.pp.ru (8.14.5/8.14.5/Submit) id q2RI3LEH003025; Wed, 28 Mar 2012 01:03:21 +0700 (NOVT) (envelope-from eugen) Message-Id: <201203271803.q2RI3LEH003025@grosbein.pp.ru> Date: Wed, 28 Mar 2012 01:03:21 +0700 (NOVT) From: Eugene Grosbein To: FreeBSD-gnats-submit@FreeBSD.org X-Send-Pr-Version: 3.113 Cc: Subject: bin/166448: [patch] newsyslog -t fails to find previous rotated log X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: Eugene Grosbein List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Mar 2012 18:10:12 -0000 >Number: 166448 >Category: bin >Synopsis: [patch] newsyslog -t fails to find previous rotated log >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Tue Mar 27 18:10:11 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Eugene Grosbein >Release: FreeBSD 8.3-PRERELEASE amd64 >Organization: RDTC JSC >Environment: System: FreeBSD grosbein.pp.ru 8.3-PRERELEASE FreeBSD 8.3-PRERELEASE #19: Tue Mar 20 03:24:04 NOVT 2012 root@grosbein.pp.ru:/usr/local/obj/usr/local/src/sys/DADV amd64 >Description: newsyslog.conf(5) has "when" field instructing newsyslog to find previous rotated copy of log and look if it is older than "when" hours. newsyslog always looks for "file.0" and this is wrong when -t flag is used. >How-To-Repeat: Use newsyslog -t and non-zero value in "when" field: /var/log/cron 600 3 * 8@T C This should rotate log three times a day starting from midnight. >Fix: --- usr.sbin/newsyslog/newsyslog.c.orig 2012-03-27 22:43:06.000000000 +0700 +++ usr.sbin/newsyslog/newsyslog.c 2012-03-28 00:53:21.000000000 +0700 @@ -2206,6 +2206,77 @@ return (kbytes(dbtob(sb.st_blocks))); } +/* Return the age of previous old log file, when using time based filenames. */ +static time_t +find_oldest_timelog(const char *dir, const char *logfname) +{ + struct stat sb; + int c, valid; + size_t logfname_len; + struct tm tm; + time_t oldt; + struct dirent *dp; + DIR *dirp; + char *s; + + if ((dirp = opendir(dir)) == NULL) + err(1, "Cannot open log directory '%s'", dir); + + oldt = -1; + logfname_len = strlen(logfname); + while ((dp = readdir(dirp)) != NULL) { + if (dp->d_type != DT_REG) + continue; + /* Ignore everything but files with our logfile prefix */ + if (strncmp(dp->d_name, logfname, logfname_len) != 0) + continue; + /* Ignore the actual non-rotated logfile */ + if (dp->d_namlen == logfname_len) + continue; + /* + * Make sure we have found a logfile, so the + * postfix is valid, IE format is: '.