View | Details | Raw Unified | Return to bug 16056
Collapse All | Expand All

(-)apr/include/apr_shm.h (-1 / +18 lines)
Lines 25-30 Link Here
25
#include "apr.h"
25
#include "apr.h"
26
#include "apr_pools.h"
26
#include "apr_pools.h"
27
#include "apr_errno.h"
27
#include "apr_errno.h"
28
#include "apr_file_info.h"
28
29
29
#ifdef __cplusplus
30
#ifdef __cplusplus
30
extern "C" {
31
extern "C" {
Lines 43-49 extern "C" { Link Here
43
typedef struct apr_shm_t apr_shm_t;
44
typedef struct apr_shm_t apr_shm_t;
44
45
45
/**
46
/**
46
 * Create and make accessable a shared memory segment.
47
 * Create and make accessible a shared memory segment.
47
 * @param m The shared memory structure to create.
48
 * @param m The shared memory structure to create.
48
 * @param reqsize The desired size of the segment.
49
 * @param reqsize The desired size of the segment.
49
 * @param filename The file to use for shared memory on platforms that
50
 * @param filename The file to use for shared memory on platforms that
Lines 71-76 APR_DECLARE(apr_status_t) apr_shm_create Link Here
71
                                         apr_pool_t *pool);
72
                                         apr_pool_t *pool);
72
73
73
/**
74
/**
75
 * Create with given permission a shared memory segment.
76
 * @param m The shared memory structure to create.
77
 * @param reqsize The desired size of the segment.
78
 * @param filename The file to use for shared memory on platforms that
79
 *        require it.
80
 * @param perm Access permissions for file.
81
 * @param pool the pool from which to allocate the shared memory structure/
82
 * @remark Remarks of apr_shm_create() applies here as well.
83
 */
84
APR_DECLARE(apr_status_t) apr_shm_create_ex(apr_shm_t **m,
85
                                            apr_size_t reqsize,
86
                                            const char *filename,
87
                                            apr_fileperms_t perm,
88
                                            apr_pool_t *pool);
89
90
/**
74
 * Remove shared memory segment associated with a filename.
91
 * Remove shared memory segment associated with a filename.
75
 * @param filename The filename associated with shared-memory segment which
92
 * @param filename The filename associated with shared-memory segment which
76
 *        needs to be removed
93
 *        needs to be removed
(-)apr/shmem/unix/shm.c (-10 / +19 lines)
Lines 15-20 Link Here
15
 */
15
 */
16
16
17
#include "apr_arch_shm.h"
17
#include "apr_arch_shm.h"
18
#include "apr_arch_file_io.h"
18
19
19
#include "apr_general.h"
20
#include "apr_general.h"
20
#include "apr_errno.h"
21
#include "apr_errno.h"
Lines 78-89 static apr_status_t shm_cleanup_owner(vo Link Here
78
}
79
}
79
80
80
APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
81
APR_DECLARE(apr_status_t) apr_shm_create(apr_shm_t **m,
81
                                         apr_size_t reqsize, 
82
                                         apr_size_t reqsize,
82
                                         const char *filename,
83
                                         const char *filename,
83
                                         apr_pool_t *pool)
84
                                         apr_pool_t *pool)
84
{
85
{
86
    return apr_shm_create_ex(m, reqsize, filename, APR_FPROT_OS_DEFAULT, pool);
87
}
88
89
APR_DECLARE(apr_status_t) apr_shm_create_ex(apr_shm_t **m,
90
                                            apr_size_t reqsize,
91
                                            const char *filename,
92
                                            apr_fileperms_t perm,
93
                                            apr_pool_t *pool)
94
{
85
    apr_shm_t *new_m;
95
    apr_shm_t *new_m;
86
    apr_status_t status;
96
    apr_status_t status;
97
    mode_t mode = apr_unix_perms2mode(perm);
87
#if APR_USE_SHMEM_SHMGET || APR_USE_SHMEM_SHMGET_ANON
98
#if APR_USE_SHMEM_SHMGET || APR_USE_SHMEM_SHMGET_ANON
88
    struct shmid_ds shmbuf;
99
    struct shmid_ds shmbuf;
89
    apr_uid_t uid;
100
    apr_uid_t uid;
Lines 187-192 APR_DECLARE(apr_status_t) apr_shm_create Link Here
187
        apr_uid_current(&uid, &gid, pool);
198
        apr_uid_current(&uid, &gid, pool);
188
        shmbuf.shm_perm.uid = uid;
199
        shmbuf.shm_perm.uid = uid;
189
        shmbuf.shm_perm.gid = gid;
200
        shmbuf.shm_perm.gid = gid;
201
        shmbuf.shm_perm.mode = mode;
190
        if (shmctl(new_m->shmid, IPC_SET, &shmbuf) == -1) {
202
        if (shmctl(new_m->shmid, IPC_SET, &shmbuf) == -1) {
191
            return errno;
203
            return errno;
192
        }
204
        }
Lines 223-232 APR_DECLARE(apr_status_t) apr_shm_create Link Here
223
        status = APR_SUCCESS;
235
        status = APR_SUCCESS;
224
    
236
    
225
#if APR_USE_SHMEM_MMAP_TMP
237
#if APR_USE_SHMEM_MMAP_TMP
226
        /* FIXME: Is APR_OS_DEFAULT sufficient? */
238
        status = apr_file_open(&file, filename, APR_READ | APR_WRITE |
227
        status = apr_file_open(&file, filename, 
239
                               APR_CREATE | APR_EXCL, perm, pool);
228
                               APR_READ | APR_WRITE | APR_CREATE | APR_EXCL,
229
                               APR_OS_DEFAULT, pool);
230
        if (status != APR_SUCCESS) {
240
        if (status != APR_SUCCESS) {
231
            return status;
241
            return status;
232
        }
242
        }
Lines 255-261 APR_DECLARE(apr_status_t) apr_shm_create Link Here
255
        }
265
        }
256
#endif /* APR_USE_SHMEM_MMAP_TMP */
266
#endif /* APR_USE_SHMEM_MMAP_TMP */
257
#if APR_USE_SHMEM_MMAP_SHM
267
#if APR_USE_SHMEM_MMAP_SHM
258
        tmpfd = shm_open(filename, O_RDWR | O_CREAT | O_EXCL, 0644);
268
        tmpfd = shm_open(filename, O_RDWR | O_CREAT | O_EXCL, mode);
259
        if (tmpfd == -1) {
269
        if (tmpfd == -1) {
260
            return errno;
270
            return errno;
261
        }
271
        }
Lines 298-307 APR_DECLARE(apr_status_t) apr_shm_create Link Here
298
#if APR_USE_SHMEM_SHMGET
308
#if APR_USE_SHMEM_SHMGET
299
        new_m->realsize = reqsize;
309
        new_m->realsize = reqsize;
300
310
301
        /* FIXME: APR_OS_DEFAULT is too permissive, switch to 600 I think. */
311
        status = apr_file_open(&file, filename, APR_WRITE | APR_CREATE |
302
        status = apr_file_open(&file, filename, 
312
                               APR_EXCL, perm, pool);
303
                               APR_WRITE | APR_CREATE | APR_EXCL,
304
                               APR_OS_DEFAULT, pool);
305
        if (status != APR_SUCCESS) {
313
        if (status != APR_SUCCESS) {
306
            return status;
314
            return status;
307
        }
315
        }
Lines 329-334 APR_DECLARE(apr_status_t) apr_shm_create Link Here
329
        apr_uid_current(&uid, &gid, pool);
337
        apr_uid_current(&uid, &gid, pool);
330
        shmbuf.shm_perm.uid = uid;
338
        shmbuf.shm_perm.uid = uid;
331
        shmbuf.shm_perm.gid = gid;
339
        shmbuf.shm_perm.gid = gid;
340
        shmbuf.shm_perm.mode = mode;
332
        if (shmctl(new_m->shmid, IPC_SET, &shmbuf) == -1) {
341
        if (shmctl(new_m->shmid, IPC_SET, &shmbuf) == -1) {
333
            return errno;
342
            return errno;
334
        }
343
        }

Return to bug 16056