Mercurial > hg > nginx
comparison src/os/unix/ngx_shmem.c @ 605:5dac8c7fb71b release-0.3.24
nginx-0.3.24-RELEASE import
*) Workaround: for bug in FreeBSD kqueue.
*) Bugfix: now a response generated by the "post_action" directive is
not transferred to a client.
*) Bugfix: the memory leaks were occurring if many log files were used.
*) Bugfix: the first "proxy_redirect" directive was working inside one
location.
*) Bugfix: on 64-bit platforms segmentation fault may occurred on start
if the many names were used in the "server_name" directives; the bug
had appeared in 0.3.18.
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Wed, 01 Feb 2006 18:22:15 +0000 |
parents | src/os/unix/ngx_shared.c@2ff194b74f1e |
children | 715d24327080 |
comparison
equal
deleted
inserted
replaced
604:f4a6e8f250a8 | 605:5dac8c7fb71b |
---|---|
1 | |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 | |
10 | |
11 #if (NGX_HAVE_MAP_ANON) | |
12 | |
13 ngx_int_t | |
14 ngx_shm_alloc(ngx_shm_t *shm) | |
15 { | |
16 shm->addr = mmap(NULL, shm->size, | |
17 PROT_READ|PROT_WRITE, MAP_ANON|MAP_SHARED, -1, 0); | |
18 | |
19 if (shm->addr == MAP_FAILED) { | |
20 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, | |
21 "mmap(MAP_ANON|MAP_SHARED, %uz) failed", shm->size); | |
22 return NGX_ERROR; | |
23 } | |
24 | |
25 return NGX_OK; | |
26 } | |
27 | |
28 | |
29 void | |
30 ngx_shm_free(ngx_shm_t *shm) | |
31 { | |
32 if (munmap(shm->addr, shm->size) == -1) { | |
33 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, | |
34 "munmap(%p, %uz) failed", shm->addr, shm->size); | |
35 } | |
36 } | |
37 | |
38 #elif (NGX_HAVE_MAP_DEVZERO) | |
39 | |
40 ngx_int_t | |
41 ngx_shm_alloc(ngx_shm_t *shm) | |
42 { | |
43 ngx_fd_t fd; | |
44 | |
45 fd = open("/dev/zero", O_RDWR); | |
46 | |
47 if (fd == -1) { | |
48 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, | |
49 "open(\"/dev/zero\") failed"); | |
50 return NGX_ERROR; | |
51 } | |
52 | |
53 shm->addr = mmap(NULL, shm->size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); | |
54 | |
55 if (shm->addr == MAP_FAILED) { | |
56 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, | |
57 "mmap(/dev/zero, MAP_SHARED, %uz) failed", shm->size); | |
58 } | |
59 | |
60 if (close(fd) == -1) { | |
61 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, | |
62 "close(\"/dev/zero\") failed"); | |
63 } | |
64 | |
65 return (shm->addr == MAP_FAILED) ? NGX_ERROR : NGX_OK; | |
66 } | |
67 | |
68 | |
69 void | |
70 ngx_shm_free(ngx_shm_t *shm) | |
71 { | |
72 if (munmap(shm->addr, shm->size) == -1) { | |
73 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, | |
74 "munmap(%p, %uz) failed", shm->addr, shm->size); | |
75 } | |
76 } | |
77 | |
78 #elif (NGX_HAVE_SYSVSHM) | |
79 | |
80 #include <sys/ipc.h> | |
81 #include <sys/shm.h> | |
82 | |
83 | |
84 ngx_int_t | |
85 ngx_shm_alloc(ngx_shm_t *shm) | |
86 { | |
87 int id; | |
88 | |
89 id = shmget(IPC_PRIVATE, shm->size, (SHM_R|SHM_W|IPC_CREAT)); | |
90 | |
91 if (id == -1) { | |
92 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, | |
93 "shmget(%uz) failed", shm->size); | |
94 return NGX_ERROR; | |
95 } | |
96 | |
97 ngx_log_debug1(NGX_LOG_DEBUG_CORE, shm->log, 0, "shmget id: %d", id); | |
98 | |
99 shm->addr = shmat(id, NULL, 0); | |
100 | |
101 if (shm->addr == (void *) -1) { | |
102 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, "shmat() failed"); | |
103 } | |
104 | |
105 if (shmctl(id, IPC_RMID, NULL) == -1) { | |
106 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, | |
107 "shmctl(IPC_RMID) failed"); | |
108 } | |
109 | |
110 return (shm->addr == (void *) -1) ? NGX_ERROR : NGX_OK; | |
111 } | |
112 | |
113 | |
114 void | |
115 ngx_shm_free(ngx_shm_t *shm) | |
116 { | |
117 if (shmdt(shm->addr) == -1) { | |
118 ngx_log_error(NGX_LOG_ALERT, shm->log, ngx_errno, | |
119 "shmdt(%p) failed", shm->addr); | |
120 } | |
121 } | |
122 | |
123 #endif |