From mishka@mail.industrialcarriers.com  Sat Mar 30 15:32:54 2002
Return-Path: <mishka@mail.industrialcarriers.com>
Received: from mail.industrialcarriers.com (mail.industrialcarriers.com [195.138.73.178])
	by hub.freebsd.org (Postfix) with ESMTP id AFD5537B405
	for <FreeBSD-gnats-submit@freebsd.org>; Sat, 30 Mar 2002 15:32:48 -0800 (PST)
Received: (from mishka@localhost)
	by mail.industrialcarriers.com (8.11.6/8.11.6) id g2UNWdo85282;
	Sun, 31 Mar 2002 01:32:39 +0200 (EET)
	(envelope-from mishka)
Message-Id: <200203302332.g2UNWdo85282@mail.industrialcarriers.com>
Date: Sun, 31 Mar 2002 01:32:39 +0200 (EET)
From: Mishka <mishka@terabyte.com.ua>
Reply-To: Mishka <mishka@terabyte.com.ua>
To: FreeBSD-gnats-submit@freebsd.org
Cc: mishka@batraq.anything3d.com
Subject: Two new features in newsyslog(8)
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         36553
>Category:       bin
>Synopsis:       [patch] [request] Two new features in newsyslog(8)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    gad
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Mar 30 15:40:01 PST 2002
>Closed-Date:    
>Last-Modified:  Sat Jan 26 04:51:08 UTC 2008
>Originator:     Mishka
>Release:        FreeBSD 4.5-STABLE i386
>Organization:
Terabyte ACS
>Environment:
System: FreeBSD mail.industrialcarriers.com 4.5-STABLE FreeBSD 4.5-STABLE #0: Sun Mar 24 13:13:03 EET 2002 mishka@victor.terabyte.com.ua:/usr/src/sys/compile/HARLEY i386

>Description:

Dear Sirs!

I am very happy with FreeBSD built-in utilities. Such, in most cases i needn't
any other software to solve my problems and task. Hovewer, there is posted some
useful changes to newsyslog(8):
1. When time="*" and size="*" now it means that newsyslog must rotate log file
   with any size and at any time, when started. Early it just skip such logs.
   I think, if we always want to skip some logfiles, we can comment it out or
   just remove.
2. After all, newsyslog always tries to sent some signal (HUP by default) to
   some process (syslogd(8) by default) which can be not wanted sometimes. Now
   if path_to_pid_file="-" the newsyslog will not sent any signal to any
   process for this records.

Few examples:
/var/log/squid/access.log	644  31  *     *     -  -
/var/log/apache/access.log	644   3  8192  *     Z  -
/var/log/maillog		644   7  *     @T00  Z

I take a look to ports collection before, but have not find any with such
features, when my rotation scheme want to have such ones.

For apply my changes please use patch provided. If you find my changes useful
please inform me how can i fix it (move to ports collection or other way).

--
Best regards,
Mishka.


>How-To-Repeat:

1. You can change time and size fields to asterisk (*) and see newer turned
   over logfiles.
2. You can't avoid sending signal. If you ignore path_to_pid_file field the
   newsyslog will sent SIGHUP to syslogd(8). Moreover, this field must be
   started with slash "/" character, so should be path to some pid-file.

>Fix:

Please use following patch:

Note: This patchfile should be placed into /usr/src/usr.sbin directory.
(cd /usr/sys/usr.sbin ; patch < newsyslog.patch)
diff -ur /usr/src/usr.sbin/newsyslog/newsyslog.8 newsyslog/newsyslog.8
--- /usr/src/usr.sbin/newsyslog/newsyslog.8	Sun Mar 31 00:38:19 2002
+++ newsyslog/newsyslog.8	Sat Mar 30 06:34:07 2002
@@ -254,6 +254,16 @@
 rotate on every 5th day of month at 6:00 hr
 .El
 .Pp
+.Em Note:
+if you place asterisk 
+.Pq Ql \&*
+into both
+.Ar size
+and
+.Ar when
+fields the logfile will be turned over each time starting
+.Nm .
+.Pp
 .It Ar flags
 This optional field specifies if the archive should have any
 special processing done to the archived log files.
@@ -284,9 +294,14 @@
 the file name to read to find the daemon process id.  If this
 field is present, a
 .Ar signal_number
