From dan@obluda.cz  Sun Nov  8 23:29:23 2009
Return-Path: <dan@obluda.cz>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id AE88D106566B
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  8 Nov 2009 23:29:23 +0000 (UTC)
	(envelope-from dan@obluda.cz)
Received: from master7.ms.mff.cuni.cz (master7.ms.mff.cuni.cz [195.113.20.22])
	by mx1.freebsd.org (Postfix) with ESMTP id 498BD8FC08
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  8 Nov 2009 23:29:22 +0000 (UTC)
Received: (from root@localhost)
	by master7.ms.mff.cuni.cz (8.14.3/8.14.3) id nA8NTLaB021533
	for FreeBSD-gnats-submit@freebsd.org; Mon, 9 Nov 2009 00:29:21 +0100 (CET)
	(envelope-from dan@obluda.cz)
Message-Id: <200911082329.nA8NTLaB021533@master7.ms.mff.cuni.cz>
Date: Mon, 9 Nov 2009 00:29:21 +0100 (CET)
From: Dan Lukes <dan@obluda.cz>
Reply-To: Dan Lukes <dan@obluda.cz>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: newsyslog doesn't handle stopped daemons correctly
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         140397
>Category:       bin
>Synopsis:       [patch] newsyslog(8) doesn't handle stopped daemons correctly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    delphij
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Nov 08 23:30:01 UTC 2009
>Closed-Date:    Mon May 03 22:09:30 UTC 2010
>Last-Modified:  Mon May  3 22:10:02 UTC 2010
>Originator:     Dan Lukes
>Release:        FreeBSD 7.2-RELEASE-p3 i386
>Organization:
Obludarium
>Environment:
analyzed on:
System: FreeBSD 7.2-RELEASE-p3
usr.sbin/newsyslog/newsyslog.c,v 1.107.2.1.4.1 2009/04/15 03:14:26

but apply to:
HEAD
usr.sbin/newsyslog/newsyslog.c,v 1.108 2008/01/30 22:11:59
as well

>Description:
The current code says:

               /*
                 * Warn if the PID file is empty, but do not consider
                 * it an error.  Most likely it means the process has
                 * has terminated, so it should be safe to rotate any
                 * log files that the process would have been using.
                 */

True, but the same apply when PID file doesn't exist at all. The code should
handle missing PID file the same way as empty PID file. 
The missing PID file is handled like error for now.

>How-To-Repeat:
	Stop a daemon that remove the PID file on exit. Try to use newsyslog
to rotate it's log file while daemon not running.
>Fix:

	<how to correct or work around the problem, if known (multiple lines)>

--- usr.sbin/newsyslog/newsyslog.c.orig	2009-04-15 05:14:26.000000000 +0200
+++ usr.sbin/newsyslog/newsyslog.c	2009-11-07 00:45:09.000000000 +0100
@@ -1779,7 +1779,17 @@
 
 	f = fopen(ent->pid_file, "r");
 	if (f == NULL) {
-		warn("can't open pid file: %s", ent->pid_file);
+	        if (errno == ENOENT) {
+        		/*
+        		 * Warn if the PID file doesn't exist, but do not consider
+        		 * it an error.  Most likely it means the process has
+	        	 * has terminated, so it should be safe to rotate any
+		         * log files that the process would have been using.
+        		 */
+			swork->sw_pidok = 1;
+			warnx("pid file doesn't exist: %s", ent->pid_file);
+	        } else
+        		warn("can't open pid file: %s", ent->pid_file);
 		return;
 	}
 
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->patched 
State-Changed-By: delphij 
State-Changed-When: Mon Dec 21 20:12:12 UTC 2009 
State-Changed-Why:  
Patch applied against -HEAD, MFC reminder. 


