From ed973241f44f8dd1b688bbab37018f33160027bf Mon Sep 17 00:00:00 2001 From: default Date: Tue, 21 May 2024 19:08:33 +0200 Subject: [PATCH] Another approach to disabling SHM. --- httpd.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/httpd.c b/httpd.c index 993aa1c..8a20c89 100644 --- a/httpd.c +++ b/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) /* opens or deletes the shared memory object */ { @@ -687,6 +664,13 @@ srv_state *srv_state_op(xs_str **fname, int op) switch (op) { case 0: /* open for writing */ + +#ifdef WITHOUT_SHM + + errno = ENOTSUP; + +#else + if ((fd = shm_open(*fname, O_CREAT | O_RDWR, 0666)) != -1) { ftruncate(fd, sizeof(*ss)); @@ -697,6 +681,8 @@ srv_state *srv_state_op(xs_str **fname, int op) close(fd); } +#endif + if (ss == NULL) { /* shared memory error: just create a plain structure */ 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; case 1: /* open for reading */ + +#ifdef WITHOUT_SHM + + errno = ENOTSUP; + +#else + if ((fd = shm_open(*fname, O_RDONLY, 0666)) != -1) { if ((ss = mmap(0, sizeof(*ss), PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) ss = NULL; @@ -717,6 +710,8 @@ srv_state *srv_state_op(xs_str **fname, int op) close(fd); } +#endif + if (ss == NULL) { /* shared memory error */ 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; case 2: /* unlink */ + +#ifndef WITHOUT_SHM + if (*fname) shm_unlink(*fname); +#endif + break; }