aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-10-10 23:16:11 +0200
committerXavier Del Campo Romero <xavi.dcr@tutanota.com>2023-10-10 23:16:11 +0200
commit832e198f8c77970b5b923eb18201ba83d9c72b80 (patch)
tree26039e1c731f1ca73c5b17b1447bb42d23263a20
parent07e0063870725506447a0ad29a6b92bb8c8c4e0b (diff)
server.c: Replace sequential calls with loop
-rw-r--r--server.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/server.c b/server.c
index 20329cb..b86a912 100644
--- a/server.c
+++ b/server.c
@@ -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;