diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2023-05-06 15:54:55 +0200 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2023-05-06 15:55:06 +0200 |
commit | 156edd022ef315eb68e0f7002994dfeb172a25c1 (patch) | |
tree | 596268f59b72cc1ccf1e2aad7e64297a3ff8b2de /src | |
parent | get rid of __attribute__((constructor)) (diff) | |
download | cimple-156edd022ef315eb68e0f7002994dfeb172a25c1.tar.gz cimple-156edd022ef315eb68e0f7002994dfeb172a25c1.zip |
shut down server/workers gracefully on SIGTERM
Diffstat (limited to 'src')
-rw-r--r-- | src/server.c | 9 | ||||
-rw-r--r-- | src/worker.c | 7 |
2 files changed, 13 insertions, 3 deletions
diff --git a/src/server.c b/src/server.c index 33610f3..51ee27f 100644 --- a/src/server.c +++ b/src/server.c @@ -393,8 +393,13 @@ int server_main(struct server *server) log("Waiting for new connections\n"); ret = tcp_server_accept(server->tcp_server, server_conn_handler, server); - if (ret < 0) - break; + if (ret < 0) { + if (errno == EINVAL && global_stop_flag) { + ret = 0; + break; + } + return ret; + } } return server_set_stopping(server); diff --git a/src/worker.c b/src/worker.c index 05243ac..7471cd1 100644 --- a/src/worker.c +++ b/src/worker.c @@ -195,8 +195,13 @@ int worker_main(struct worker *worker, UNUSED int argc, UNUSED char *argv[]) log("Waiting for a new command\n"); ret = msg_recv(worker->fd, &request); - if (ret < 0) + if (ret < 0) { + if (errno == EINVAL && global_stop_flag) { + ret = 0; + break; + } return ret; + } ret = worker_msg_handler(worker, &request); msg_free(&request); |