aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/tcp_server.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2023-05-15 18:52:56 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2023-05-15 18:52:56 +0200
commitc77c9a162a57ca140b922859b06cba6bcba3fb22 (patch)
tree7d3d71ddc43183fcc65ed1bbfa341568ee00caad /src/tcp_server.c
parentdocker: fix failing valgrind runs (diff)
downloadcimple-c77c9a162a57ca140b922859b06cba6bcba3fb22.tar.gz
cimple-c77c9a162a57ca140b922859b06cba6bcba3fb22.zip
signal: refactoring, add comments in tcp_server, etc.
Diffstat (limited to '')
-rw-r--r--src/tcp_server.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/tcp_server.c b/src/tcp_server.c
index d840414..dbf1146 100644
--- a/src/tcp_server.c
+++ b/src/tcp_server.c
@@ -60,7 +60,9 @@ static void *connection_thread(void *_ctx)
struct child_context *ctx = (struct child_context *)_ctx;
int ret = 0;
- ret = signal_block_child();
+ /* Let the child thread handle its signals except those that should be
+ * handled in the main thread. */
+ ret = signal_unblock_all_except_stop_signals();
if (ret < 0)
goto free_ctx;
@@ -92,7 +94,10 @@ int tcp_server_accept(const struct tcp_server *server, tcp_server_conn_handler h
goto free_ctx;
ctx->fd = ret;
- ret = signal_block_parent(&old_mask);
+ /* Block all signals (we'll unblock them later); the child thread will
+ * have all signals blocked initially. This allows the main thread to
+ * handle SIGINT/SIGTERM/etc. */
+ ret = signal_block_all(&old_mask);
if (ret < 0)
goto close_conn;
@@ -102,12 +107,13 @@ int tcp_server_accept(const struct tcp_server *server, tcp_server_conn_handler h
goto restore_mask;
}
- signal_set(&old_mask, NULL);
+ /* Restore the previously-enabled signals for handling in the main thread. */
+ signal_restore(&old_mask);
return ret;
restore_mask:
- signal_set(&old_mask, NULL);
+ signal_restore(&old_mask);
close_conn:
log_errno_if(close(ctx->fd), "close");