You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Jeff Trawick <tr...@gmail.com> on 2010/02/16 23:11:40 UTC

Re: svn commit: r910705 - in /httpd/httpd/trunk: CHANGES docs/manual/programs/htcacheclean.xml support/htcacheclean.c

On Tue, Feb 16, 2010 at 4:42 PM,  <mi...@apache.org> wrote:
> Author: minfrin
> Date: Tue Feb 16 21:42:03 2010
> New Revision: 910705
>
> URL: http://svn.apache.org/viewvc?rev=910705&view=rev
> Log:
> support/htcacheclean: Teach it how to write a pid file (modelled on
> httpd's writing of a pid file) so that it becomes possible to run
> more than one instance of htcacheclean on the same machine.
>
> Modified:
>    httpd/httpd/trunk/CHANGES
>    httpd/httpd/trunk/docs/manual/programs/htcacheclean.xml
>    httpd/httpd/trunk/support/htcacheclean.c
>
> Modified: httpd/httpd/trunk/CHANGES
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=910705&r1=910704&r2=910705&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/CHANGES [utf-8] (original)
> +++ httpd/httpd/trunk/CHANGES [utf-8] Tue Feb 16 21:42:03 2010
> @@ -2,6 +2,11 @@
>
>  Changes with Apache 2.3.7
>
> +  *) support/htcacheclean: Teach it how to write a pid file (modelled on
> +     httpd's writing of a pid file) so that it becomes possible to run
> +     more than one instance of htcacheclean on the same machine.
> +     [Graham Leggett]

Based on my own initial confusion of the "becomes possible" language
(which isn't strictly true), I suspect that this feature description
would be more readily understood if this stressed the ease of
termination by pid file, since the admin/script no longer has to check
ps output (which certainly is a bigger benefit when there are multiple
instances, which would require looking at the path parameter).
Mileage varies, of course.

> +
>   *) Log command line on startup, so there's a record of command line
>      arguments like -f.
>      PR 48752.  [Dan Poirier]
>
> Modified: httpd/httpd/trunk/docs/manual/programs/htcacheclean.xml
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/programs/htcacheclean.xml?rev=910705&r1=910704&r2=910705&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/docs/manual/programs/htcacheclean.xml (original)
> +++ httpd/httpd/trunk/docs/manual/programs/htcacheclean.xml Tue Feb 16 21:42:03 2010
> @@ -49,6 +49,7 @@
>     [ -<strong>n</strong> ]
>     [ -<strong>t</strong> ]
>     [ -<strong>i</strong> ]
> +    [ -<strong>P</strong><var>pidfile</var> ]
>     -<strong>d</strong><var>interval</var>
>     -<strong>p</strong><var>path</var>
>     -<strong>l</strong><var>limit</var></code></p>
> @@ -95,6 +96,10 @@
>     should be the same value as specified with the <directive
>     module="mod_disk_cache">CacheRoot</directive> directive.</dd>
>
> +    <dt><code>-P<var>pidfile</var></code></dt>
> +    <dd>Specify <var>pidfile</var> as the name of the file to write the
> +    process ID to when daemonized.</dd>
> +
>     <dt><code>-l<var>limit</var></code></dt>
>     <dd>Specify <var>limit</var> as the total disk cache size limit. The value
>     is expressed in bytes by default (or attaching <code>B</code> to the
>
> Modified: httpd/httpd/trunk/support/htcacheclean.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/support/htcacheclean.c?rev=910705&r1=910704&r2=910705&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/support/htcacheclean.c (original)
> +++ httpd/httpd/trunk/support/htcacheclean.c Tue Feb 16 21:42:03 2010
> @@ -708,8 +708,8 @@
>     }
>     apr_file_printf(errfile,
>     "%s -- program for cleaning the disk cache."                             NL
> -    "Usage: %s [-Dvtrn] -pPATH -lLIMIT"                                      NL
> -    "       %s [-nti] -dINTERVAL -pPATH -lLIMIT"                             NL
> +    "Usage: %s [-Dvtrn] -pPATH -lLIMIT [-PPIDFILE]"                          NL
> +    "       %s [-nti] -dINTERVAL -pPATH -lLIMIT [-PPIDFILE]"                 NL
>                                                                              NL
>     "Options:"                                                               NL
>     "  -d   Daemonize and repeat cache cleaning every INTERVAL minutes."     NL
> @@ -735,6 +735,8 @@
>                                                                              NL
>     "  -p   Specify PATH as the root directory of the disk cache."           NL
>                                                                              NL
> +    "  -P   Specify PIDFILE as the file to write the pid file to."           NL

s/write the pid file to/write the pid to/

> +                                                                             NL
>     "  -l   Specify LIMIT as the total disk cache size limit. Attach 'K'"    NL
>     "       or 'M' to the number for specifying KBytes or MBytes."           NL
>                                                                              NL
> @@ -770,7 +772,7 @@
>     int retries, isdaemon, limit_found, intelligent, dowork;
>     char opt;
>     const char *arg;
> -    char *proxypath, *path;
> +    char *proxypath, *path, *pidfile;
>     char errmsg[1024];
>
>     interrupted = 0;
> @@ -786,6 +788,7 @@
>     intelligent = 0;
>     previous = 0; /* avoid compiler warning */
>     proxypath = NULL;
> +    pidfile = NULL;
>
>     if (apr_app_initialize(&argc, &argv, NULL) != APR_SUCCESS) {
>         return 1;
> @@ -807,7 +810,7 @@
>     apr_getopt_init(&o, pool, argc, argv);
>
>     while (1) {
> -        status = apr_getopt(o, "iDnvrtd:l:L:p:", &opt, &arg);
> +        status = apr_getopt(o, "iDnvrtd:l:L:p:P:", &opt, &arg);
>         if (status == APR_EOF) {
>             break;
>         }
> @@ -912,6 +915,14 @@
>                                        proxypath, apr_strerror(status, errmsg, sizeof errmsg)));
>                 }
>                 break;
> +
> +            case 'P':
> +                if (pidfile) {
> +                    usage_repeated_arg(pool, opt);
> +                }
> +                pidfile = apr_pstrdup(pool, arg);
> +                break;
> +
>             } /* switch */
>         } /* else */
>     } /* while */
> @@ -957,6 +968,22 @@
>     }
>  #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_UREAD | APR_UWRITE | APR_GREAD, pool))) {
> +            apr_file_printf(file, "%ld" APR_EOL_STR, (long) mypid);

