You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modules-dev@httpd.apache.org by Andrej van der Zee <an...@gmail.com> on 2009/03/13 08:01:39 UTC

post_config on reload

Hi,

I found this piece of code for dealing with the post_config issue (it is
called twice, while I need to initialise my stuff only once):

  void *data;
  const char *userdata_key = "post_config_only_once_key";
  apr_pool_userdata_get(&data, userdata_key, s->process->pool);
  if (!data) {
    apr_pool_userdata_set((const void *)1, userdata_key,
apr_pool_cleanup_null, s->process->pool);
    return OK;
  } else {
     // do initialize
  }

I was wondering if there is a solution for detecting a post_config
invocation on behalf of "apachctl restart" instead of a clean start (in case
of a restart, I do not want to initialise my stuff again).

Thank you,
Andrej

Re: post_config on reload

Posted by Andrej van der Zee <an...@gmail.com>.
Hi,


Register a function with the cleanup of the conf pool. The conf pool
>> is destroyed prior to a restart/kill/reload.
>>
>> You have an example in the code I've sent you.
>>
>> S
>>
>>
>>
> Perfect answer!  Unfortunately, the post_config is called twice on a
> restart, and with different memory pointers, so shared memory handles,
> mutexes, etc, those will all suddenly disappear.  You'd be forced to
> initialize your post_config again or potentially segmentation fault the
> server.  So, that is a good excuse to implement some extra code to handle
> restarting a thread anyway.
>
>
Thanks, one less choice to make :)

Greets,
Andrej

Re: post_config on reload

Posted by Joe Lewis <jo...@joe-lewis.com>.
Sorin Manolache wrote:
> On Fri, Mar 13, 2009 at 16:21, Andrej van der Zee
> <an...@gmail.com> wrote:
>   
>> Hi,
>>
>> Do not do this -  a restart should be a restart, not a half of a restart.
>>     
>>>  You should be reinitializing whatever you do on a restart as well as a
>>> start.  That's the whole point.
>>>
>>> I have one phrase that should illustrate why : memory leak.
>>>
>>> For example, if your extension creates another thread or spawns another
>>> process and that other thread/process doesn't clean up on a restart and
>>> contains a memory leak, what good is restart to you? Restart has suddenly
>>> become pointless.
>>>
>>> It is good etiquette to honour the concept of a restart.
>>>
>>>       
>> Okay, point taken. My extension indeed creates a thread. How can I know that
>> a user issues a restart? In other words, where can I kill my thread?
>>     
>
> Register a function with the cleanup of the conf pool. The conf pool
> is destroyed prior to a restart/kill/reload.
>
> You have an example in the code I've sent you.
>
> S
>
>   
Perfect answer!  Unfortunately, the post_config is called twice on a 
restart, and with different memory pointers, so shared memory handles, 
mutexes, etc, those will all suddenly disappear.  You'd be forced to 
initialize your post_config again or potentially segmentation fault the 
server.  So, that is a good excuse to implement some extra code to 
handle restarting a thread anyway.

Joe

Re: post_config on reload

Posted by Sorin Manolache <so...@gmail.com>.
On Fri, Mar 13, 2009 at 16:21, Andrej van der Zee
<an...@gmail.com> wrote:
> Hi,
>
> Do not do this -  a restart should be a restart, not a half of a restart.
>>  You should be reinitializing whatever you do on a restart as well as a
>> start.  That's the whole point.
>>
>> I have one phrase that should illustrate why : memory leak.
>>
>> For example, if your extension creates another thread or spawns another
>> process and that other thread/process doesn't clean up on a restart and
>> contains a memory leak, what good is restart to you? Restart has suddenly
>> become pointless.
>>
>> It is good etiquette to honour the concept of a restart.
>>
>
> Okay, point taken. My extension indeed creates a thread. How can I know that
> a user issues a restart? In other words, where can I kill my thread?

Register a function with the cleanup of the conf pool. The conf pool
is destroyed prior to a restart/kill/reload.

You have an example in the code I've sent you.

S

-- 
A: Because it reverses the logical flow of conversation.
Q: Why is top-posting frowned upon?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

Re: post_config on reload

Posted by Andrej van der Zee <an...@gmail.com>.
Hi,

Do not do this -  a restart should be a restart, not a half of a restart.
>  You should be reinitializing whatever you do on a restart as well as a
> start.  That's the whole point.
>
> I have one phrase that should illustrate why : memory leak.
>
> For example, if your extension creates another thread or spawns another
> process and that other thread/process doesn't clean up on a restart and
> contains a memory leak, what good is restart to you? Restart has suddenly
> become pointless.
>
> It is good etiquette to honour the concept of a restart.
>

Okay, point taken. My extension indeed creates a thread. How can I know that
a user issues a restart? In other words, where can I kill my thread?

Cheers,
Andrej

Re: post_config on reload

Posted by Joe Lewis <jo...@joe-lewis.com>.
Andrej van der Zee wrote:
> Hi,
>
> I was wondering if there is a solution for detecting a post_config
> invocation on behalf of "apachctl restart" instead of a clean start (in case
> of a restart, I do not want to initialise my stuff again).
>   

Do not do this -  a restart should be a restart, not a half of a 
restart.  You should be reinitializing whatever you do on a restart as 
well as a start.  That's the whole point.

I have one phrase that should illustrate why : memory leak.

For example, if your extension creates another thread or spawns another 
process and that other thread/process doesn't clean up on a restart and 
contains a memory leak, what good is restart to you? Restart has 
suddenly become pointless.

It is good etiquette to honour the concept of a restart.

Joe