Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 20 Jan 2010 01:07:38 +0000 (UTC)
From:      Xin LI <delphij@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r202668 - head/usr.sbin/newsyslog
Message-ID:  <201001200107.o0K17cGj061025@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: delphij
Date: Wed Jan 20 01:07:38 2010
New Revision: 202668
URL: http://svn.freebsd.org/changeset/base/202668

Log:
  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.
  
  Requested by:	stas
  MFC after:	2 weeks
  X-MFC with:	r200806

Modified:
  head/usr.sbin/newsyslog/newsyslog.8
  head/usr.sbin/newsyslog/newsyslog.c

Modified: head/usr.sbin/newsyslog/newsyslog.8
==============================================================================
--- head/usr.sbin/newsyslog/newsyslog.8	Wed Jan 20 00:54:51 2010	(r202667)
+++ head/usr.sbin/newsyslog/newsyslog.8	Wed Jan 20 01:07:38 2010	(r202668)
@@ -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: head/usr.sbin/newsyslog/newsyslog.c
==============================================================================
--- head/usr.sbin/newsyslog/newsyslog.c	Wed Jan 20 00:54:51 2010	(r202667)
+++ head/usr.sbin/newsyslog/newsyslog.c	Wed Jan 20 01:07:38 2010	(r202668)
@@ -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,7 @@ set_swpid(struct sigwork_entry *swork, c
 
 	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 +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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201001200107.o0K17cGj061025>