APR_PID_T_FMT and no (long) cast

> +            apr_file_close(file);
> +        }
> +        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));
> +        }

why not just let this be a fatal error?  the user specified an invalid
path in all likelihood and needs to fix it

Also, I suspect that cleaning up the pid file on exit would be anticipated.

Re: svn commit: r910705 - in /httpd/httpd/trunk: CHANGES docs/manual/programs/htcacheclean.xml support/htcacheclean.c

Posted by Jeff Trawick <tr...@gmail.com>.
On Wed, Feb 17, 2010 at 7:56 PM, Graham Leggett <mi...@sharp.fm> wrote:
> On 17 Feb 2010, at 8:54 PM, Jeff Trawick wrote:
>
>> The daemon-report-pidfile-error situation seems to be easily handled
>> just by reversing the order of the apr_proc_detach block with the
>> if-pidfile block.  Then the unusable pidfile path error could be
>> reported to the console in conjunction with -d just like a bogus cache
>> path or such errors (which are already fatal).
>
> In the process you end up logging the pid of the parent process, the process
> doomed to exit on daemonisation, and not the child process, which is the pid
> you want to keep track of.

whoops :(

> One option is to open the file before the daemonisation, and write the pid
> file after the daemonisation, assuming this kind of thing is portable, I
> don't know.

simply logging it twice in the case of daemonization should avoid any
odd behavior as well as allow reporting almost all error scenarios to
the console; that also requires closing the open pidfile handle before
daemonizing to avoid a race between unlink in the parent and creation
in the child; the attached patch seems to work

I still think exit() is in order after failing to write the pidfile,
even when there's nowhere to report an error logging the pid.  There
are pros and cons, but in the interest of scripts that monitor or
terminate the daemon it seems best that no pidfile means no active
daemon.

Re: svn commit: r910705 - in /httpd/httpd/trunk: CHANGES docs/manual/programs/htcacheclean.xml support/htcacheclean.c

Posted by Graham Leggett <mi...@sharp.fm>.
On 17 Feb 2010, at 8:54 PM, Jeff Trawick wrote:

> The daemon-report-pidfile-error situation seems to be easily handled
> just by reversing the order of the apr_proc_detach block with the
> if-pidfile block.  Then the unusable pidfile path error could be
> reported to the console in conjunction with -d just like a bogus cache
> path or such errors (which are already fatal).

In the process you end up logging the pid of the parent process, the  
process doomed to exit on daemonisation, and not the child process,  
which is the pid you want to keep track of.

One option is to open the file before the daemonisation, and write the  
pid file after the daemonisation, assuming this kind of thing is  
portable, I don't know.

> Fix both?  Although httpd has left dangling pid files in weird failure
> scenarios for a long time, I wouldn't consider it a feature, so yeah.
>
> At the same time?  irrelevant as far as I'm concerned

When I said "at the same time", I meant "fix both now, rather than one  
now, and the other later (aka never)". I didn't necessarily mean  
simultaneously :)

