From 134e17742f79a18cfdf246e1191b20003128eea7 Mon Sep 17 00:00:00 2001 From: Eric Chanudet Date: Thu, 14 Jun 2018 17:17:18 -0400 Subject: [PATCH] xcpmd: Remove pidfile on exit. Initscripts should not have to remove the pidfile created by the daemon. Signed-off-by: Eric Chanudet OXT-1352 (cherry picked from commit eb59cb48046e9f42f3ea654219940ae72ba3142c) Signed-off-by: Eric Chanudet --- xcpmd/src/xcpmd.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/xcpmd/src/xcpmd.c b/xcpmd/src/xcpmd.c index 07c547e9..020a4c96 100644 --- a/xcpmd/src/xcpmd.c +++ b/xcpmd/src/xcpmd.c @@ -43,9 +43,18 @@ #include "rules.h" +void sighandler_term(int signal, short event, void *base) +{ + (void) signal; + (void) event; + event_base_loopbreak(base); +} + int main(int argc, char *argv[]) { int ret = 0; + struct event ev_sigterm; + struct event_base *ev_base; #ifndef RUN_STANDALONE openlog("xcpmd", 0, LOG_DAEMON); @@ -55,7 +64,11 @@ int main(int argc, char *argv[]) { xcpmd_log(LOG_INFO, "Starting XenClient power management daemon.\n"); //Initialize libevent library - event_init(); + ev_base = event_init(); + + //SIGTERM handler. + evsignal_set(&ev_sigterm, SIGTERM, sighandler_term, ev_base); + evsignal_add(&ev_sigterm, NULL); //Initialize xenstore. if (xenstore_init() == -1) { @@ -131,8 +144,7 @@ int main(int argc, char *argv[]) { #ifndef RUN_STANDALONE closelog(); #endif + unlink(XCPMD_PID_FILE); return ret; } - -