SOLVED-- Apache Shared Mem Really Isn't Shared

SOLVED-- Apache Shared Mem Really Isn't Shared

Post by pacm.. » Sun, 01 Oct 2000 04:00:00



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
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <sys/mman.h>
#include "httpd.h"
#include "http_config.h"
#include "http_log.h"
#include "http_protocol.h"
#include "http_request.h"
#include "http_core.h"

caddr_t *test;

// THIS IS YOUR MODULE HANDLER
static int your_handler(request_rec *r)
{
   test = (caddr_t *) ap_get_module_config(r->server->module_config,
                      &thesite_module );
   // DO WHAT EVERY YOU WANT WITH YOUR SHARED MEMORY

Quote:}

static void *mconfig_for_server(pool *p, server_rec *s)
{
   int fd;
   caddr_t mm;
   int size = 64;  // SIZE(IN BYTES) YOU WISH TO ALLOC

   ap_block_alarms();
   // 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);
   close(fd);
   *mm = 0; // STORE WHATEVER DATA YOU WANT INTO YOUR SHARED MEMORY
   ap_unblock_alarms();

   return mm;

Quote:}

// REST OF MODULE REQUIREMENT CODE GOES BELOW

-------------------------/

Paul_L

Sent via Deja.com http://www.deja.com/
Before you buy.

 
 
 

SOLVED-- Apache Shared Mem Really Isn't Shared

Post by pacm.. » Fri, 06 Oct 2000 04:00:00


Quote:>    fd = open("/home/nobody/nobody.txt", O_RDWR , 0);

Also be aware that the dummy file nobody.txt must be the same or
greater size of the amount of memory that you want to alloc.  Make sure
file attributes of nobody.txt is read / writable.  Again, nobody.txt
can be in any path and any name just as long as it's accessible to the
user nobody or whatever your httpd processes are running as.

Paul_L

Sent via Deja.com http://www.deja.com/
Before you buy.