Responsible-Changed-From-To: freebsd-bugs->delphij 
Responsible-Changed-By: delphij 
Responsible-Changed-When: Mon Dec 21 20:12:12 UTC 2009 
Responsible-Changed-Why:  
Take. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/140397: commit references a PR
Date: Mon, 21 Dec 2009 20:12:10 +0000 (UTC)

 Author: delphij
 Date: Mon Dec 21 20:12:01 2009
 New Revision: 200806
 URL: http://svn.freebsd.org/changeset/base/200806
 
 Log:
   Don't consider non-existence of a PID file an error, we should be able
   to proceed anyway as this most likely mean that the process has been
   terminated.
   
   PR:		bin/140397
   Submitted by:	Dan Lukes <dan obluda cz>
   MFC after:	1 month
 
 Modified:
   head/usr.sbin/newsyslog/newsyslog.c
 
 Modified: head/usr.sbin/newsyslog/newsyslog.c
 ==============================================================================
 --- head/usr.sbin/newsyslog/newsyslog.c	Mon Dec 21 20:09:19 2009	(r200805)
 +++ head/usr.sbin/newsyslog/newsyslog.c	Mon Dec 21 20:12:01 2009	(r200806)
 @@ -1779,7 +1779,18 @@ set_swpid(struct sigwork_entry *swork, c
  
  	f = fopen(ent->pid_file, "r");
  	if (f == NULL) {
 -		warn("can't open pid file: %s", ent->pid_file);
 +		if (errno == ENOENT) {
 +			/*
 +			 * Warn if the PID file doesn't exist, but do
 +			 * not consider it an error.  Most likely it
 +			 * means the process has been terminated,
 +			 * so it should be safe to rotate any log
 +			 * files that the process would have been using.
 +			 */
 +			swork->sw_pidok = 1;
 +			warnx("pid file doesn't exist: %s", ent->pid_file);
 +		} else
 +			warn("can't open pid file: %s", ent->pid_file);
  		return;
  	}
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
State-Changed-From-To: patched->closed 
State-Changed-By: delphij 
State-Changed-When: Wed Feb 3 18:42:28 UTC 2010 
State-Changed-Why:  
MFC'ed to 8-STABLE, thanks for your submission! 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/140397: commit references a PR
Date: Wed,  3 Feb 2010 18:42:23 +0000 (UTC)

 Author: delphij
 Date: Wed Feb  3 18:42:14 2010
 New Revision: 203436
 URL: http://svn.freebsd.org/changeset/base/203436
 
 Log:
   MFC r202668+r200806:
   
   Don't consider non-existence of a PID file an error, we should be able
   to proceed anyway as this most likely mean that the process has been
   terminated. [1]
   
   Add a new option, -P, which reverts newsyslog(8) to the old behavior,
   which stops to proceed further, as it is possible that processes which
   fails to create PID file get screwed by rotation. [2]
   
   PR:		bin/140397
   Submitted by:	Dan Lukes [1]
   Requested by:	stas [2]
 
 Modified:
   stable/8/usr.sbin/newsyslog/newsyslog.8
   stable/8/usr.sbin/newsyslog/newsyslog.c
 Directory Properties:
   stable/8/usr.sbin/newsyslog/   (props changed)
 
 Modified: stable/8/usr.sbin/newsyslog/newsyslog.8
 ==============================================================================
 --- stable/8/usr.sbin/newsyslog/newsyslog.8	Wed Feb  3 18:32:29 2010	(r203435)
 +++ stable/8/usr.sbin/newsyslog/newsyslog.8	Wed Feb  3 18:42:14 2010	(r203436)
 @@ -17,7 +17,7 @@
  .\" the suitability of this software for any purpose.  It is
  .\" provided "as is" without express or implied warranty.
  .\"
 -.Dd February 24, 2005
 +.Dd January 19, 2010
  .Dt NEWSYSLOG 8
  .Os
  .Sh NAME
 @@ -25,7 +25,7 @@
  .Nd maintain system log files to manageable sizes
  .Sh SYNOPSIS
  .Nm
 -.Op Fl CFNnrsv
 +.Op Fl CFNPnrsv
  .Op Fl R Ar tagname
  .Op Fl a Ar directory
  .Op Fl d Ar directory
 @@ -169,6 +169,10 @@ This option is intended to be used with 
  or
  .Fl CC
  options when creating log files is the only objective.
 +.It Fl P
 +Prevent further action if we should send signal but the
 +.Dq pidfile
 +is empty or does not exist.
  .It Fl R Ar tagname
  Specify that
  .Nm
 
 Modified: stable/8/usr.sbin/newsyslog/newsyslog.c
 ==============================================================================
 --- stable/8/usr.sbin/newsyslog/newsyslog.c	Wed Feb  3 18:32:29 2010	(r203435)
 +++ stable/8/usr.sbin/newsyslog/newsyslog.c	Wed Feb  3 18:42:14 2010	(r203436)
 @@ -167,6 +167,7 @@ int needroot = 1;		/* Root privs are nec
  int noaction = 0;		/* Don't do anything, just show it */
  int norotate = 0;		/* Don't rotate */
  int nosignal;			/* Do not send any signals */
 +int enforcepid = 0;		/* If PID file does not exist or empty, do nothing */
  int force = 0;			/* Force the trim no matter what */
  int rotatereq = 0;		/* -R = Always rotate the file(s) as given */
  				/*    on the command (this also requires   */
 @@ -580,7 +581,7 @@ parse_args(int argc, char **argv)
  		*p = '\0';
  
  	/* Parse command line options. */
 -	while ((ch = getopt(argc, argv, "a:d:f:nrsvCD:FNR:")) != -1)
 +	while ((ch = getopt(argc, argv, "a:d:f:nrsvCD:FNPR:")) != -1)
  		switch (ch) {
  		case 'a':
  			archtodir++;
 @@ -624,6 +625,9 @@ parse_args(int argc, char **argv)
  		case 'N':
  			norotate++;
  			break;
 +		case 'P':
 +			enforcepid++;
 +			break;
  		case 'R':
  			rotatereq++;
  			requestor = strdup(optarg);
 @@ -1779,7 +1783,18 @@ set_swpid(struct sigwork_entry *swork, c
  
  	f = fopen(ent->pid_file, "r");
  	if (f == NULL) {
 -		warn("can't open pid file: %s", ent->pid_file);
 +		if (errno == ENOENT && enforcepid == 0) {
 +			/*
 +			 * Warn if the PID file doesn't exist, but do
 +			 * not consider it an error.  Most likely it
 +			 * means the process has been terminated,
 +			 * so it should be safe to rotate any log
 +			 * files that the process would have been using.
 +			 */
 +			swork->sw_pidok = 1;
 +			warnx("pid file doesn't exist: %s", ent->pid_file);
 +		} else
 +			warn("can't open pid file: %s", ent->pid_file);
  		return;
  	}
  
 @@ -1790,7 +1805,7 @@ set_swpid(struct sigwork_entry *swork, c
  		 * has terminated, so it should be safe to rotate any
  		 * log files that the process would have been using.
  		 */
 -		if (feof(f)) {
 +		if (feof(f) && enforcepid == 0) {
  			swork->sw_pidok = 1;
  			warnx("pid file is empty: %s", ent->pid_file);
  		} else
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 

From: Dan Lukes <dan@obluda.cz>
To: delphij@FreeBSD.org
Cc: bug-followup@FreeBSD.org
Subject: Re: bin/140397: [patch] newsyslog(8) doesn't handle stopped daemons
 correctly
Date: Wed, 03 Feb 2010 22:13:23 +0100

 On 02/03/10 19:42, delphij@FreeBSD.org:
 > State-Changed-From-To: patched->closed
 > http://www.freebsd.org/cgi/query-pr.cgi?pr=140397
 
 
 1) Thank you
 2) A reason not to MFC it into 7-STABLE as well ?
 3) The new -P command line option is not optimal way, IMHO. The better 
 way is to implement new flag into newsyslog.conf. It allow to set the 
 behavior "per line", not using the "one behavior fit for all" logic 
 which seems not to have positives here ...
 
 					Dan

From: Xin LI <delphij@delphij.net>
To: Dan Lukes <dan@obluda.cz>
Cc: delphij@FreeBSD.ORG, bug-followup@FreeBSD.ORG
Subject: Re: bin/140397: [patch] newsyslog(8) doesn't handle stopped daemons
 correctly
Date: Wed, 03 Feb 2010 14:36:02 -0800

 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
 On 2010/02/03 13:13, Dan Lukes wrote:
 > On 02/03/10 19:42, delphij@FreeBSD.org:
 >> State-Changed-From-To: patched->closed
 >> http://www.freebsd.org/cgi/query-pr.cgi?pr=140397
 > 
 > 
 > 1) Thank you
 > 2) A reason not to MFC it into 7-STABLE as well ?
 
 Currently 7-STABLE is in a code freeze, so I think we should only merge
 important bug fixes at this moment.  Do you think this one is so important?
 
 > 3) The new -P command line option is not optimal way, IMHO. The better
 > way is to implement new flag into newsyslog.conf. It allow to set the
 > behavior "per line", not using the "one behavior fit for all" logic
 > which seems not to have positives here ...
 
 Well...  To be honest, I (personally) think the -P is not quite sane,
 it's just a choice provided, so that users can "opt out" the behavior if
 they know what they are doing.  Or, say, if an application fails to
 update PID file, but just go ahead and write logs, then it's already
 somewhat out of control and need a right fix.
 
 If we were to add some new features as per-file option, the ability of
 executing arbitrary command after cutting the file and before archiving
 it would deserve more attention than this (mis)behavior, IMHO.
 
 Cheers,
 - -- 
 Xin LI <delphij@delphij.net>	http://www.delphij.net/
 FreeBSD - The Power to Serve!	       Live free or die
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.14 (FreeBSD)
 
 iQEcBAEBAgAGBQJLafpSAAoJEATO+BI/yjfBWKIH/i9LW5utT3kCSq/fIjOov/cz
 giabjiPa2qZkL3nceQzPR7ZRc+GRV95bX96EKi5RSApqHweG522/Fp6Sm+/zp8D9
 65bo52/M8GiqRLGEB5Q/psr8TX/BtfvG1a4z9ng3eSB2IOPJ8c3QiCTo30KnUMFj
 g1Nr3Y2M/nh/dIAxgQ2Q4oyrtgK/oMuC89ClvcRTtAgsudy49pwBKsbcjBL/BlY4
 D+lue8bNIjaNuu+4KCBlFrcSxm3UINU0nI4yx1GUwvQoGvntQNwH+tBItLKO1Sqi
 BBOYK2xzaxZM1frJnFj3/DX9na511ygV/1rsurjyGlGd8sZNlMeRcDkdn9WnOh0=
 =NzHu
 -----END PGP SIGNATURE-----
