Skip to contentSkip to conversation

Remove fifos on dmeventd shutdown

PATCH New Peter Rajnoha 3 participants 3 messages Mar 14, 2012 – Mar 15, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Remove fifos on dmeventd shutdown

I think we should clean these fifos properly (if not using systemd activation where they are maintained by systemd itself).

Also, there's missing SIGTERM signal handler registration for the case we run in foreground - it leaves the dmeventd.pid in filesystem then. (..it would leave the fifos behind as well)

Peter

---
 daemons/dmeventd/dmeventd.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)
daemons/dmeventd/dmeventd.c +11 -2
index b61fb8b..b28816e 100644
@@ -1735,10 +1735,18 @@ out:
 }
 #endif
 
-static void remove_lockfile(void)
+static void _remove_files_on_exit(void)
 {
 	if (unlink(DMEVENTD_PIDFILE))
 		perror(DMEVENTD_PIDFILE ": unlink failed");
+
+	if (!_systemd_activation) {
+		if (unlink(DM_EVENT_FIFO_CLIENT))
+			perror(DM_EVENT_FIFO_CLIENT " : unlink failed");
+
+		if (unlink(DM_EVENT_FIFO_SERVER))
+			perror(DM_EVENT_FIFO_SERVER " : unlink failed");
+	}
 }
 
 static void _daemonize(void)
@@ -1949,10 +1957,11 @@ int main(int argc, char *argv[])
 	if (dm_create_lockfile(DMEVENTD_PIDFILE) == 0)
 		exit(EXIT_FAILURE);
 
-	atexit(remove_lockfile);
+	atexit(_remove_files_on_exit);
 	(void) dm_prepare_selinux_context(NULL, 0);
 
 	/* Set the rest of the signals to cause '_exit_now' to be set */
+	signal(SIGTERM, &_exit_handler);
 	signal(SIGINT, &_exit_handler);
 	signal(SIGHUP, &_exit_handler);
 	signal(SIGQUIT, &_exit_handler);
#1 lore raw

PATCH 1/1 Remove fifos on dmeventd shutdown

Quoted 6 lines · Peter Rajnoha

I think we should clean these fifos properly (if not using systemd activation where they are maintained by systemd itself).

Also, there's missing SIGTERM signal handler registration for the case we run in foreground - it leaves the dmeventd.pid in filesystem then. (..it would leave the fifos behind as well)

Looks OK to me. Ack.

Petr

Signature · 1 line
id' Ash = Ash; id' Dust = Dust; id' _ = undefined
#2 lore raw

PATCH 1/1 Remove fifos on dmeventd shutdown

In reply to Peter Rajnoha

daemons/dmeventd/dmeventd.c int main(int argc, char *argv[]) · line 1967

Quoted 5 lines · Peter Rajnoha
daemons/dmeventd/dmeventd.c +1 -0
 	/* Set the rest of the signals to cause '_exit_now' to be set */
+	signal(SIGTERM, &_exit_handler);
 	signal(SIGINT, &_exit_handler);
 	signal(SIGHUP, &_exit_handler);
 	signal(SIGQUIT, &_exit_handler);

I'd prefer it if we used sigaction() directly like we do elsewhere in lvm so we can specify precisely the behaviour we intend.

signal() has a bad history and, as the man page states, should be avoided.

Alasdair