bin/140397: newsyslog doesn't handle stopped daemons correctly

Dan Lukes dan at obluda.cz
Sun Nov 8 23:30:03 UTC 2009


>Number:         140397
>Category:       bin
>Synopsis:       newsyslog doesn't handle stopped daemons correctly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Nov 08 23:30:01 UTC 2009
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:


More information about the freebsd-bugs mailing list