httpd-modules-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sorin Manolache" <sor...@gmail.com>
Subject Re: APR, Shared Memory and extern process
Date Tue, 18 Nov 2008 20:49:51 GMT
On Tue, Nov 18, 2008 at 20:17, ricardo13 <ricardoogrande@gmail.com> wrote:
>
> Hi,
>
> I'm writing a apache's module that comunicate with a extern process.
>
> My extern process is built in C:
>
>        char*  shm_address;
>        int    shmid;
>        key_t  shmkey;
>
>        shmkey = 5678;
>        shmid = shmget(shmkey, SIZEOFSHMSEG, 0666);
>        if (shmid == -1)
>                printf("main: shmget() failed\n");
>
>        shm_address = shmat(shmid, NULL, 0);
>        if ( shm_address==NULL )
>                printf("main: shmat() failed\n");
>
>        while(1) {
>                if(strcmp(shm_address, ":") == 0) {
>                        strcpy(shm_address, data);
>                        break;
>                }
>        }
>
>        int rc = shmdt(shm_address);
>        if (rc==-1)
>                printf("main: shmdt() failed\n");
>
>
> Now I want to write a module that take (or get) the information in this
> segment.
> Can someone help me ??
>
> Thank You
>
> Ricardo

Use the post_config hook because it is run in the parent of all apache
children. There, you simply shmget and shmat. Also, use
apr_pool_register_cleanup in order to register a callback that will
shmdt your shared memory segment when the config pool is destroyed,
i.e. when apache is killed or the configuration reloaded.

I hope this helps. If not, I must have some code skeleton at work, I
can find it tomorrow for you.

S

Mime
View raw message