State-Changed-From-To: closed->patched 
State-Changed-By: delphij 
State-Changed-When: Wed Feb 3 23:16:06 UTC 2010 
State-Changed-Why:  
Revert back to patched state, as the submitter wants it to be 
in 7-STABLE after 7.3-R. 

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

From: Dan Lukes <dan@obluda.cz>
To: d@delphij.net
Cc: Xin LI <delphij@delphij.net>, delphij@FreeBSD.ORG,
        bug-followup@FreeBSD.ORG
Subject: Re: bin/140397: [patch] newsyslog(8) doesn't handle stopped daemons
 correctly
Date: Thu, 04 Feb 2010 00:12:13 +0100

 On 02/03/10 23:36, Xin LI:
 >> 2) A reason not to MFC it into 7-STABLE as well ?
 >
 > Currently 7-STABLE is in a code freeze, so I think we should only merge
 > important bug fixes at this moment.  Do you think this one is so important?
 
 It can wait until code unfreezed.
 I'm not speaking about RELENG_7_2 which is freezed, I'm speaking about 
 RELENG_7 which is open the same way as RELENG_8, isn't it ?
 
 The RELENG_7 is not considered EOL. Is it too much work to MFC ? I 
 assumed the MFC is more about the decision than amount of work. I don't 
 know, I'm not comitter.
 
 >> 3) The new -P command line option is not optimal way, IMHO. The better
 >> way is to implement new flag into newsyslog.conf. It allow to set the
 >> behavior "per line", not using the "one behavior fit for all" logic
 >> which seems not to have positives here ...
 >
 > Well...  To be honest, I (personally) think the -P is not quite sane,
 > it's just a choice provided, so that users can "opt out" the behavior if
 > they know what they are doing.  Or, say, if an application fails to
 > update PID file, but just go ahead and write logs, then it's already
 > somewhat out of control and need a right fix.
 
 I agree. And because it's not so sane and we need it for specifically 
 damaged application only, then it's more important to enable such 
 behavior for such (damaged) application only, not affecting the others.
 
 We can claim "we don't support broken applications" then we need no -P 
 at all. Or we want to support them (for backward compatibility) such 
 behavior - then it's better to "enable" it for known broken application 
 only, not for all applications just because there is one broken of them.
 
 Just my $0.02
 
 						Dan
 
 
 

