From f9f5f0f3cd6c0af6a84af274ef8c4c5302d0a5fb Mon Sep 17 00:00:00 2001 From: "Sven M. Hallberg" Date: Tue, 14 Oct 2014 15:27:45 +0200 Subject: [PATCH] publish example: exit cleanly on SIGINT, SIGTERM --- examples/core-publish-service.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/examples/core-publish-service.c b/examples/core-publish-service.c index 8d6377e..1d5ce9d 100644 --- a/examples/core-publish-service.c +++ b/examples/core-publish-service.c @@ -24,6 +24,8 @@ #include #include #include +#include +#include #include #include @@ -189,6 +191,14 @@ static void server_callback(CattaServer *s, CattaServerState state, CATTA_GCC_UN } } +static void signal_exit(int signum) { + int errnosave = errno; + catta_simple_poll_quit(simple_poll); + errno = errnosave; + + (void)signum; // ignore +} + int main(CATTA_GCC_UNUSED int argc, CATTA_GCC_UNUSED char*argv[]) { CattaServerConfig config; CattaServer *server = NULL; @@ -224,6 +234,10 @@ int main(CATTA_GCC_UNUSED int argc, CATTA_GCC_UNUSED char*argv[]) { goto fail; } + /* exit cleanly on signals */ + signal(SIGINT, signal_exit); + signal(SIGTERM, signal_exit); + /* Run the main loop */ catta_simple_poll_loop(simple_poll); -- 2.39.5