Return-Path: Delivered-To: apmail-httpd-cvs-archive@www.apache.org Received: (qmail 62275 invoked from network); 27 Feb 2010 18:14:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 27 Feb 2010 18:14:19 -0000 Received: (qmail 45100 invoked by uid 500); 27 Feb 2010 18:14:19 -0000 Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 45054 invoked by uid 500); 27 Feb 2010 18:14:19 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 45047 invoked by uid 99); 27 Feb 2010 18:14:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Feb 2010 18:14:19 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 27 Feb 2010 18:14:17 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A148F23888DD; Sat, 27 Feb 2010 18:13:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r917002 - /httpd/httpd/trunk/support/htcacheclean.c Date: Sat, 27 Feb 2010 18:13:56 -0000 To: cvs@httpd.apache.org From: minfrin@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100227181356.A148F23888DD@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: minfrin Date: Sat Feb 27 18:13:56 2010 New Revision: 917002 URL: http://svn.apache.org/viewvc?rev=917002&view=rev Log: Try open the pid file twice, once before daemonisation so we can see any error, and once after daemonisation so the child's pid is logged correctly. Patch by Jeff Trawick. Modified: httpd/httpd/trunk/support/htcacheclean.c Modified: httpd/httpd/trunk/support/htcacheclean.c URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/htcacheclean.c?rev=917002&r1=917001&r2=917002&view=diff ============================================================================== --- httpd/httpd/trunk/support/htcacheclean.c (original) +++ httpd/httpd/trunk/support/htcacheclean.c Sat Feb 27 18:13:56 2010 @@ -758,6 +758,28 @@ option)); } +static void log_pid(apr_pool_t *pool, const char *pidfilename, apr_file_t **pidfile) +{ + apr_status_t status; + char errmsg[120]; + pid_t mypid = getpid(); + + if (APR_SUCCESS == (status = apr_file_open(pidfile, pidfilename, APR_WRITE + | APR_CREATE | APR_TRUNCATE | APR_DELONCLOSE, + APR_UREAD | APR_UWRITE | APR_GREAD, pool))) { + apr_file_printf(*pidfile, "%" APR_PID_T_FMT APR_EOL_STR, mypid); + } + else { + if (errfile) { + apr_file_printf(errfile, + "Could not write the pid file '%s': %s" APR_EOL_STR, + pidfilename, + apr_strerror(status, errmsg, sizeof errmsg)); + } + exit(1); + } +} + /* * main */ @@ -769,10 +791,11 @@ apr_pool_t *pool, *instance; apr_getopt_t *o; apr_finfo_t info; + apr_file_t *pidfile; int retries, isdaemon, limit_found, intelligent, dowork; char opt; const char *arg; - char *proxypath, *path, *pidfile; + char *proxypath, *path, *pidfilename; char errmsg[1024]; interrupted = 0; @@ -788,7 +811,7 @@ intelligent = 0; previous = 0; /* avoid compiler warning */ proxypath = NULL; - pidfile = NULL; + pidfilename = NULL; if (apr_app_initialize(&argc, &argv, NULL) != APR_SUCCESS) { return 1; @@ -917,10 +940,10 @@ break; case 'P': - if (pidfile) { + if (pidfilename) { usage_repeated_arg(pool, opt); } - pidfile = apr_pstrdup(pool, arg); + pidfilename = apr_pstrdup(pool, arg); break; } /* switch */ @@ -961,27 +984,25 @@ } baselen = strlen(path); + if (pidfilename) { + log_pid(pool, pidfilename, &pidfile); /* before daemonizing, so we + * can report errors + */ + } + #ifndef DEBUG if (isdaemon) { apr_file_close(errfile); - apr_proc_detach(APR_PROC_DETACH_DAEMONIZE); - } -#endif - - if (pidfile) { - apr_file_t *file; - pid_t mypid = getpid(); - if (APR_SUCCESS == (status = apr_file_open(&file, pidfile, APR_WRITE - | APR_CREATE | APR_TRUNCATE | APR_DELONCLOSE, - APR_UREAD | APR_UWRITE | APR_GREAD, pool))) { - apr_file_printf(file, "%" APR_PID_T_FMT APR_EOL_STR, mypid); + errfile = NULL; + if (pidfilename) { + apr_file_close(pidfile); /* delete original pidfile only in parent */ } - else if (!isdaemon) { - apr_file_printf(errfile, - "Could not write the pid file '%s': %s" APR_EOL_STR, - pidfile, apr_strerror(status, errmsg, sizeof errmsg)); + apr_proc_detach(APR_PROC_DETACH_DAEMONIZE); + if (pidfilename) { + log_pid(pool, pidfilename, &pidfile); } } +#endif do { apr_pool_create(&instance, pool);