The following reply was made to PR general/3937; it has been noted by GNATS.

From: "Ralf S. Engelschall" <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
Cc:  Subject: Re: general/3937: Design issues concerning shared memory.
Date: Wed, 10 Mar 1999 13:29:19 +0100

 In article <[EMAIL PROTECTED]> you wrote:
 
 > I've just completed a rewrite of the mod_throttle.c code for Apache 1.3.x 
 > that
 > allows throttling based on virtual servers.  This module requires the use of
 > shared memory in order to properly keep track of the number of bytes_sent for
 > a virtual server. 
 > 
 > Now there is no pool management for shared memory, that I can see.  Also 
 > there
 > doesn't not appear to be any module handler called when parent server 
 > terminates,
 > which would permit the proper release of shared memory.
 > 
 > As a result, shared memory resources appear to "leak" in that they are 
 > consumed
 > and never released when ever the server is stopped and/or restarted.  User 
 > intervention is then required to issue an "ipcrm" command.
 > 
 > I believe this is a design-flaw in the module handler structure, lack a 
 > server termination handler; however, as I've just learned new skills for
 > this project (how to write an Apache module and use of shared memory) it
 > may be a covered by some Apache API and/or a fault in my understanding.
 
 Two things:
 
 1. I've already started to integrate a shared memory pool facility
    into Apache 1.3 by the help of a library I've recently written for this
    purpose. A first cut for a patch was already posted to the new-httpd
    mailing list. I hope that in the near future Apache 1.3 provides both heap
    and shared memory based allocation through it's pool concept.
 
 2. In the meantime, when you use IPC Shared Memory you should
    do it this way (extracted from my librarys code):
 
     if ((fdmem = shmget(IPC_PRIVATE, size, (SHM_R|SHM_W|IPC_CREAT))) == -1)
         FAIL;
     if ((area = (void *)shmat(fdmem, NULL, 0)) == ((void *)-1))
         FAIL;
     if (shmctl(fdmem, IPC_STAT, &shmbuf) == -1)
         FAIL;
     shmbuf.shm_perm.uid = getuid();
     shmbuf.shm_perm.gid = getgid();
     if (shmctl(fdmem, IPC_SET, &shmbuf) == -1)
         FAIL;
     if (shmctl(fdmem, IPC_RMID, NULL) == -1)
         FAIL;
 
   The important point is the shmctl() with IPC_RMID _after_ the shmat() but
   before a corresponding shmdt(). This at least makes sure no shared memory
   segments are staying around after Apache exists. Perhaps this helps.
 
                                        Ralf S. Engelschall
                                        [EMAIL PROTECTED]
                                        www.engelschall.com

Reply via email to