Thank you very much for your promptness. I've tested and segfaults if I unload the module. In order to resolve this problem I use a flag which is true if everything went fine, and false if didn't, but I thought that you can unload the module if something goes wrong.
I'm using "post_config" to initialize some structures some of them based on the configuration read form httpd.conf . Here is the place where I get some shared memory, and mutex. In the same hook I used apr_pool_cleanup_register but doesn't work. After apache exits "ipcs" command shows my shm & mutex. ipcrm helps to clear IPCs. Indeed all IPC used by children, after exit are freed (due to apr_pool_cleanup_register), but the main process, the parent of these children doesn't de-allocates & destroies the shm segment for example. The children only detach the sahred memory, but the main process should destroy it. This segment is created by main httpd process at startup and used by all other httpd's children. Sorry if I'm not very clear ... My problem is that I don't know how to make the main httpd process, which runs as root, to dealocate some IPC at exit, that were created at its startup. Thank you again. Have I nice day! ----- Original Message ---- From: Joe Lewis <[EMAIL PROTECTED]> To: [email protected] Sent: Monday, October 15, 2007 9:04:35 PM Subject: Re: [Unload module] Marin Cosmin wrote: > Hello, > > I'm working on an Apache module that will log some statistics in a file. > My problem is that I have no ideea about what should I do to unload the module. > In ap_hook_post_config hook I initialize some structures, use open() for some files ... > If I get an error during this phase how can I unload the module ? > > I'm not sure that unloading the module is a good idea. I'd suggest using one of the *open_logs or *post_config hooks - and return an appropriate error code if failure occurs. If you find that apache continues to load, then you may want to set a flag in a configuration structure that you can use to determine if you had success earlier. (For example, so that you don't try to write statistics to a file that failed to open earlier). > Where should I destroy IPCS ? > I used apr_pool_cleanup_register here but the behaviuor isn't the desired one. > > Using apr_pool_cleanup_register in ap_hook_child_init seems to work. > That is where you want it - when the child starts, each child needs to be able to clean up after itself, hence wait until the child starts to register that one. This is a bit more clear when comparing worker vs. prefork MPM's - each child process has to take care of it's own in order to prevent memory leaks, etc. Joe -- Joseph Lewis <http://sharktooth.org/> "Divide the fire, and you will sooner put it out." - Publius Syrus ____________________________________________________________________________________ Building a website is a piece of cake. Yahoo! Small Business gives you all the tools to get online. http://smallbusiness.yahoo.com/webhosting
