To allow Apache (and others) to control various things when creating shared memory, I've added apr_shm_create_ex. At present, we just have the bit flags for controlling the uid/gid bits of SysV shared memory, but the capability is there for more :)
Comments: Index: include/apr_shm.h =================================================================== RCS file: /home/cvs/apr/include/apr_shm.h,v retrieving revision 1.2 diff -u -r1.2 apr_shm.h --- include/apr_shm.h 13 Mar 2002 20:39:15 -0000 1.2 +++ include/apr_shm.h 27 Sep 2002 13:28:56 -0000 @@ -81,6 +81,44 @@ typedef struct apr_shm_t apr_shm_t; /** + * Public possible bit settings for use by apr_shm_create_ex(). + */ +enum { + APR_SHMEM_SYSV_ANON_SETUGID = 0x1, + APR_SHMEM_SYSV_NAMED_SETUGID = 0x2 +}; + +/** + * Create and make accessable a shared memory segment with optional bit flags. + * @param m The shared memory structure to create. + * @param reqsize The desired size of the segment. + * @param file The file to use for shared memory on platforms that + * require it. + * @param pool the pool from which to allocate the shared memory + * structure. + * @param bflags bit flag controlling behavior or settings of segment + * @remark A note about Anonymous vs. Named shared memory segments: + * Not all plaforms support anonymous shared memory segments, but in + * some cases it is prefered over other types of shared memory + * implementations. Passing a NULL 'file' parameter to this function + * will cause the subsystem to use anonymous shared memory segments. + * If such a system is not available, APR_ENOTIMPL is returned. + * @remark A note about allocation sizes: + * On some platforms it is necessary to store some metainformation + * about the segment within the actual segment. In order to supply + * the caller with the requested size it may be necessary for the + * implementation to request a slightly greater segment length + * from the subsystem. In all cases, the apr_shm_baseaddr_get() + * function will return the first usable byte of memory. + * + */ +APR_DECLARE(apr_status_t) apr_shm_create_ex(apr_shm_t **m, + apr_size_t reqsize, + const char *filename, + apr_pool_t *pool, + int bflags); + +/** * Create and make accessable a shared memory segment. * @param m The shared memory structure to create. * @param reqsize The desired size of the segment. Index: shmem/beos/shm.c =================================================================== RCS file: /home/cvs/apr/shmem/beos/shm.c,v retrieving revision 1.9 diff -u -r1.9 shm.c --- shmem/beos/shm.c 13 Mar 2002 20:39:26 -0000 1.9 +++ shmem/beos/shm.c 27 Sep 2002 13:28:56 -0000 @@ -71,10 +71,11 @@ area_id aid; }; -APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m, +APR_DECLARE(apr_status_t) apr_shm_create_ex(apr_shm_t **m, apr_size_t reqsize, const char *file, - apr_pool_t *p) + apr_pool_t *p, + int bflags) { apr_size_t pagesize; area_id newid; @@ -98,6 +99,14 @@ (*m)->reqsize = reqsize; return APR_SUCCESS; +} + +APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m, + apr_size_t reqsize, + const char *file, + apr_pool_t *p) +{ + return apr_shm_create_ex(m, reqsize, file, p, 0); } APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shm_t *m) Index: shmem/os2/shm.c =================================================================== RCS file: /home/cvs/apr/shmem/os2/shm.c,v retrieving revision 1.7 diff -u -r1.7 shm.c --- shmem/os2/shm.c 13 Mar 2002 20:39:26 -0000 1.7 +++ shmem/os2/shm.c 27 Sep 2002 13:28:56 -0000 @@ -64,10 +64,11 @@ void *memblock; }; -APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m, +APR_DECLARE(apr_status_t) apr_shm_create_ex(apr_shm_t **m, apr_size_t reqsize, const char *filename, - apr_pool_t *pool) + apr_pool_t *pool, + int bflags) { int rc; apr_shm_t *newm = (apr_shm_t *)apr_palloc(pool, sizeof(apr_shm_t)); @@ -92,6 +93,14 @@ *m = newm; return APR_SUCCESS; +} + +APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m, + apr_size_t reqsize, + const char *filename, + apr_pool_t *pool) +{ + return apr_shm_create_ex(m, reqsize, filename, pool, 0); } APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shm_t *m) Index: shmem/unix/shm.c =================================================================== RCS file: /home/cvs/apr/shmem/unix/shm.c,v retrieving revision 1.18 diff -u -r1.18 shm.c --- shmem/unix/shm.c 16 Apr 2002 20:25:57 -0000 1.18 +++ shmem/unix/shm.c 27 Sep 2002 13:28:57 -0000 @@ -127,10 +127,11 @@ return APR_ENOTIMPL; } -APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m, +APR_DECLARE(apr_status_t) apr_shm_create_ex(apr_shm_t **m, apr_size_t reqsize, const char *filename, - apr_pool_t *pool) + apr_pool_t *pool, + int bflags) { apr_shm_t *new_m; apr_status_t status; @@ -241,10 +242,12 @@ return errno; } apr_current_userid(&uid, &gid, pool); - shmbuf.shm_perm.uid = uid; - shmbuf.shm_perm.gid = gid; - if (shmctl(new_m->shmid, IPC_SET, &shmbuf) == -1) { - return errno; + if (bflags & APR_SHMEM_SYSV_ANON_SETUGID) { + shmbuf.shm_perm.uid = uid; + shmbuf.shm_perm.gid = gid; + if (shmctl(new_m->shmid, IPC_SET, &shmbuf) == -1) { + return errno; + } } /* Remove the segment once use count hits zero. @@ -388,10 +391,12 @@ return errno; } apr_current_userid(&uid, &gid, pool); - shmbuf.shm_perm.uid = uid; - shmbuf.shm_perm.gid = gid; - if (shmctl(new_m->shmid, IPC_SET, &shmbuf) == -1) { - return errno; + if (bflags & APR_SHMEM_SYSV_NAMED_SETUGID) { + shmbuf.shm_perm.uid = uid; + shmbuf.shm_perm.gid = gid; + if (shmctl(new_m->shmid, IPC_SET, &shmbuf) == -1) { + return errno; + } } nbytes = sizeof(reqsize); @@ -414,6 +419,14 @@ } return APR_ENOTIMPL; +} + +APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m, + apr_size_t reqsize, + const char *filename, + apr_pool_t *pool) +{ + return apr_shm_create_ex(m, reqsize, filename, pool, 0); } APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shm_t *m) Index: shmem/win32/shm.c =================================================================== RCS file: /home/cvs/apr/shmem/win32/shm.c,v retrieving revision 1.12 diff -u -r1.12 shm.c --- shmem/win32/shm.c 31 Jul 2002 06:20:15 -0000 1.12 +++ shmem/win32/shm.c 27 Sep 2002 13:28:57 -0000 @@ -89,10 +89,11 @@ return rv; } -APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m, +APR_DECLARE(apr_status_t) apr_shm_create_ex(apr_shm_t **m, apr_size_t reqsize, const char *file, - apr_pool_t *pool) + apr_pool_t *pool, + int bflags) { static apr_size_t memblock = 0; HANDLE hMap, hFile; @@ -187,6 +188,14 @@ apr_pool_cleanup_register((*m)->pool, *m, shm_cleanup, apr_pool_cleanup_null); return APR_SUCCESS; +} + +APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m, + apr_size_t reqsize, + const char *file, + apr_pool_t *pool) +{ + return apr_shm_create_ex(m, reqsize, file, pool, 0); } APR_DECLARE(apr_status_t) apr_shm_destroy(apr_shm_t *m) -- =========================================================================== Jim Jagielski [|] [EMAIL PROTECTED] [|] http://www.jaguNET.com/ "A society that will trade a little liberty for a little order will lose both and deserve neither" - T.Jefferson