On Wed, Sep 18, 2002 at 10:24:43AM +0100, Thom May wrote:
> Shared memory (as used by at least the ssl module) needs to rethink
> how they go about cleaning it up. Currently kill -9 the apache
> processes or it would appear that even /etc/init.d/apache2 reload will
> cause apache to fail to start because the shared memory segment can't
> be created since it already exists.
Any time you use SIGKILL you're going to have to manually clean up
semaphores, segments, and other shared resources. The solution to
that is to not use kill -9.
> There are a couple solutions to this. If the shared memory segment
> already exists just attach to it, but this has security issues.
It's not so much about security as it is about not knowing if there
is a current generation of httpd processes still using it or if it's
safe to jump right in and start reusing the same segment. I can't
think of any robust ways to detect this.
> If the shared memory segment already exists pick another magic number
> and try again, this could eventually leave many unused shared memory
> regious laying around.
At some point you will run out of system resources. The right thing
to do is to not use kill -9 and if you must, to make sure you clean
up your shared resources.
An alternative, since Debian/Linux has a robust VM system, would be
to make sure Apache uses an mmap()-based shared memory syscall. This
would take some tweaking of the autoconf scripts.
> This is how I've done it in the past. Allocate the shared memory
> segment, attach to it, delete it. It will stick around until the last
> process detaches. We just need to use the shmid to attach to our
> segment instead of using the key.
I tried this when I was writing the new apr_shm.h stuff, but the problem
is once you mark a segment for deletion, no new processes can attach
to it (including children, if I remember correctly).
-aaron