mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-25 06:25:04 +00:00
Another approach to disabling SHM.
This commit is contained in:
parent
cdfaf6dc57
commit
ed973241f4
1 changed files with 23 additions and 23 deletions
46
httpd.c
46
httpd.c
|
@ -653,29 +653,6 @@ void term_handler(int s)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef WITHOUT_SHM
|
|
||||||
|
|
||||||
/* dummy versions */
|
|
||||||
|
|
||||||
int shm_open(const char *name, int flags, mode_t mode)
|
|
||||||
{
|
|
||||||
(void)name;
|
|
||||||
(void)flags;
|
|
||||||
(void)mode;
|
|
||||||
|
|
||||||
errno = ENOTSUP;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
int shm_unlink(const char *name)
|
|
||||||
{
|
|
||||||
(void)name;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
srv_state *srv_state_op(xs_str **fname, int op)
|
srv_state *srv_state_op(xs_str **fname, int op)
|
||||||
/* opens or deletes the shared memory object */
|
/* opens or deletes the shared memory object */
|
||||||
{
|
{
|
||||||
|
@ -687,6 +664,13 @@ srv_state *srv_state_op(xs_str **fname, int op)
|
||||||
|
|
||||||
switch (op) {
|
switch (op) {
|
||||||
case 0: /* open for writing */
|
case 0: /* open for writing */
|
||||||
|
|
||||||
|
#ifdef WITHOUT_SHM
|
||||||
|
|
||||||
|
errno = ENOTSUP;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
if ((fd = shm_open(*fname, O_CREAT | O_RDWR, 0666)) != -1) {
|
if ((fd = shm_open(*fname, O_CREAT | O_RDWR, 0666)) != -1) {
|
||||||
ftruncate(fd, sizeof(*ss));
|
ftruncate(fd, sizeof(*ss));
|
||||||
|
|
||||||
|
@ -697,6 +681,8 @@ srv_state *srv_state_op(xs_str **fname, int op)
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
if (ss == NULL) {
|
if (ss == NULL) {
|
||||||
/* shared memory error: just create a plain structure */
|
/* shared memory error: just create a plain structure */
|
||||||
srv_log(xs_fmt("warning: shm object error (%s)", strerror(errno)));
|
srv_log(xs_fmt("warning: shm object error (%s)", strerror(errno)));
|
||||||
|
@ -710,6 +696,13 @@ srv_state *srv_state_op(xs_str **fname, int op)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1: /* open for reading */
|
case 1: /* open for reading */
|
||||||
|
|
||||||
|
#ifdef WITHOUT_SHM
|
||||||
|
|
||||||
|
errno = ENOTSUP;
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
if ((fd = shm_open(*fname, O_RDONLY, 0666)) != -1) {
|
if ((fd = shm_open(*fname, O_RDONLY, 0666)) != -1) {
|
||||||
if ((ss = mmap(0, sizeof(*ss), PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED)
|
if ((ss = mmap(0, sizeof(*ss), PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED)
|
||||||
ss = NULL;
|
ss = NULL;
|
||||||
|
@ -717,6 +710,8 @@ srv_state *srv_state_op(xs_str **fname, int op)
|
||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
if (ss == NULL) {
|
if (ss == NULL) {
|
||||||
/* shared memory error */
|
/* shared memory error */
|
||||||
srv_log(xs_fmt("error: shm object error (%s) server not running?", strerror(errno)));
|
srv_log(xs_fmt("error: shm object error (%s) server not running?", strerror(errno)));
|
||||||
|
@ -734,9 +729,14 @@ srv_state *srv_state_op(xs_str **fname, int op)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2: /* unlink */
|
case 2: /* unlink */
|
||||||
|
|
||||||
|
#ifndef WITHOUT_SHM
|
||||||
|
|
||||||
if (*fname)
|
if (*fname)
|
||||||
shm_unlink(*fname);
|
shm_unlink(*fname);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue