Author: mladen.turk(a)jboss.com
Date: 2008-06-19 04:58:46 -0400 (Thu, 19 Jun 2008)
New Revision: 1723
Modified:
trunk/mod_cluster/native/mod_slotmem/sharedmem_util.c
Log:
Add sharedmem unixd util
Modified: trunk/mod_cluster/native/mod_slotmem/sharedmem_util.c
===================================================================
--- trunk/mod_cluster/native/mod_slotmem/sharedmem_util.c 2008-06-18 16:00:03 UTC (rev
1722)
+++ trunk/mod_cluster/native/mod_slotmem/sharedmem_util.c 2008-06-19 08:58:46 UTC (rev
1723)
@@ -37,6 +37,25 @@
#include "slotmem.h"
+#include "httpd.h"
+#ifdef AP_NEED_SET_MUTEX_PERMS
+#include "unixd.h"
+#endif
+
+#if APR_HAVE_UNISTD_H
+#include <unistd.h> /* for getpid() */
+#endif
+
+#if HAVE_SYS_SEM_H
+#include <sys/shm.h>
+#if !defined(SHM_R)
+#define SHM_R 0400
+#endif
+#if !defined(SHM_W)
+#define SHM_W 0200
+#endif
+#endif
+
/* The description of the slots to reuse the slotmem */
struct sharedslotdesc {
apr_size_t item_size;
@@ -59,6 +78,36 @@
static struct ap_slotmem *globallistmem = NULL;
static apr_pool_t *globalpool = NULL;
+apr_status_t unixd_set_shm_perms(const char *fname)
+{
+#ifdef AP_NEED_SET_MUTEX_PERMS
+#if APR_USE_SHMEM_SHMGET || APR_USE_SHMEM_SHMGET_ANON
+ struct shmid_ds shmbuf;
+ key_t shmkey;
+ int shmid;
+
+ shmkey = ftok(fname, 1);
+ if (shmkey == (key_t)-1) {
+ return errno;
+ }
+ if ((shmid = shmget(shmkey, 0, SHM_R | SHM_W)) == -1) {
+ return errno;
+ }
+ shmbuf.shm_perm.uid = unixd_config.user_id;
+ shmbuf.shm_perm.gid = unixd_config.group_id;
+ shmbuf.shm_perm.mode = 0600;
+ if (shmctl(shmid, IPC_SET, &shmbuf) == -1) {
+ return errno;
+ }
+ return APR_SUCCESS;
+#else
+ return APR_ENOTIMPL;
+#endif
+#else
+ return APR_ENOTIMPL;
+#endif
+}
+
/*
* Persiste the slotmem in a file
* slotmem name and file name.
@@ -237,7 +286,13 @@
if (rv != APR_SUCCESS) {
return rv;
}
-
+ if (name) {
+ /* Set permissions to shared memory
+ * so it can be attached by child process
+ * having different user credentials
+ */
+ unixd_set_shm_perms(fname);
+ }
ptr = apr_shm_baseaddr_get(res->shm);
desc.item_size = item_size;
desc.item_num = item_num;
Show replies by date