Ilya Obshadko <[EMAIL PROTECTED]> wrote:
>Hello modperl,
>
> Yet another mystic thing. I've been messing around with
> IPC::Shareable. The purpose was just simple: create shared memory
> segment on startup, give access to it for all child processes,
> destroy this segment after httpd shutdown. I've encountered a
> strange problem with the last action. I did not understand what's
> going on until I've printed PIDs that execute cleanup to STDERR.
> Then I found that END block IS NOT BEING EXECUTED BY PARENT
> HTTPD PROCESS. Of course httpd child, that is executed with ordinary
> user privileges, cannot destrroy shm object owned by root :(
What you want to do, I think, is something like the following:
sub tie_keys {
unless(tied %Keys or not defined $IPC::Shareable::VERSION) {
tie(%Keys, 'IPC::Shareable', 'abcd', { # random glue...
mode => 0600, # a bit more secure
destroy => 'no',
exclusive => 'no',
create => 'yes',
});
}
}
if(defined $Apache::VERSION) {
Apache->push_handlers(PerlChildInitHandler => \&tie_keys);
} else {
tie_keys; # we're not in mod_perl
}
When the child cleans up and dies, the hash will be untied. You can't do the tieing
or shared memory creation in the module initialization since the server is running as
root at that point, but nolonger when the child comes along and needs to tie to the
shared memory.
This will not clean up the shared memory when all the children die, since the
`destroy' attribute is set to `no'. If I read the docs correctly, setting it to `yes'
will cause the shared memory to be deleted with the creating process closes the
segment. The above code will reuse the shared memory segment across server restarts.
Whether or not the destruction of the shared memory can be done in the END block, I
don't think it can, but Doug would probably be authoritative on that.
--
James Smith <[EMAIL PROTECTED]>, 409-862-3725
Texas A&M CIS Operating Systems Group, Unix