Regards,
Graham
--


Re: svn commit: r910705 - in /httpd/httpd/trunk: CHANGES docs/manual/programs/htcacheclean.xml support/htcacheclean.c

Posted by Jeff Trawick <tr...@gmail.com>.
On Tue, Feb 16, 2010 at 6:08 PM, Graham Leggett <mi...@sharp.fm> wrote:
> On 17 Feb 2010, at 12:11 AM, Jeff Trawick wrote:
>
>>> +  *) support/htcacheclean: Teach it how to write a pid file (modelled on
>>> +     httpd's writing of a pid file) so that it becomes possible to run
>>> +     more than one instance of htcacheclean on the same machine.
>>> +     [Graham Leggett]
>>
>> Based on my own initial confusion of the "becomes possible" language
>> (which isn't strictly true), I suspect that this feature description
>> would be more readily understood if this stressed the ease of
>> termination by pid file, since the admin/script no longer has to check
>> ps output (which certainly is a bigger benefit when there are multiple
>> instances, which would require looking at the path parameter).
>> Mileage varies, of course.
>
> s/possible/practical/ I think makes more sense.
>
> "killall <processname>" is a really awful way to kill a process :)
>
>>> +    "  -P   Specify PIDFILE as the file to write the pid file to."
>>>     NL
>>
>> s/write the pid file to/write the pid to/
>
> Just fixed this in r910735.
>
>>> +            apr_file_printf(file, "%ld" APR_EOL_STR, (long) mypid);
>>
>> APR_PID_T_FMT and no (long) cast
>
> server/log.c is guilty too, fixed it in r910747.
>
>>> +            apr_file_close(file);
>>> +        }
>>> +        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));
>>> +        }
>>
>> why not just let this be a fatal error?  the user specified an invalid
>> path in all likelihood and needs to fix it
>
> We've daemonised at this point, so we can't fail, as the end user won't know
> it's happened. There is also an established pattern in here that when
> daemonised, it stays silent, which probably isn't a good idea, but would
> need to be fixed separately.
>
> One option is to use syslog, will need to see how httpd does it so the
> Windows side works too.

The daemon-report-pidfile-error situation seems to be easily handled
just by reversing the order of the apr_proc_detach block with the
if-pidfile block.  Then the unusable pidfile path error could be
reported to the console in conjunction with -d just like a bogus cache
path or such errors (which are already fatal).

>
>> Also, I suspect that cleaning up the pid file on exit would be
>> anticipated.
>
> Also fixed, svn is off and on and so will commit when it's back up.
>
> server/log.c is also guilty of the same thing, would it make sense to fix
> both at the same time?

Fix both?  Although httpd has left dangling pid files in weird failure
scenarios for a long time, I wouldn't consider it a feature, so yeah.

At the same time?  irrelevant as far as I'm concerned

Re: svn commit: r910705 - in /httpd/httpd/trunk: CHANGES docs/manual/programs/htcacheclean.xml support/htcacheclean.c

Posted by Graham Leggett <mi...@sharp.fm>.
On 17 Feb 2010, at 8:16 AM, Jaime Carmona Loeches wrote:

> Hi, I don't have time for help in developing Apache.
>
> How can I put my email off of this distribution list?

In the mail headers of most emails from mailing lists you'll find the  
email address to use to unsubscribe, and an email address to send mail  
to to get an automated help response back.

On your mail, the headers said this:

List-Help: 	<ma...@httpd.apache.org>
List-Unsubscribe: 	<ma...@httpd.apache.org>

Regards,
Graham
--


Re: svn commit: r910705 - in /httpd/httpd/trunk: CHANGES docs/manual/programs/htcacheclean.xml support/htcacheclean.c

Posted by Jaime Carmona Loeches <ja...@gmail.com>.
Hi, I don't have time for help in developing Apache.

How can I put my email off of this distribution list?

