You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by venky_naganathan <ve...@yahoo.com> on 2005/04/02 02:41:43 UTC

Re: Fw: apr_shm_create

I had the same issue. It appears to be bug in apr_shm_create in 
Apache 2.0. The bug is hard to characterize. The first time i start 
it would fail. (My filename was based on pid of the httpd process. 
Then i would stop apache & restart retaining the old shmem file, it 
would work. If i cleanup the old shmem file it would not.

I have finally managed to workaround it.
Instead of passing a filename to apr_shm_create i pass a NULL.
Now im able to predictably create/allocate shared memory

--- In new-httpd@yahoogroups.com, "Nedelcho Stanev" <de...@s...> 
wrote:
> sending this twice, since i did'n get this in mail list.
> may be there are some problem ?
> 
> ----- Original Message ----- 
> From: Nedelcho Stanev 
> To: dev@h... 
> Sent: Friday, August 15, 2003 2:43 PM
> Subject: apr_shm_create
> 
> 
> Hello All,
> 
> i have this problem when i use shared memory with Apache.
> Apache is 2.0.47, compiled on Red Hat linux 8 with kernel 2.4.18-14.
> Same module and same Apache on Windows work perfect, but on linux
> i have some problems.
> so ...
> i create shared memory block with 
> sts = apr_shm_create(&client_shm, shmem_size, MOD_MQUBE_SHMEMFILE, 
ctx);
> in initialize_module of my module.
> in same function i add cleanup callback with  
apr_pool_cleanup_register
> in this callbeck i do cleaning with
> apr_shm_destroy(client_shm);
> client_shm = NULL;
> 
> when i stop and start apache properly all works perfect :) but
> if server crash, or i kill it with -9 , then in /tmp directory i 
still have MOD_MQUBE_SHMEMFILE 
> file still. and this is ok, because cleanup callback is not called
> but when i start again apache apr_shm_create doesent work.
> goin in a deep, i see that in sorce of this function ( unix/shm.c)
> problem come from here :
> if ((new_m->shmid = shmget(shmkey, new_m->realsize,
> befor this line we have
> status = apr_file_open(&file, filename, 
> and this create file correctly
> but shmget return error - File exists
> 
> so, does anyone know why this happens? :)
> btw , same effect is if i don't delete this file from tmp directory
> but, even if i delete it apache cannot allocate shared memory.
> 
> 
> decho




RE: Fw: apr_shm_create

Posted by Frédéric Bor <fr...@wanadoo.fr>.
I'm using apr shm facilities in my module and it's working fine (on
linux/win32/solaris).

For Nedelcho's problem, you can use a named shared memory segment with
apr_shm_create but if you kill server process or if server crash, you have
to remove the segment from the kernel (see commands like ipcs and ipcrm) or
the used name will stay in used state for the system (error message 'File
exists' does not necessary mean that the hard disk file still exist).

For your problem, how were you creating and attaching the segment?


-----Message d'origine-----
De : venky_naganathan [mailto:venky_naganathan@yahoo.com] 
Envoyé : samedi 2 avril 2005 02:42
À : dev@httpd.apache.org
Objet : Re: Fw: apr_shm_create


I had the same issue. It appears to be bug in apr_shm_create in 
Apache 2.0. The bug is hard to characterize. The first time i start 
it would fail. (My filename was based on pid of the httpd process. 
Then i would stop apache & restart retaining the old shmem file, it 
would work. If i cleanup the old shmem file it would not.

I have finally managed to workaround it.
Instead of passing a filename to apr_shm_create i pass a NULL.
Now im able to predictably create/allocate shared memory

--- In new-httpd@yahoogroups.com, "Nedelcho Stanev" <de...@s...> 
wrote:
> sending this twice, since i did'n get this in mail list.
> may be there are some problem ?
> 
> ----- Original Message ----- 
> From: Nedelcho Stanev 
> To: dev@h... 
> Sent: Friday, August 15, 2003 2:43 PM
> Subject: apr_shm_create
> 
> 
> Hello All,
> 
> i have this problem when i use shared memory with Apache.
> Apache is 2.0.47, compiled on Red Hat linux 8 with kernel 2.4.18-14.
> Same module and same Apache on Windows work perfect, but on linux
> i have some problems.
> so ...
> i create shared memory block with 
> sts = apr_shm_create(&client_shm, shmem_size, MOD_MQUBE_SHMEMFILE, 
ctx);
> in initialize_module of my module.
> in same function i add cleanup callback with  
apr_pool_cleanup_register
> in this callbeck i do cleaning with
> apr_shm_destroy(client_shm);
> client_shm = NULL;
> 
> when i stop and start apache properly all works perfect :) but
> if server crash, or i kill it with -9 , then in /tmp directory i 
still have MOD_MQUBE_SHMEMFILE 
> file still. and this is ok, because cleanup callback is not called
> but when i start again apache apr_shm_create doesent work.
> goin in a deep, i see that in sorce of this function ( unix/shm.c)
> problem come from here :
> if ((new_m->shmid = shmget(shmkey, new_m->realsize,
> befor this line we have
> status = apr_file_open(&file, filename, 
> and this create file correctly
> but shmget return error - File exists
> 
> so, does anyone know why this happens? :)
> btw , same effect is if i don't delete this file from tmp directory
> but, even if i delete it apache cannot allocate shared memory.
> 
> 
> decho