From: Xin LI <delphij@delphij.net>
To: Dan Lukes <dan@obluda.cz>
Cc: d@delphij.net, delphij@FreeBSD.ORG, bug-followup@FreeBSD.ORG
Subject: Re: bin/140397: [patch] newsyslog(8) doesn't handle stopped daemons
 correctly
Date: Wed, 03 Feb 2010 15:21:15 -0800

 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
 On 2010/02/03 15:12, Dan Lukes wrote:
 > On 02/03/10 23:36, Xin LI:
 >>> 2) A reason not to MFC it into 7-STABLE as well ?
 >>
 >> Currently 7-STABLE is in a code freeze, so I think we should only merge
 >> important bug fixes at this moment.  Do you think this one is so
 >> important?
 > 
 > It can wait until code unfreezed.
 
 Yes agreed.  I've reverted the PR to 'patched' state so it won't be
 forgotten then.
 
 > I'm not speaking about RELENG_7_2 which is freezed, I'm speaking about
 > RELENG_7 which is open the same way as RELENG_8, isn't it ?
 
 Nope...  RELENG_7 is frozen in preparation for RELENG_7_3 right now.
 
 > The RELENG_7 is not considered EOL. Is it too much work to MFC ? I
 > assumed the MFC is more about the decision than amount of work. I don't
 > know, I'm not comitter.
 
 No, it wouldn't be too much work :)
 
 >>> 3) The new -P command line option is not optimal way, IMHO. The better
 >>> way is to implement new flag into newsyslog.conf. It allow to set the
 >>> behavior "per line", not using the "one behavior fit for all" logic
 >>> which seems not to have positives here ...
 >>
 >> Well...  To be honest, I (personally) think the -P is not quite sane,
 >> it's just a choice provided, so that users can "opt out" the behavior if
 >> they know what they are doing.  Or, say, if an application fails to
 >> update PID file, but just go ahead and write logs, then it's already
 >> somewhat out of control and need a right fix.
 > 
 > I agree. And because it's not so sane and we need it for specifically
 > damaged application only, then it's more important to enable such
 > behavior for such (damaged) application only, not affecting the others.
 > 
 > We can claim "we don't support broken applications" then we need no -P
 > at all. Or we want to support them (for backward compatibility) such
 > behavior - then it's better to "enable" it for known broken application
 > only, not for all applications just because there is one broken of them.
 
 I don't have any passion in implementing this feature (it's not a high
 priority thing if we compare it to the ability to execute arbitrary
 command) but I'd be happy to offer help to get it integrated if someone
 else would work on it =-)
 
 Cheers,
 - -- 
 Xin LI <delphij@delphij.net>	http://www.delphij.net/
 FreeBSD - The Power to Serve!	       Live free or die
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.14 (FreeBSD)
 
 iQEcBAEBAgAGBQJLagTrAAoJEATO+BI/yjfBFDgIAMIv5Jm1EJVVz5rLuRNgNjFa
 13vWxC/sUMKcm6P/zFxEI3JfzcEGM70UfIoqsXTLInk/ljpViL9Qf9R6ctjlVvB8
 4XyDsbMfS11rELiW6cZXicMSxwza7NtvHa3pi7WoSk1xuTjvtNmeufysZLqRfOMq
 NyJ1jb5Hj2nlQLUqTuDLd4vulut5yB11rTEqh7eY5TUG3JcRvVDsHpwinps4T0Gn
 B2e3jZ1boQ6PWb7NKxtaOHQmMzQCFIWKOerUfeRToxID3h8uMDwzD/6/4FKaqzeX
 Hv1bKIxeSndH0LZKDMmmdfgiRhZ2aOfrjptwiKyr3x8eRN+WoiIPtnWC8lqXFbs=
 =ScZX
 -----END PGP SIGNATURE-----