Thanks in advance,
   Jaime.

2010/2/17 Graham Leggett <mi...@sharp.fm>

> On 17 Feb 2010, at 12:11 AM, Jeff Trawick wrote:
>
>  +  *) support/htcacheclean: Teach it how to write a pid file (modelled on
>>> +     httpd's writing of a pid file) so that it becomes possible to run
>>> +     more than one instance of htcacheclean on the same machine.
>>> +     [Graham Leggett]
>>>
>>
>> Based on my own initial confusion of the "becomes possible" language
>> (which isn't strictly true), I suspect that this feature description
>> would be more readily understood if this stressed the ease of
>> termination by pid file, since the admin/script no longer has to check
>> ps output (which certainly is a bigger benefit when there are multiple
>> instances, which would require looking at the path parameter).
>> Mileage varies, of course.
>>
>
> s/possible/practical/ I think makes more sense.
>
> "killall <processname>" is a really awful way to kill a process :)
>
>
>  +    "  -P   Specify PIDFILE as the file to write the pid file to."
>>>     NL
>>>
>>
>> s/write the pid file to/write the pid to/
>>
>
> Just fixed this in r910735.
>
>
>  +            apr_file_printf(file, "%ld" APR_EOL_STR, (long) mypid);
>>>
>>
>> APR_PID_T_FMT and no (long) cast
>>
>
> server/log.c is guilty too, fixed it in r910747.
>
>
>  +            apr_file_close(file);
>>> +        }
>>> +        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));
>>> +        }
>>>
>>
>> why not just let this be a fatal error?  the user specified an invalid
>> path in all likelihood and needs to fix it
>>
>
> We've daemonised at this point, so we can't fail, as the end user won't
> know it's happened. There is also an established pattern in here that when
> daemonised, it stays silent, which probably isn't a good idea, but would
> need to be fixed separately.
>
> One option is to use syslog, will need to see how httpd does it so the
> Windows side works too.
>
>
>  Also, I suspect that cleaning up the pid file on exit would be
>> anticipated.
>>
>
> Also fixed, svn is off and on and so will commit when it's back up.
>
> server/log.c is also guilty of the same thing, would it make sense to fix
> both at the same time?
>
> Regards,
> Graham
> --
>
>


-- 
NOTA IMPORTANTE: Por favor, en adelante envíen los correos a
jcarmonaloeches@gmail.com

Re: svn commit: r910705 - in /httpd/httpd/trunk: CHANGES docs/manual/programs/htcacheclean.xml support/htcacheclean.c

Posted by Graham Leggett <mi...@sharp.fm>.
On 17 Feb 2010, at 12:11 AM, Jeff Trawick wrote:

>> +  *) support/htcacheclean: Teach it how to write a pid file  
>> (modelled on
>> +     httpd's writing of a pid file) so that it becomes possible to  
>> run
>> +     more than one instance of htcacheclean on the same machine.
>> +     [Graham Leggett]
>
> Based on my own initial confusion of the "becomes possible" language
> (which isn't strictly true), I suspect that this feature description
> would be more readily understood if this stressed the ease of
> termination by pid file, since the admin/script no longer has to check
> ps output (which certainly is a bigger benefit when there are multiple
> instances, which would require looking at the path parameter).
> Mileage varies, of course.

s/possible/practical/ I think makes more sense.

"killall <processname>" is a really awful way to kill a process :)

>> +    "  -P   Specify PIDFILE as the file to write the pid file  
>> to."           NL
>
> s/write the pid file to/write the pid to/

Just fixed this in r910735.

>> +            apr_file_printf(file, "%ld" APR_EOL_STR, (long) mypid);
>
> APR_PID_T_FMT and no (long) cast

server/log.c is guilty too, fixed it in r910747.

>> +            apr_file_close(file);
>> +        }
>> +        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));
>> +        }
>
> why not just let this be a fatal error?  the user specified an invalid
> path in all likelihood and needs to fix it

We've daemonised at this point, so we can't fail, as the end user  
won't know it's happened. There is also an established pattern in here  
that when daemonised, it stays silent, which probably isn't a good  
idea, but would need to be fixed separately.

One option is to use syslog, will need to see how httpd does it so the  
Windows side works too.

> Also, I suspect that cleaning up the pid file on exit would be  
> anticipated.

Also fixed, svn is off and on and so will commit when it's back up.

server/log.c is also guilty of the same thing, would it make sense to  
fix both at the same time?

Regards,
Graham
--