I'm so glad I finally have some code that allows apache modules to
share memory for reading & writing! Sounds easy? Well I've tried
everything recommended and nothing worked until now.
The problem: if you use standard apache shared ap_palloc function it
really tricks you into thinking you're using shared memory when really
each httpd process running has it's own memory-- at least it does on my
high security mandrake 7.1 linux apache 1.3.12. At init I would set
the shared mem and apache would copy that into all the httpd processes
tricking you into thinking it was one memory. Maybe it's the high
security kernel that comes with mandrake highest security install. BTW,
I love mandrake!!! I've been hacked countless times with redhat and
never with mandrake. Try the paranoid expert install-- it's awesome!
I hope this helps someone else because I've spent weeks on this. Here's
the basic code that works for me.
// BASIC APACHED MODULE SHARED MEMORY FOR READ AND WRITING
// THIS IS YOUR MODULE HANDLER
static int your_handler(request_rec *r)
test = (caddr_t *) ap_get_module_config(r->server->module_config,
// DO WHAT EVERY YOU WANT WITH YOUR SHARED MEMORY
static void *mconfig_for_server(pool *p, server_rec *s)Quote:}
int size = 64; // SIZE(IN BYTES) YOU WISH TO ALLOC
// USE ANY FILE & PATH THAT YOUR httpd PROCESS CAN WRITE TO.
// THE FILE DOES NOT NEED TO EXITS.
// YOUR APACHE PROCESSES WILL PROBABLY BE RUNNING AS nobody, SO
// MAKE SURE THE PATH IS ACCESSIBLE TO nobody
fd = open("/home/nobody/nobody.txt", O_RDWR , 0);
mm = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
*mm = 0; // STORE WHATEVER DATA YOU WANT INTO YOUR SHARED MEMORY
// REST OF MODULE REQUIREMENT CODE GOES BELOWQuote:}
Sent via Deja.com http://www.deja.com/
Before you buy.