diff options
author | Jim Jagielski <jim@apache.org> | 2013-10-17 15:10:11 +0000 |
---|---|---|
committer | Jim Jagielski <jim@apache.org> | 2013-10-17 15:10:11 +0000 |
commit | 83f1d0dd4db126de59e7c23dcfaacfe247743b4a (patch) | |
tree | a1e334e9d4bc5b999a88b3f65784de0e19fdfcad /shmem | |
parent | fd2c51a0674a0a50a526e98ed651e0c477e9c86c (diff) | |
download | apr-83f1d0dd4db126de59e7c23dcfaacfe247743b4a.tar.gz |
Merge r1533104 from trunk:
it should really handle src==NULL
Reviewed/backported by: jim
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1533105 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'shmem')
-rw-r--r-- | shmem/beos/shm.c | 2 | ||||
-rw-r--r-- | shmem/os2/shm.c | 2 | ||||
-rw-r--r-- | shmem/unix/shm.c | 41 | ||||
-rw-r--r-- | shmem/win32/shm.c | 2 |
4 files changed, 37 insertions, 10 deletions
diff --git a/shmem/beos/shm.c b/shmem/beos/shm.c index 1f06f78ac..d6b888b08 100644 --- a/shmem/beos/shm.c +++ b/shmem/beos/shm.c @@ -149,6 +149,8 @@ APR_DECLARE(apr_size_t) apr_shm_size_get(const apr_shm_t *m) return m->reqsize; } +APR_PERMS_SET_ENOTIMPL(shm) + APR_POOL_IMPLEMENT_ACCESSOR(shm) APR_DECLARE(apr_status_t) apr_os_shm_get(apr_os_shm_t *osshm, diff --git a/shmem/os2/shm.c b/shmem/os2/shm.c index 340cae407..dcdb41587 100644 --- a/shmem/os2/shm.c +++ b/shmem/os2/shm.c @@ -113,6 +113,8 @@ APR_DECLARE(apr_size_t) apr_shm_size_get(const apr_shm_t *m) return size; } +APR_PERMS_SET_ENOTIMPL(shm) + APR_POOL_IMPLEMENT_ACCESSOR(shm) APR_DECLARE(apr_status_t) apr_os_shm_get(apr_os_shm_t *osshm, diff --git a/shmem/unix/shm.c b/shmem/unix/shm.c index 73a729df9..f1259e232 100644 --- a/shmem/unix/shm.c +++ b/shmem/unix/shm.c @@ -15,6 +15,7 @@ */ #include "apr_arch_shm.h" +#include "apr_arch_file_io.h" #include "apr_general.h" #include "apr_errno.h" @@ -102,7 +103,6 @@ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m, #endif #if APR_USE_SHMEM_SHMGET apr_size_t nbytes; - key_t shmkey; #endif #if APR_USE_SHMEM_MMAP_ZERO || APR_USE_SHMEM_SHMGET || \ APR_USE_SHMEM_MMAP_TMP || APR_USE_SHMEM_MMAP_SHM @@ -175,8 +175,8 @@ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m, new_m->reqsize = reqsize; new_m->realsize = reqsize; new_m->filename = NULL; - - if ((new_m->shmid = shmget(IPC_PRIVATE, new_m->realsize, + new_m->shmkey = IPC_PRIVATE; + if ((new_m->shmid = shmget(new_m->shmkey, new_m->realsize, SHM_R | SHM_W | IPC_CREAT)) < 0) { return errno; } @@ -312,13 +312,13 @@ APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m, /* ftok() (on solaris at least) requires that the file actually * exist before calling ftok(). */ - shmkey = ftok(filename, 1); - if (shmkey == (key_t)-1) { + new_m->shmkey = ftok(filename, 1); + if (new_m->shmkey == (key_t)-1) { apr_file_close(file); return errno; } - if ((new_m->shmid = shmget(shmkey, new_m->realsize, + if ((new_m->shmid = shmget(new_m->shmkey, new_m->realsize, SHM_R | SHM_W | IPC_CREAT | IPC_EXCL)) < 0) { apr_file_close(file); return errno; @@ -523,7 +523,6 @@ APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m, apr_status_t status; apr_file_t *file; /* file where metadata is stored */ apr_size_t nbytes; - key_t shmkey; new_m = apr_palloc(pool, sizeof(apr_shm_t)); @@ -546,11 +545,11 @@ APR_DECLARE(apr_status_t) apr_shm_attach(apr_shm_t **m, new_m->filename = apr_pstrdup(pool, filename); new_m->pool = pool; - shmkey = ftok(filename, 1); - if (shmkey == (key_t)-1) { + new_m->shmkey = ftok(filename, 1); + if (new_m->shmkey == (key_t)-1) { return errno; } - if ((new_m->shmid = shmget(shmkey, 0, SHM_R | SHM_W)) == -1) { + if ((new_m->shmid = shmget(new_m->shmkey, 0, SHM_R | SHM_W)) == -1) { return errno; } if ((new_m->base = shmat(new_m->shmid, NULL, 0)) == (void *)-1) { @@ -587,6 +586,28 @@ APR_DECLARE(apr_size_t) apr_shm_size_get(const apr_shm_t *m) return m->reqsize; } +APR_PERMS_SET_IMPLEMENT(shm) +{ +#if APR_USE_SHMEM_SHMGET || APR_USE_SHMEM_SHMGET_ANON + struct shmid_ds shmbuf; + int shmid; + apr_shm_t *m = (apr_shm_t *)theshm; + + if ((shmid = shmget(m->shmkey, 0, SHM_R | SHM_W)) == -1) { + return errno; + } + shmbuf.shm_perm.uid = uid; + shmbuf.shm_perm.gid = gid; + shmbuf.shm_perm.mode = apr_unix_perms2mode(perms); + if (shmctl(shmid, IPC_SET, &shmbuf) == -1) { + return errno; + } + return APR_SUCCESS; +#else + return APR_ENOTIMPL; +#endif +} + APR_POOL_IMPLEMENT_ACCESSOR(shm) APR_DECLARE(apr_status_t) apr_os_shm_get(apr_os_shm_t *osshm, diff --git a/shmem/win32/shm.c b/shmem/win32/shm.c index 85926ab7e..117e4c81f 100644 --- a/shmem/win32/shm.c +++ b/shmem/win32/shm.c @@ -281,6 +281,8 @@ APR_DECLARE(apr_size_t) apr_shm_size_get(const apr_shm_t *m) return m->length; } +APR_PERMS_SET_ENOTIMPL(shm) + APR_POOL_IMPLEMENT_ACCESSOR(shm) APR_DECLARE(apr_status_t) apr_os_shm_get(apr_os_shm_t *osshm, |