[PATCH 23/33] Handling SIG TERM of the daemon

Janani Venkataraman
2014-03-20T09:42:10Z

We handle SIGTERM on the daemon, by closing the socket opened for that
connection.

Signed-off-by: Janani Venkataraman <jananive@linux.vnet.ibm.com>
---
src/coredump.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

diff --git a/src/coredump.c b/src/coredump.c
index 72ba8d8..c0da457 100755
--- a/src/coredump.c
+++ b/src/coredump.c
@@ -562,6 +562,17 @@ int handle_request(void)
return 0;
}

+/* Handles Signals to the Daemon */
+void sig_daemon_handler(int sig)
+{
+ close(socket_fd);
+ unlink(SOCKET_PATH);
+
+ gencore_log("[%d]: Cleanup done and daemon exiting.\n", pid_log);
+
+ fclose(fp_log);
+}
+
/* Daemon for self dump */
int daemon_dump(void)
{
@@ -602,6 +613,11 @@ int daemon_dump(void)
/* SIGCHILD - Signal handler */
signal(SIGCHLD, sigchild_handler);

+ /* Terminate Daemon - signal handler */
+ signal(SIGTERM, sig_daemon_handler);
+ signal(SIGSEGV, sig_daemon_handler);
+ signal(SIGPIPE, sig_daemon_handler);
+
while (1) {

/* Blocks on request */