2
* The following is a patch ported from mod_fcgid for Apache 2.0 releases
3
* which don't provide a version of apr_shm_remove.
5
* Please have a look at the mod_fcgid mailing list for details.
6
* The original patch can be found at:
7
* http://lists.freebsd.org/pipermail/freebsd-ports-bugs/2007-June/122731.html
9
/* BEGIN OF PATCH ---------------------------------------------------------- */
10
/* apr version 0.x not support apr_shm_remove, I have to copy it from apr version 1.x */
12
#if APR_HAS_SHARED_MEMORY
14
#ifdef HAVE_SYS_MMAN_H
20
#ifdef HAVE_SYS_MUTEX_H
21
#include <sys/mutex.h>
32
#ifdef HAVE_SYS_FILE_H
36
/* To avoid conflicts with mod_fcgid and that instance of the patch there.
37
* This basically replaces each of our instances of apr_shm_remove with a local
38
* identifier only used by us thus avoiding hard-to-find bugs if the wrong
39
* version of this function gets linked in when loading the module.
41
* If re-using this patch you are therefore encouraged to change the name of
42
* the resulting function in the makro and the function declaration below.
44
#define apr_shm_remove modup_backport_apr_shm_remove
45
static apr_status_t modup_backport_apr_shm_remove(const char *filename, apr_pool_t * pool)
47
#if APR_USE_SHMEM_SHMGET
54
#if APR_USE_SHMEM_MMAP_TMP
55
return apr_file_remove(filename, pool);
58
#if APR_USE_SHMEM_MMAP_SHM
59
if (shm_unlink(filename) == -1) {
65
#if APR_USE_SHMEM_SHMGET
66
/* Presume that the file already exists; just open for writing */
67
status = apr_file_open(&file, filename, APR_WRITE, APR_OS_DEFAULT, pool);
72
/* ftok() (on solaris at least) requires that the file actually
73
* exist before calling ftok(). */
74
shmkey = ftok(filename, 1);
75
if (shmkey == (key_t) - 1) {
76
goto shm_remove_failed;
80
if ((shmid = shmget(shmkey, 0, SHM_R | SHM_W)) < 0) {
81
goto shm_remove_failed;
84
/* Indicate that the segment is to be destroyed as soon
85
* as all processes have detached. This also disallows any
86
* new attachments to the segment. */
87
if (shmctl(shmid, IPC_RMID, NULL) == -1) {
88
goto shm_remove_failed;
90
return apr_file_remove(filename, pool);
94
/* ensure the file has been removed anyway. */
95
apr_file_remove(filename, pool);
99
/* No support for anonymous shm */
102
/* END OF PATCH ------------------------------------------------------------ */