diff options
author | Nikos Mavrogiannopoulos <nmav@redhat.com> | 2014-07-31 10:37:09 +0200 |
---|---|---|
committer | Stef Walter <stefw@redhat.com> | 2014-09-25 09:48:15 +0200 |
commit | 620c91d04628321e4e212bc6bbeba4aa345937d4 (patch) | |
tree | 6fe06ac1ba00eaf6c0d0c9b291f79dd5af754700 | |
parent | 206379862e41114a3f6f4fb010b576b45bcd93f0 (diff) | |
download | p11-kit-620c91d04628321e4e212bc6bbeba4aa345937d4.tar.gz |
remote: gracefully handle sigterm
-rw-r--r-- | p11-kit/remote.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/p11-kit/remote.c b/p11-kit/remote.c index 4367bf4..36cebdf 100644 --- a/p11-kit/remote.c +++ b/p11-kit/remote.c @@ -69,6 +69,7 @@ typedef void (*sighandler_t)(int); #endif static unsigned need_children_cleanup = 0; +static unsigned terminate = 0; static unsigned children_avail = 0; static @@ -205,6 +206,11 @@ static void handle_children(int signo) need_children_cleanup = 1; } +static void handle_term(int signo) +{ + terminate = 1; +} + int p11_kit_remote_serve_module (CK_FUNCTION_LIST *module, const char *socket_file, @@ -230,7 +236,11 @@ p11_kit_remote_serve_module (CK_FUNCTION_LIST *module, sigemptyset(&blockset); sigemptyset(&emptyset); sigaddset(&blockset, SIGCHLD); + sigaddset(&blockset, SIGTERM); + sigaddset(&blockset, SIGINT); ocsignal(SIGCHLD, handle_children); + ocsignal(SIGTERM, handle_term); + ocsignal(SIGINT, handle_term); return_val_if_fail (module != NULL, 1); @@ -291,6 +301,9 @@ p11_kit_remote_serve_module (CK_FUNCTION_LIST *module, if (need_children_cleanup) cleanup_children(); + if (terminate != 0) + goto exit; + FD_ZERO(&rd_set); FD_SET(sd, &rd_set); |