From 092e3f81233655849156b0948a53f3b5f51b8c97 Mon Sep 17 00:00:00 2001 From: Peter Jones Date: Wed, 17 Oct 2012 14:43:58 -0400 Subject: [PATCH 15/42] Make daemon shutdown actually close the NSS databases and whatnot. Signed-off-by: Peter Jones --- src/daemon.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/daemon.c b/src/daemon.c index 085cfec..dd215f8 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -125,8 +125,7 @@ handle_kill_daemon(context *ctx, struct pollfd *pollfd, socklen_t size) ctx->backup_cms->log(ctx->backup_cms, ctx->priority|LOG_NOTICE, "pesignd exiting (pid %d)", getpid()); - cms_context_fini(ctx->backup_cms); - exit(0); + should_exit = 1; } static void @@ -625,6 +624,16 @@ handle_event(context *ctx, struct pollfd *pollfd) return 0; } +static void +do_shutdown(context *ctx, int nsockets, struct pollfd *pollfds) +{ + for (int i = 0; i < nsockets; i++) + close(pollfds[i].fd); + free(pollfds); + + xfree(ctx->errstr); +} + static int handle_events(context *ctx) { @@ -643,9 +652,14 @@ handle_events(context *ctx) pollfds[0].events = POLLIN|POLLPRI|POLLHUP; while (1) { + if (should_exit != 0) { +shutdown: + do_shutdown(ctx, nsockets, pollfds); + return 0; + } rc = ppoll(pollfds, nsockets, NULL, NULL); if (should_exit != 0) - exit(0); + goto shutdown; if (rc < 0) { ctx->backup_cms->log(ctx->backup_cms, ctx->priority|LOG_WARNING, -- 1.7.12.1