diff options
| author | 2024-05-21 19:08:33 +0200 | |
|---|---|---|
| committer | 2024-05-21 19:08:33 +0200 | |
| commit | ed973241f44f8dd1b688bbab37018f33160027bf (patch) | |
| tree | b0dd4d007b7c28ed6c26bcd234e7142fad68f850 /httpd.c | |
| parent | New compilation variable WITHOUT_SHM, to disable shared memory functions. (diff) | |
| download | snac2-ed973241f44f8dd1b688bbab37018f33160027bf.tar.gz snac2-ed973241f44f8dd1b688bbab37018f33160027bf.tar.xz snac2-ed973241f44f8dd1b688bbab37018f33160027bf.zip | |
Another approach to disabling SHM.
Diffstat (limited to 'httpd.c')
| -rw-r--r-- | httpd.c | 46 |
1 files changed, 23 insertions, 23 deletions
| @@ -653,29 +653,6 @@ void term_handler(int s) | |||
| 653 | } | 653 | } |
| 654 | 654 | ||
| 655 | 655 | ||
| 656 | #ifdef WITHOUT_SHM | ||
| 657 | |||
| 658 | /* dummy versions */ | ||
| 659 | |||
| 660 | int shm_open(const char *name, int flags, mode_t mode) | ||
| 661 | { | ||
| 662 | (void)name; | ||
| 663 | (void)flags; | ||
| 664 | (void)mode; | ||
| 665 | |||
| 666 | errno = ENOTSUP; | ||
| 667 | return -1; | ||
| 668 | } | ||
| 669 | |||
| 670 | int shm_unlink(const char *name) | ||
| 671 | { | ||
| 672 | (void)name; | ||
| 673 | return -1; | ||
| 674 | } | ||
| 675 | |||
| 676 | |||
| 677 | #endif | ||
| 678 | |||
| 679 | srv_state *srv_state_op(xs_str **fname, int op) | 656 | srv_state *srv_state_op(xs_str **fname, int op) |
| 680 | /* opens or deletes the shared memory object */ | 657 | /* opens or deletes the shared memory object */ |
| 681 | { | 658 | { |
| @@ -687,6 +664,13 @@ srv_state *srv_state_op(xs_str **fname, int op) | |||
| 687 | 664 | ||
| 688 | switch (op) { | 665 | switch (op) { |
| 689 | case 0: /* open for writing */ | 666 | case 0: /* open for writing */ |
| 667 | |||
| 668 | #ifdef WITHOUT_SHM | ||
| 669 | |||
| 670 | errno = ENOTSUP; | ||
| 671 | |||
| 672 | #else | ||
| 673 | |||
| 690 | if ((fd = shm_open(*fname, O_CREAT | O_RDWR, 0666)) != -1) { | 674 | if ((fd = shm_open(*fname, O_CREAT | O_RDWR, 0666)) != -1) { |
| 691 | ftruncate(fd, sizeof(*ss)); | 675 | ftruncate(fd, sizeof(*ss)); |
| 692 | 676 | ||
| @@ -697,6 +681,8 @@ srv_state *srv_state_op(xs_str **fname, int op) | |||
| 697 | close(fd); | 681 | close(fd); |
| 698 | } | 682 | } |
| 699 | 683 | ||
| 684 | #endif | ||
| 685 | |||
| 700 | if (ss == NULL) { | 686 | if (ss == NULL) { |
| 701 | /* shared memory error: just create a plain structure */ | 687 | /* shared memory error: just create a plain structure */ |
| 702 | srv_log(xs_fmt("warning: shm object error (%s)", strerror(errno))); | 688 | 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) | |||
| 710 | break; | 696 | break; |
| 711 | 697 | ||
| 712 | case 1: /* open for reading */ | 698 | case 1: /* open for reading */ |
| 699 | |||
| 700 | #ifdef WITHOUT_SHM | ||
| 701 | |||
| 702 | errno = ENOTSUP; | ||
| 703 | |||
| 704 | #else | ||
| 705 | |||
| 713 | if ((fd = shm_open(*fname, O_RDONLY, 0666)) != -1) { | 706 | if ((fd = shm_open(*fname, O_RDONLY, 0666)) != -1) { |
| 714 | if ((ss = mmap(0, sizeof(*ss), PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) | 707 | if ((ss = mmap(0, sizeof(*ss), PROT_READ, MAP_SHARED, fd, 0)) == MAP_FAILED) |
| 715 | ss = NULL; | 708 | ss = NULL; |
| @@ -717,6 +710,8 @@ srv_state *srv_state_op(xs_str **fname, int op) | |||
| 717 | close(fd); | 710 | close(fd); |
| 718 | } | 711 | } |
| 719 | 712 | ||
| 713 | #endif | ||
| 714 | |||
| 720 | if (ss == NULL) { | 715 | if (ss == NULL) { |
| 721 | /* shared memory error */ | 716 | /* shared memory error */ |
| 722 | srv_log(xs_fmt("error: shm object error (%s) server not running?", strerror(errno))); | 717 | 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) | |||
| 734 | break; | 729 | break; |
| 735 | 730 | ||
| 736 | case 2: /* unlink */ | 731 | case 2: /* unlink */ |
| 732 | |||
| 733 | #ifndef WITHOUT_SHM | ||
| 734 | |||
| 737 | if (*fname) | 735 | if (*fname) |
| 738 | shm_unlink(*fname); | 736 | shm_unlink(*fname); |
| 739 | 737 | ||
| 738 | #endif | ||
| 739 | |||
| 740 | break; | 740 | break; |
| 741 | } | 741 | } |
| 742 | 742 | ||