diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-10-10 23:16:11 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-10-10 23:16:11 +0200 |
| commit | 832e198f8c77970b5b923eb18201ba83d9c72b80 (patch) | |
| tree | 26039e1c731f1ca73c5b17b1447bb42d23263a20 /server.c | |
| parent | 07e0063870725506447a0ad29a6b92bb8c8c4e0b (diff) | |
server.c: Replace sequential calls with loop
Diffstat (limited to 'server.c')
| -rw-r--r-- | server.c | 32 |
1 files changed, 18 insertions, 14 deletions
@@ -294,23 +294,27 @@ static int init_signals(void) sigemptyset(&sa.sa_mask); - if (sigaction(SIGINT, &sa, NULL)) + static const struct signal { - fprintf(stderr, "%s: sigaction(2) SIGINT: %s\n", - __func__, strerror(errno)); - return -1; - } - else if (sigaction(SIGTERM, &sa, NULL)) + int signal; + const char *name; + } signals[] = { - fprintf(stderr, "%s: sigaction(2) SIGTERM: %s\n", - __func__, strerror(errno)); - return -1; - } - else if (sigaction(SIGPIPE, &sa, NULL)) + {.signal = SIGINT, .name = "SIGINT"}, + {.signal = SIGTERM, .name = "SIGTERM"}, + {.signal = SIGPIPE, .name = "SIGPIPE"} + }; + + for (size_t i = 0; i < sizeof signals / sizeof *signals; i++) { - fprintf(stderr, "%s: sigaction(2) SIGPIPE: %s\n", - __func__, strerror(errno)); - return -1; + const struct signal *const s = &signals [i]; + + if (sigaction(s->signal, &sa, NULL)) + { + fprintf(stderr, "%s: sigaction(2) %s: %s\n", + __func__, s->name, strerror(errno)); + return -1; + } } return 0; |