-is sent the process id contained in this
-file.  This field must start with "/" in order to be recognized
-properly.
+is sent the process id contained in this file; in other case
+.Nm
+will tries sent signal to
+.Xr syslogd 8 .
+Please note, all path must be absolute, (i.e. paths must start with "/"
+in order to be recognized properly). Place the dash
+.Ar -
+here if you don't want sent any signals to any processes.
 .It Ar signal_number
 This optional field specifies
 the signal number will be sent to the daemon process.
diff -ur /usr/src/usr.sbin/newsyslog/newsyslog.c newsyslog/newsyslog.c
--- /usr/src/usr.sbin/newsyslog/newsyslog.c	Sun Mar 31 00:38:21 2002
+++ newsyslog/newsyslog.c	Sun Mar 31 01:03:25 2002
@@ -25,7 +25,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-"$FreeBSD: src/usr.sbin/newsyslog/newsyslog.c,v 1.25.2.4 2001/11/14 16:58:58 obrien Exp $";
+"$Id$";
 #endif	/* not lint */
 
 #define OSF
@@ -67,6 +67,7 @@
 #define CE_BZCOMPACT 8		/* Compact the achived log files with bzip2 */
 				/*  status messages */
 #define	CE_TRIMAT  4		/* trim at a specific time */
+#define CE_SKIPNOTIFY 16	/* skip syslogd(8) notification */
 
 #define NONE -1
 
@@ -167,17 +168,24 @@
 					    ctime(&ent->trim_at));
 				return;
 			} else if (verbose && ent->hours <= 0) {
-				printf("--> time is up\n");
+				printf("time is up");
+				if (ent->size < 0)
+					printf(" or ");
+				else
+					printf(", ");
 			}
 		}
 		if (verbose && (ent->size > 0))
 			printf("size (Kb): %d [%d] ", size, ent->size);
 		if (verbose && (ent->hours > 0))
 			printf(" age (hr): %d [%d] ", modtime, ent->hours);
-		if (force || ((ent->size > 0) && (size >= ent->size)) ||
+		if (verbose && (ent->hours <= 0 && ent->size < 0)) 
+			printf("always ");
+		if ( force || ((ent->size > 0) && (size >= ent->size)) ||
 		    (ent->hours <= 0 && (ent->flags & CE_TRIMAT)) ||
-		    ((ent->hours > 0) && ((modtime >= ent->hours)
-			    || (modtime < 0)))) {
+		    ((ent->hours > 0) && ((modtime >= ent->hours) ||
+			(modtime < 0) )) ||
+		    (ent->hours <= 0 && ent->size < 0) ) {
 			if (verbose)
 				printf("--> trimming log....\n");
 			if (noaction && !verbose) {
@@ -460,6 +468,8 @@
 		if (q && *q) {
 			if (*q == '/')
 				working->pid_file = strdup(q);
+			else if (*q == '-')
+				working->flags |= CE_SKIPNOTIFY;
 			else if (isdigit(*q))
 				goto got_sig;
 			else
@@ -666,7 +676,11 @@
 		pid = get_pid(pid_file);
 	}
 	if (pid) {
-		if (noaction) {
+		if (flags & CE_SKIPNOTIFY) {
+			notified = 1;
+			if (verbose)
+				printf("no syslogd(8) notification needed\n");
+		} else if (noaction) {
 			notified = 1;
 			printf("kill -%d %d\n", sig, (int) pid);
 		} else if (kill(pid, sig))
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->gad 
Responsible-Changed-By: gad 
Responsible-Changed-When: Fri Feb 21 18:08:15 PST 2003 
Responsible-Changed-Why:  
.    I will be looking into these changes while working on some other 
changes to newsyslog.  I definitely want to provide some way to say 
"do not signal any process when rotating this file".  I don't quite 
understand your other change, but I will also look into it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=36553 

From: Garance A Drosehn <gad@FreeBSD.org>
To: freebsd-gnats-submit@FreeBSD.org, mishka@terabyte.com.ua
Cc:  
Subject: Re: bin/36553: Two new features in newsyslog(8)
Date: Sun, 2 Mar 2003 22:27:25 -0500

 I have committed a change to newsyslog in freebsd-current
 which adds the 'N' flag for config file entries.  If you
 specify the 'N' flag, it will not signal any processes.
 I did it this way to match an option that NetBSD has.
 
 I also understand what you meant in the first part of your PR.
 I have not committed any changes for that yet, but I will.
 
 -- 
 Garance Alistair Drosehn     =      gad@gilead.netel.rpi.edu
 Senior Systems Programmer               or   gad@FreeBSD.org
 Rensselaer Polytechnic Institute;             Troy, NY;  USA
 
>Unformatted:
