From owner-svn-src-all@FreeBSD.ORG Wed Feb 3 18:42:14 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 9F8AE1065672; Wed, 3 Feb 2010 18:42:14 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 8EF738FC15; Wed, 3 Feb 2010 18:42:14 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o13IgE6I075841; Wed, 3 Feb 2010 18:42:14 GMT (envelope-from delphij@svn.freebsd.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o13IgEwV075838; Wed, 3 Feb 2010 18:42:14 GMT (envelope-from delphij@svn.freebsd.org) Message-Id: <201002031842.o13IgEwV075838@svn.freebsd.org> From: Xin LI Date: Wed, 3 Feb 2010 18:42:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r203436 - stable/8/usr.sbin/newsyslog X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Feb 2010 18:42:14 -0000 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