svn commit: r200806 - head/usr.sbin/newsyslog

Xin LI delphij at delphij.net
Tue Dec 22 22:11:18 UTC 2009


On 2009/12/22 13:32, Stanislav Sedov wrote:
> On Mon, 21 Dec 2009 20:12:02 +0000 (UTC)
> Xin LI<delphij at FreeBSD.org>  mentioned:
>
>> 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.
>
> Or the process has not created the PID file and can be screwed up by rotating
> its log file.  What about making this optional controlled by a command line
> switch?  It might be a more safe alternative.

Yes probably.  I think the both case (can't find the PID file, or the 
PID file is empty) should be counted, as they may represent the similar 
situation, however, I think we'd better leave the current behavior 
default, since it's the most case.

Do you think the attached patch makes sense?

Cheers,
-- 
Xin LI <delphij at delphij.net>	http://www.delphij.net/
FreeBSD - The Power to Serve!	       Live free or die
-------------- next part --------------
Index: newsyslog.8
===================================================================
--- newsyslog.8	(revision 200868)
+++ newsyslog.8	(working copy)
@@ -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 December 23, 2009
 .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 @@
 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
Index: newsyslog.c
===================================================================
--- newsyslog.c	(revision 200868)
+++ newsyslog.c	(working copy)
@@ -167,6 +167,7 @@
 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 @@
 		*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:FNR:P")) != -1)
 		switch (ch) {
 		case 'a':
 			archtodir++;
@@ -624,6 +625,8 @@
 		case 'N':
 			norotate++;
 			break;
+		case 'P':
+			enforcepid++;
 		case 'R':
 			rotatereq++;
 			requestor = strdup(optarg);
@@ -1779,7 +1782,7 @@
 
 	f = fopen(ent->pid_file, "r");
 	if (f == NULL) {
-		if (errno == ENOENT) {
+		if (errno == ENOENT && enforcepid == 0) {
 			/*
 			 * Warn if the PID file doesn't exist, but do
 			 * not consider it an error.  Most likely it
@@ -1801,7 +1804,7 @@
 		 * 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


More information about the svn-src-head mailing list