aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/tcp_server.c
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-08-28 18:17:23 +0200
committerEgor Tensin <Egor.Tensin@gmail.com>2022-08-28 19:42:28 +0200
commit4835e38f6f2005073e06907021d91dde2f4d2d4f (patch)
tree76d62a95b2eb080d3f5b9e12663971ee6f96098d /src/tcp_server.c
parentadd missing #include (diff)
downloadcimple-4835e38f6f2005073e06907021d91dde2f4d2d4f.tar.gz
cimple-4835e38f6f2005073e06907021d91dde2f4d2d4f.zip
don't use the latest glibc features
pthread_attr_setsigmask_np is only available since 2.32, which is too modern.
Diffstat (limited to 'src/tcp_server.c')
-rw-r--r--src/tcp_server.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/tcp_server.c b/src/tcp_server.c
index 47317e7..b536507 100644
--- a/src/tcp_server.c
+++ b/src/tcp_server.c
@@ -30,7 +30,15 @@ struct child_context {
static void *connection_thread(void *_ctx)
{
struct child_context *ctx = (struct child_context *)_ctx;
+ int ret = 0;
+
+ ret = signal_block_child();
+ if (ret < 0)
+ goto close;
+
ctx->handler(ctx->fd, ctx->arg);
+
+close:
check_errno(close(ctx->fd), "close");
free(ctx);
return NULL;
@@ -40,6 +48,7 @@ int tcp_server_accept(const struct tcp_server *server, tcp_server_conn_handler h
{
struct child_context *ctx;
pthread_attr_t child_attr;
+ sigset_t old_mask;
pthread_t child;
int conn_fd, ret = 0;
@@ -68,20 +77,25 @@ int tcp_server_accept(const struct tcp_server *server, tcp_server_conn_handler h
goto destroy_attr;
}
- ret = signal_set_thread_attr(&child_attr);
+ ret = signal_block_parent(&old_mask);
if (ret < 0)
goto destroy_attr;
ret = pthread_create(&child, &child_attr, connection_thread, ctx);
if (ret) {
pthread_print_errno(ret, "pthread_create");
- goto destroy_attr;
+ goto restore_mask;
}
+ signal_set(&old_mask, NULL);
+
pthread_check(pthread_attr_destroy(&child_attr), "pthread_attr_destroy");
return ret;
+restore_mask:
+ signal_set(&old_mask, NULL);
+
destroy_attr:
pthread_check(pthread_attr_destroy(&child_attr), "pthread_attr_destroy");