From: Dan Lukes <dan@obluda.cz>
To: d@delphij.net
Cc: Xin LI <delphij@delphij.net>, delphij@FreeBSD.ORG,
        bug-followup@FreeBSD.ORG
Subject: Re: bin/140397: [patch] newsyslog(8) doesn't handle stopped daemons
 correctly
Date: Thu, 04 Feb 2010 00:51:49 +0100

 On 02/04/10 00:21, Xin LI:
 >> I'm not speaking about RELENG_7_2 which is freezed, I'm speaking about
 >> RELENG_7 which is open the same way as RELENG_8, isn't it ?
 >
 > Nope...  RELENG_7 is frozen in preparation for RELENG_7_3 right now.
 
 Then the
 http://www.freebsd.org/releng/index.html
 is outdated.
 
 >>>> 3) The new -P command line option is not optimal way
 
 > I don't have any passion in implementing this feature
 
 In the fact I know no application which require the previous behavior. 
 So I'm not so motivated also.
 
 					Dan
State-Changed-From-To: patched->closed 
State-Changed-By: delphij 
State-Changed-When: Mon May 3 22:09:15 UTC 2010 
State-Changed-Why:  
MFC done on 7-STABLE. 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/140397: commit references a PR
Date: Mon,  3 May 2010 22:09:17 +0000 (UTC)

 Author: delphij
 Date: Mon May  3 22:09:06 2010
 New Revision: 207587
 URL: http://svn.freebsd.org/changeset/base/207587
 
 Log:
   MFC r202668 and r200806 [1]:
   
   Add a new option, -P, which reverts newsyslog(8) to the old behavior,
   which stops to proceed further, as it is possible that processes which
   fails to create PID file get screwed by rotation.
   
   ----
   Don't consider non-existence of a PID file an error, we should be able
   to proceed anyway as this most likely mean that the process has been
   terminated.
   
   PR:             bin/140397
   Submitted by:   Dan Lukes <dan obluda cz>
 
 Modified:
   stable/7/usr.sbin/newsyslog/newsyslog.8
   stable/7/usr.sbin/newsyslog/newsyslog.c
 Directory Properties:
   stable/7/usr.sbin/newsyslog/   (props changed)
   stable/7/usr.sbin/newsyslog/newsyslog.conf.5   (props changed)
 
 Modified: stable/7/usr.sbin/newsyslog/newsyslog.8
 ==============================================================================
 --- stable/7/usr.sbin/newsyslog/newsyslog.8	Mon May  3 20:59:27 2010	(r207586)
 +++ stable/7/usr.sbin/newsyslog/newsyslog.8	Mon May  3 22:09:06 2010	(r207587)
 @@ -17,7 +17,7 @@
  .\" the suitability of this software for any purpose.  It is
  .\" provided "as is" without express or implied warranty.
  .\"
 -.Dd February 24, 2005
 +.Dd January 19, 2010
  .Dt NEWSYSLOG 8
  .Os
  .Sh NAME
 @@ -25,7 +25,7 @@
  .Nd maintain system log files to manageable sizes
  .Sh SYNOPSIS
  .Nm
 -.Op Fl CFNnrsv
 +.Op Fl CFNPnrsv
  .Op Fl R Ar tagname
  .Op Fl a Ar directory
  .Op Fl d Ar directory
 @@ -169,6 +169,10 @@ This option is intended to be used with 
  or
  .Fl CC
  options when creating log files is the only objective.
 +.It Fl P
 +Prevent further action if we should send signal but the
 +.Dq pidfile
 +is empty or does not exist.
  .It Fl R Ar tagname
  Specify that
  .Nm
 
 Modified: stable/7/usr.sbin/newsyslog/newsyslog.c
 ==============================================================================
 --- stable/7/usr.sbin/newsyslog/newsyslog.c	Mon May  3 20:59:27 2010	(r207586)
 +++ stable/7/usr.sbin/newsyslog/newsyslog.c	Mon May  3 22:09:06 2010	(r207587)
 @@ -167,6 +167,7 @@ int needroot = 1;		/* Root privs are nec
  int noaction = 0;		/* Don't do anything, just show it */
  int norotate = 0;		/* Don't rotate */
  int nosignal;			/* Do not send any signals */
 +int enforcepid = 0;		/* If PID file does not exist or empty, do nothing */
  int force = 0;			/* Force the trim no matter what */
  int rotatereq = 0;		/* -R = Always rotate the file(s) as given */
  				/*    on the command (this also requires   */
 @@ -580,7 +581,7 @@ parse_args(int argc, char **argv)
  		*p = '\0';
  
  	/* Parse command line options. */
 -	while ((ch = getopt(argc, argv, "a:d:f:nrsvCD:FNR:")) != -1)
 +	while ((ch = getopt(argc, argv, "a:d:f:nrsvCD:FNPR:")) != -1)
  		switch (ch) {
  		case 'a':
  			archtodir++;
 @@ -624,6 +625,9 @@ parse_args(int argc, char **argv)
  		case 'N':
  			norotate++;
  			break;
 +		case 'P':
 +			enforcepid++;
 +			break;
  		case 'R':
  			rotatereq++;
  			requestor = strdup(optarg);
 @@ -1779,7 +1783,18 @@ set_swpid(struct sigwork_entry *swork, c
  
  	f = fopen(ent->pid_file, "r");
  	if (f == NULL) {
 -		warn("can't open pid file: %s", ent->pid_file);
 +		if (errno == ENOENT && enforcepid == 0) {
 +			/*
 +			 * Warn if the PID file doesn't exist, but do
 +			 * not consider it an error.  Most likely it
 +			 * means the process has been terminated,
 +			 * so it should be safe to rotate any log
 +			 * files that the process would have been using.
 +			 */
 +			swork->sw_pidok = 1;
 +			warnx("pid file doesn't exist: %s", ent->pid_file);
 +		} else
 +			warn("can't open pid file: %s", ent->pid_file);
  		return;
  	}
  
 @@ -1790,7 +1805,7 @@ set_swpid(struct sigwork_entry *swork, c
  		 * has terminated, so it should be safe to rotate any
  		 * log files that the process would have been using.
  		 */
 -		if (feof(f)) {
 +		if (feof(f) && enforcepid == 0) {
  			swork->sw_pidok = 1;
  			warnx("pid file is empty: %s", ent->pid_file);
  		} else
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
