[PATCH 24/33] Handling SIG TERM of the child

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

We handle SIGTERM on the child, by sending a message to the client and then
closing the socket opened for that connection.

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

diff --git a/src/coredump.c b/src/coredump.c
index c0da457..ab120b9 100755
--- a/src/coredump.c
+++ b/src/coredump.c
@@ -501,6 +501,18 @@ int dump_task(struct ucred *client_info, char *core_file)
return 0;
}

+/* Handles signals to the child */
+void sig_handler_service_proc(int sig)
+{
+ if (sig != SIGPIPE)
+ send_reply(EINTR);
+ close(new_sock);
+
+ gencore_log("[%d]: Cleanup done and child exiting.\n", pid_log);
+
+ fflush(fp_log);
+}
+
/* Services requests */
int service_request(void)
{
@@ -508,6 +520,11 @@ int service_request(void)
char core_file[CORE_FILE_NAME_SZ];
struct ucred client_info;

+ /* Handles stopping of the servicing process */
+ signal(SIGTERM, sig_handler_service_proc);
+ signal(SIGSEGV, sig_handler_service_proc);
+ signal(SIGPIPE, sig_handler_service_proc);
+
/* Receive the message */
ret = receive_core_filename(core_file);
if (ret)