diff options
| author | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-05-01 03:06:34 +0200 |
|---|---|---|
| committer | Xavier Del Campo Romero <xavi.dcr@tutanota.com> | 2023-07-20 23:52:54 +0200 |
| commit | f75ff13b31d546b4bceea07ce0008bf0fc5ecf71 (patch) | |
| tree | 6739cd2d8202ad5710686eee2f96755a36f9c0ef /server.c | |
| parent | 0b6f28d96a6ba90a88f6ffdc712a95ff49122fcf (diff) | |
Avoid crashing on SIGPIPE
Under some circumstances, clients could cause SIGPIPE to slcl. Since
this signal was not handled by server.c (i.e., via sigaction(3)), slcl
would crash without any error messages printed to stderr.
In such situation, SIGPIPE should not be usually considered a fatal
error, so it is preferrable to close the connection and keep working.
Diffstat (limited to 'server.c')
| -rw-r--r-- | server.c | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -167,7 +167,17 @@ static volatile sig_atomic_t do_exit; static void handle_signal(const int signum) { - do_exit = 1; + switch (signum) + { + case SIGINT: + /* Fall through. */ + case SIGTERM: + do_exit = 1; + break; + + default: + break; + } } struct server_client *server_poll(struct server *const s, bool *const io, @@ -286,7 +296,13 @@ static int init_signals(void) } else if (sigaction(SIGTERM, &sa, NULL)) { - fprintf(stderr, "%s: sigaction(2) SIGINT: %s\n", + fprintf(stderr, "%s: sigaction(2) SIGTERM: %s\n", + __func__, strerror(errno)); + return -1; + } + else if (sigaction(SIGPIPE, &sa, NULL)) + { + fprintf(stderr, "%s: sigaction(2) SIGPIPE: %s\n", __func__, strerror(errno)); return -1; } |
