You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by rb...@locus.apache.org on 2000/06/10 03:36:00 UTC

cvs commit: apache-2.0/src/modules/mpm/dexter dexter.c mpm_default.h scoreboard.c

rbb         00/06/09 18:36:00

  Modified:    src/modules/mpm/dexter dexter.c mpm_default.h scoreboard.c
  Log:
  Update the Dexter MPM to use APR for shared memory.  This removes a lot
  of duplicate code and allows me to clean up some config stuff in a few
  minutes.
  
  Revision  Changes    Path
  1.91      +15 -0     apache-2.0/src/modules/mpm/dexter/dexter.c
  
  Index: dexter.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/modules/mpm/dexter/dexter.c,v
  retrieving revision 1.90
  retrieving revision 1.91
  diff -u -r1.90 -r1.91
  --- dexter.c	2000/06/05 19:44:01	1.90
  +++ dexter.c	2000/06/10 01:35:59	1.91
  @@ -92,6 +92,7 @@
   static int max_threads = 0;
   static int max_requests_per_child = 0;
   static char *ap_pid_fname=NULL;
  +API_VAR_EXPORT char *ap_scoreboard_fname=NULL;
   static int num_daemons=0;
   static int workers_may_exit = 0;
   static int requests_this_child;
  @@ -1237,6 +1238,7 @@
       max_spare_threads = DEFAULT_MAX_SPARE_THREAD;
       max_threads = HARD_THREAD_LIMIT;
       ap_pid_fname = DEFAULT_PIDLOG;
  +    ap_scoreboard_fname = DEFAULT_SCOREBOARD;
       lock_fname = DEFAULT_LOCKFILE;
       max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
       ap_dexter_set_maintain_connection_status(1);
  @@ -1266,6 +1268,17 @@
       return NULL;
   }
   
  +static const char *set_scoreboard(cmd_parms *cmd, void *dummy, char *arg)
  +{
  +    const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
  +    if (err != NULL) {
  +        return err;
  +    }
  +
  +    ap_scoreboard_fname = arg;
  +    return NULL;
  +}
  +
   static const char *set_lockfile(cmd_parms *cmd, void *dummy, char *arg) 
   {
       const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
  @@ -1434,6 +1447,8 @@
   LISTEN_COMMANDS
   { "PidFile", set_pidfile, NULL, RSRC_CONF, TAKE1,
       "A file for logging the server process ID"},
  +{ "ScoreBoardFile", set_scoreboard, NULL, RSRC_CONF, TAKE1,
  +    "A file for Apache to maintain runtime process management information"},
   { "LockFile", set_lockfile, NULL, RSRC_CONF, TAKE1,
       "The lockfile used when Apache needs to lock the accept() call"},
   { "NumServers", set_num_daemons, NULL, RSRC_CONF, TAKE1,
  
  
  
  1.6       +5 -0      apache-2.0/src/modules/mpm/dexter/mpm_default.h
  
  Index: mpm_default.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/modules/mpm/dexter/mpm_default.h,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- mpm_default.h	2000/03/31 09:05:04	1.5
  +++ mpm_default.h	2000/06/10 01:35:59	1.6
  @@ -117,6 +117,11 @@
   #define DEFAULT_LOCKFILE "logs/accept.lock"
   #endif
   
  +/* Scoreboard file, if there is one */
  +#ifndef DEFAULT_SCOREBOARD
  +#define DEFAULT_SCOREBOARD "logs/apache_runtime_status"
  +#endif
  +
   /* Where the main/parent process's pid is logged */
   #ifndef DEFAULT_PIDLOG
   #define DEFAULT_PIDLOG "logs/httpd.pid"
  
  
  
  1.15      +25 -341   apache-2.0/src/modules/mpm/dexter/scoreboard.c
  
  Index: scoreboard.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/modules/mpm/dexter/scoreboard.c,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- scoreboard.c	2000/05/18 23:25:01	1.14
  +++ scoreboard.c	2000/06/10 01:35:59	1.15
  @@ -68,22 +68,9 @@
   #include "scoreboard.h"
   #include "mpm.h" /* for ap_max_daemons_limit */
   #include <sys/types.h>
  -#ifdef USE_SHMGET_SCOREBOARD
  -#include <sys/ipc.h>
  -#include <sys/shm.h>
  -#endif
   
  -#ifdef USE_OS2_SCOREBOARD
  -    /* Add MMAP style functionality to OS/2 */
  -#define INCL_DOSMEMMGR
  -#define INCL_DOSEXCEPTIONS
  -#define INCL_DOSSEMAPHORES
  -#include <os2.h>
  -#include <umalloc.h>
  -#include <stdio.h>
  -#endif
  -
   static scoreboard *ap_scoreboard_image = NULL;
  +API_VAR_EXPORT char *ap_scoreboard_fname;
   
   /*****************************************************************
    *
  @@ -93,354 +80,51 @@
    *
    * We begin with routines which deal with the file itself... 
    */
  -
  -#if defined(USE_OS2_SCOREBOARD)
  -
  -/* The next two routines are used to access shared memory under OS/2.  */
  -/* This requires EMX v09c to be installed.                           */
  -
  -caddr_t create_shared_heap(const char *name, size_t size)
  -{
  -    ULONG rc;
  -    void *mem;
  -    Heap_t h;
  -
  -    rc = DosAllocSharedMem(&mem, name, size,
  -			   PAG_COMMIT | PAG_READ | PAG_WRITE);
  -    if (rc != 0)
  -	return NULL;
  -    h = _ucreate(mem, size, !_BLOCK_CLEAN, _HEAP_REGULAR | _HEAP_SHARED,
  -		 NULL, NULL);
  -    if (h == NULL)
  -	DosFreeMem(mem);
  -    return (caddr_t) h;
  -}
  -
  -caddr_t get_shared_heap(const char *Name)
  -{
  -
  -    PVOID BaseAddress;		/* Pointer to the base address of
  -				   the shared memory object */
  -    ULONG AttributeFlags;	/* Flags describing characteristics
  -				   of the shared memory object */
  -    APIRET rc;			/* Return code */
  -
  -    /* Request read and write access to */
  -    /*   the shared memory object       */
  -    AttributeFlags = PAG_WRITE | PAG_READ;
  -
  -    rc = DosGetNamedSharedMem(&BaseAddress, Name, AttributeFlags);
  -
  -    if (rc != 0) {
  -	printf("DosGetNamedSharedMem error: return code = %ld", rc);
  -	return 0;
  -    }
  -
  -    return BaseAddress;
  -}
  -
  -static void setup_shared_mem(ap_pool_t *p)
  -{
  -    caddr_t m;
   
  -    int rc;
  +#if APR_HAS_SHARED_MEMORY
  +#include "apr_shmem.h"
   
  -    m = (caddr_t) create_shared_heap("\\SHAREMEM\\SCOREBOARD", SCOREBOARD_SIZE);
  -    if (m == 0) {
  -	ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, 
  -                     "%s: Could not create OS/2 Shared memory pool.",
  -		     ap_server_argv0);
  -	exit(APEXIT_INIT);
  -    }
  +static ap_shmem_t *scoreboard_shm = NULL;
   
  -    rc = _uopen((Heap_t) m);
  -    if (rc != 0) {
  -	ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL,
  -		"%s: Could not uopen() newly created OS/2 Shared memory pool.",
  -		ap_server_argv0);
  -    }
  -    ap_scoreboard_image = (scoreboard *) m;
  -}
  -
  -API_EXPORT(void) reopen_scoreboard(ap_pool_t *p)
  +static ap_status_t cleanup_shared_mem(void *d)
   {
  -    caddr_t m;
  -    int rc;
  -
  -    m = (caddr_t) get_shared_heap("\\SHAREMEM\\SCOREBOARD");
  -    if (m == 0) {
  -	ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, 
  -                     "%s: Could not find existing OS/2 Shared memory pool.",
  -		ap_server_argv0);
  -	exit(APEXIT_INIT);
  -    }
  -
  -    rc = _uopen((Heap_t) m);
  -    ap_scoreboard_image = (scoreboard *) m;
  +    ap_shm_free(scoreboard_shm, ap_scoreboard_image);
  +    ap_scoreboard_image = NULL;
  +    ap_shm_destroy(scoreboard_shm);
  +    return APR_SUCCESS;
   }
   
  -#elif defined(USE_POSIX_SCOREBOARD)
  -#include <sys/mman.h>
  -/* 
  - * POSIX 1003.4 style
  - *
  - * Note 1: 
  - * As of version 4.23A, shared memory in QNX must reside under /dev/shmem,
  - * where no subdirectories allowed.
  - *
  - * POSIX shm_open() and shm_unlink() will take care about this issue,
  - * but to avoid confusion, I suggest to redefine scoreboard file name
  - * in httpd.conf to cut "logs/" from it. With default setup actual name
  - * will be "/dev/shmem/logs.apache_status". 
  - * 
  - * If something went wrong and Apache did not unlinked this object upon
  - * exit, you can remove it manually, using "rm -f" command.
  - * 
  - * Note 2:
  - * <sys/mman.h> in QNX defines MAP_ANON, but current implementation 
  - * does NOT support BSD style anonymous mapping. So, the order of 
  - * conditional compilation is important: 
  - * this #ifdef section must be ABOVE the next one (BSD style).
  - *
  - * I tested this stuff and it works fine for me, but if it provides 
  - * trouble for you, just comment out USE_MMAP_SCOREBOARD in QNX section
  - * of ap_config.h
  - *
  - * June 5, 1997, 
  - * Igor N. Kovalenko -- infoh@mail.wplus.net
  - */
  -
  -static void cleanup_shared_mem(void *d)
  -{
  -    shm_unlink(ap_scoreboard_fname);
  -}
  -
   static void setup_shared_mem(ap_pool_t *p)
   {
       char buf[512];
  -    caddr_t m;
  -    int fd;
  +    const char *fname;
   
  -    fd = shm_open(ap_scoreboard_fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
  -    if (fd == -1) {
  -	ap_snprintf(buf, sizeof(buf), "%s: could not open(create) scoreboard",
  -		    ap_server_argv0);
  -	perror(buf);
  -	exit(APEXIT_INIT);
  -    }
  -    if (ltrunc(fd, (off_t) SCOREBOARD_SIZE, SEEK_SET) == -1) {
  -	ap_snprintf(buf, sizeof(buf), "%s: could not ltrunc scoreboard",
  -		    ap_server_argv0);
  -	perror(buf);
  -	shm_unlink(ap_scoreboard_fname);
  -	exit(APEXIT_INIT);
  +    fname = ap_server_root_relative(p, ap_scoreboard_fname);
  +    if (ap_shm_init(&scoreboard_shm, SCOREBOARD_SIZE + 40, fname, p) != APR_SUCCESS) {
  +        ap_snprintf(buf, sizeof(buf), "%s: could not open(create) scoreboard",
  +                    ap_server_argv0);
  +        perror(buf);
  +        exit(APEXIT_INIT);
       }
  -    if ((m = (caddr_t) mmap((caddr_t) 0,
  -			    (size_t) SCOREBOARD_SIZE, PROT_READ | PROT_WRITE,
  -			    MAP_SHARED, fd, (off_t) 0)) == (caddr_t) - 1) {
  -	ap_snprintf(buf, sizeof(buf), "%s: cannot mmap scoreboard",
  -		    ap_server_argv0);
  -	perror(buf);
  -	shm_unlink(ap_scoreboard_fname);
  -	exit(APEXIT_INIT);
  +    ap_scoreboard_image = ap_shm_malloc(scoreboard_shm, SCOREBOARD_SIZE);
  +    if (ap_scoreboard_image == NULL) {
  +        ap_snprintf(buf, sizeof(buf), "%s: cannot allocate scoreboard",
  +                    ap_server_argv0);
  +        perror(buf);
  +        ap_shm_destroy(scoreboard_shm);
  +        exit(APEXIT_INIT);
       }
  -    close(fd);
       ap_register_cleanup(p, NULL, cleanup_shared_mem, ap_null_cleanup);
  -    ap_scoreboard_image = (scoreboard *) m;
  -}
  -
  -API_EXPORT(void) reopen_scoreboard(ap_pool_t *p)
  -{
  -}
  -
  -#elif defined(USE_MMAP_SCOREBOARD)
  -
  -static void setup_shared_mem(ap_pool_t *p)
  -{
  -    caddr_t m;
  -
  -#if defined(MAP_ANON)
  -/* BSD style */
  -#ifdef CONVEXOS11
  -    /*
  -     * 9-Aug-97 - Jeff Venters (venters@convex.hp.com)
  -     * ConvexOS maps address space as follows:
  -     *   0x00000000 - 0x7fffffff : Kernel
  -     *   0x80000000 - 0xffffffff : User
  -     * Start mmapped area 1GB above start of text.
  -     *
  -     * Also, the length requires a pointer as the actual length is
  -     * returned (rounded up to a page boundary).
  -     */
  -    {
  -	unsigned len = SCOREBOARD_SIZE;
  -
  -	m = mmap((caddr_t) 0xC0000000, &len,
  -		 PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, NOFD, 0);
  -    }
  -#elif defined(MAP_TMPFILE)
  -    {
  -	char mfile[] = "/tmp/apache_shmem_XXXX";
  -	int fd = mkstemp(mfile);
  -	if (fd == -1) {
  -	    perror("open");
  -	    ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, 
  -                         "%s: Could not open %s", ap_server_argv0, mfile);
  -	    exit(APEXIT_INIT);
  -	}
  -	m = mmap((caddr_t) 0, SCOREBOARD_SIZE,
  -		PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  -	if (m == (caddr_t) - 1) {
  -	    perror("mmap");
  -	    ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, 
  -                         "%s: Could not mmap %s", ap_server_argv0, mfile);
  -	    exit(APEXIT_INIT);
  -	}
  -	close(fd);
  -	unlink(mfile);
  -    }
  -#else
  -    m = mmap((caddr_t) 0, SCOREBOARD_SIZE,
  -	     PROT_READ | PROT_WRITE, MAP_ANON | MAP_SHARED, -1, 0);
  -#endif
  -    if (m == (caddr_t) - 1) {
  -	perror("mmap");
  -	ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, 
  -                     "%s: Could not mmap memory", ap_server_argv0);
  -	exit(APEXIT_INIT);
  -    }
  -#else
  -/* Sun style */
  -    int fd;
  -
  -    fd = open("/dev/zero", O_RDWR);
  -    if (fd == -1) {
  -	perror("open");
  -	ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, 
  -                     "%s: Could not open /dev/zero", ap_server_argv0);
  -	exit(APEXIT_INIT);
  -    }
  -    m = mmap((caddr_t) 0, SCOREBOARD_SIZE,
  -	     PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
  -    if (m == (caddr_t) - 1) {
  -	perror("mmap");
  -	ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, 
  -                     "%s: Could not mmap /dev/zero", ap_server_argv0);
  -	exit(APEXIT_INIT);
  -    }
  -    close(fd);
  -#endif
  -    ap_scoreboard_image = (scoreboard *) m;
  -}
  -
  -API_EXPORT(void) reopen_scoreboard(ap_pool_t *p)
  -{
  -}
  -
  -#elif defined(USE_SHMGET_SCOREBOARD)
  -static key_t shmkey = IPC_PRIVATE;
  -static int shmid = -1;
  -
  -static void setup_shared_mem(ap_pool_t *p)
  -{
  -    struct shmid_ds shmbuf;
  -    const server_rec * server_conf = ap_get_server_conf();
  -#ifdef MOVEBREAK
  -    char *obrk;
  -#endif
  -
  -    if ((shmid = shmget(shmkey, SCOREBOARD_SIZE, IPC_CREAT | SHM_R | SHM_W)) == -1) {
  -#ifdef LINUX
  -	if (errno == ENOSYS) {
  -	    ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_EMERG, errno,
  -                         server_conf,
  -			 "Your kernel was built without CONFIG_SYSVIPC\n"
  -			 "%s: Please consult the Apache FAQ for details",
  -			 ap_server_argv0);
  -	}
  -#endif
  -	ap_log_error(APLOG_MARK, APLOG_EMERG, errno, server_conf,
  -		    "could not call shmget");
  -	exit(APEXIT_INIT);
  -    }
  -
  -    ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, errno, server_conf,
  -		"created shared memory segment #%d", shmid);
  -
  -#ifdef MOVEBREAK
  -    /*
  -     * Some SysV systems place the shared segment WAY too close
  -     * to the dynamic memory break point (sbrk(0)). This severely
  -     * limits the use of malloc/sbrk in the program since sbrk will
  -     * refuse to move past that point.
  -     *
  -     * To get around this, we move the break point "way up there",
  -     * attach the segment and then move break back down. Ugly
  -     */
  -    if ((obrk = sbrk(MOVEBREAK)) == (char *) -1) {
  -	ap_log_error(APLOG_MARK, APLOG_ERR, errno, server_conf,
  -	    "sbrk() could not move break");
  -    }
  -#endif
  -
  -#define BADSHMAT	((scoreboard *)(-1))
  -    if ((ap_scoreboard_image = (scoreboard *) shmat(shmid, 0, 0)) == BADSHMAT) {
  -	ap_log_error(APLOG_MARK, APLOG_EMERG, errno, server_conf,
  -                     "shmat error");
  -	/*
  -	 * We exit below, after we try to remove the segment
  -	 */
  -    }
  -    else {			/* only worry about permissions if we attached the segment */
  -	if (shmctl(shmid, IPC_STAT, &shmbuf) != 0) {
  -	    ap_log_error(APLOG_MARK, APLOG_ERR, errno, server_conf,
  -		"shmctl() could not stat segment #%d", shmid);
  -	}
  -	else {
  -	    shmbuf.shm_perm.uid = unixd_config.user_id;
  -	    shmbuf.shm_perm.gid = unixd_config.group_id;
  -	    if (shmctl(shmid, IPC_SET, &shmbuf) != 0) {
  -		ap_log_error(APLOG_MARK, APLOG_ERR, errno, server_conf,
  -		    "shmctl() could not set segment #%d", shmid);
  -	    }
  -	}
  -    }
  -    /*
  -     * We must avoid leaving segments in the kernel's
  -     * (small) tables.
  -     */
  -    if (shmctl(shmid, IPC_RMID, NULL) != 0) {
  -	ap_log_error(APLOG_MARK, APLOG_WARNING, errno, server_conf,
  -		"shmctl: IPC_RMID: could not remove shared memory segment #%d",
  -		shmid);
  -    }
  -    if (ap_scoreboard_image == BADSHMAT)	/* now bailout */
  -	exit(APEXIT_INIT);
  -
  -#ifdef MOVEBREAK
  -    if (obrk == (char *) -1)
  -	return;			/* nothing else to do */
  -    if (sbrk(-(MOVEBREAK)) == (char *) -1) {
  -	ap_log_error(APLOG_MARK, APLOG_ERR, errno, server_conf,
  -	    "sbrk() could not move break back");
  -    }
  -#endif
   }
   
  -API_EXPORT(void) reopen_scoreboard(ap_pool_t *p)
  -{
  -}
  -
  -#endif
  -
  -/* Called by parent process */
   void reinit_scoreboard(ap_pool_t *p)
   {
       if (ap_scoreboard_image == NULL) {
  -	setup_shared_mem(p);
  +        setup_shared_mem(p);
       }
       memset(ap_scoreboard_image, 0, SCOREBOARD_SIZE);
   }
  +#endif   /* APR_SHARED_MEM */
   
   /****
    * Above code is shmem code. Below code is interacting with the shmem