~ubuntu-branches/ubuntu/raring/apache-upload-progress-module/raring

« back to all changes in this revision

Viewing changes to apr_shm_remove.h

  • Committer: Bazaar Package Importer
  • Author(s): Jérémy Bobbio
  • Date: 2011-07-19 18:41:47 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20110719184147-egvw5mnhj66dydx0
Tags: 0.1+git20110718-1
* New upstream snapshot.
* Do not mention Nginx and lighttpd in extended description.
  (Closes: #610805)
* Fix spelling error in extended description spotted by lintian.
* Bump Standards-Version to 3.9.2, no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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.
4
 
 *
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
8
 
 */
9
 
/* BEGIN OF PATCH ---------------------------------------------------------- */
10
 
/* apr version 0.x not support apr_shm_remove, I have to copy it from apr version 1.x */
11
 
 
12
 
#if APR_HAS_SHARED_MEMORY
13
 
 
14
 
        #ifdef HAVE_SYS_MMAN_H
15
 
                #include <sys/mman.h>
16
 
        #endif
17
 
        #ifdef HAVE_SYS_IPC_H
18
 
                #include <sys/ipc.h>
19
 
        #endif
20
 
        #ifdef HAVE_SYS_MUTEX_H
21
 
                #include <sys/mutex.h>
22
 
        #endif
23
 
        #ifdef HAVE_SYS_SHM_H
24
 
                #include <sys/shm.h>
25
 
        #endif
26
 
        #if !defined(SHM_R)
27
 
                #define SHM_R 0400
28
 
        #endif
29
 
        #if !defined(SHM_W)
30
 
                #define SHM_W 0200
31
 
        #endif
32
 
        #ifdef HAVE_SYS_FILE_H
33
 
                #include <sys/file.h>
34
 
        #endif
35
 
 
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.
40
 
 *
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.
43
 
 */
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)
46
 
{
47
 
#if APR_USE_SHMEM_SHMGET
48
 
    apr_status_t status;
49
 
    apr_file_t *file;
50
 
    key_t shmkey;
51
 
    int shmid;
52
 
#endif
53
 
 
54
 
#if APR_USE_SHMEM_MMAP_TMP
55
 
    return apr_file_remove(filename, pool);
56
 
#endif
57
 
 
58
 
#if APR_USE_SHMEM_MMAP_SHM
59
 
    if (shm_unlink(filename) == -1) {
60
 
        return errno;
61
 
    }
62
 
    return APR_SUCCESS;
63
 
#endif
64
 
 
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);
68
 
    if (status) {
69
 
        return status;
70
 
    }
71
 
 
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;
77
 
    }
78
 
 
79
 
    apr_file_close(file);
80
 
    if ((shmid = shmget(shmkey, 0, SHM_R | SHM_W)) < 0) {
81
 
        goto shm_remove_failed;
82
 
    }
83
 
 
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;
89
 
    }
90
 
    return apr_file_remove(filename, pool);
91
 
 
92
 
shm_remove_failed:
93
 
    status = errno;
94
 
    /* ensure the file has been removed anyway. */
95
 
    apr_file_remove(filename, pool);
96
 
    return status;
97
 
#endif
98
 
 
99
 
    /* No support for anonymous shm */
100
 
    return APR_ENOTIMPL;
101
 
}
102
 
/* END OF PATCH ------------------------------------------------------------ */
103
 
 
104
 
#endif