dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/mdadm-3.2.6-Add-support-for-launching-mdmon-via-systemctl-instea.patch

373056
From 0f7bdf8946316548500858303549e396655450c5 Mon Sep 17 00:00:00 2001
373056
From: Jes Sorensen <Jes.Sorensen@redhat.com>
373056
Date: Fri, 1 Feb 2013 16:15:18 +0100
373056
Subject: [PATCH 2/4] Add support for launching mdmon via systemctl instead of
373056
 fork/exec
373056
373056
If launching mdmon via systemctl fails, we fall back to the old method
373056
of fork/exec. This allows for having mdmon launched via systemctl
373056
which avoids problems with it getting killed by systemd due to it
373056
ending up in the parent's cgroup (udev).
373056
373056
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
373056
Signed-off-by: NeilBrown <neilb@suse.de>
373056
---
373056
 Makefile               |  4 ++++
373056
 systemd/mdmon@.service | 18 ++++++++++++++++++
373056
 util.c                 | 28 ++++++++++++++++++++++++++++
373056
 3 files changed, 50 insertions(+)
373056
 create mode 100644 systemd/mdmon@.service
373056
373056
diff --git a/Makefile b/Makefile
373056
index b9787d6..b6edb23 100644
373056
--- a/Makefile
373056
+++ b/Makefile
373056
@@ -73,6 +73,7 @@ MAP_PATH = $(MAP_DIR)/$(MAP_FILE)
373056
 MDMON_DIR = $(MAP_DIR)
373056
 # place for autoreplace cookies
373056
 FAILED_SLOTS_DIR = /run/mdadm/failed-slots
373056
+SYSTEMD_DIR=/lib/systemd/system
373056
 DIRFLAGS = -DMAP_DIR=\"$(MAP_DIR)\" -DMAP_FILE=\"$(MAP_FILE)\"
373056
 DIRFLAGS += -DMDMON_DIR=\"$(MDMON_DIR)\"
373056
 DIRFLAGS += -DFAILED_SLOTS_DIR=\"$(FAILED_SLOTS_DIR)\"
373056
@@ -264,6 +265,9 @@ install-man: mdadm.8 md.4 mdadm.conf.5 mdmon.8
373056
 install-udev: udev-md-raid.rules
373056
 	$(INSTALL) -D -m 644 udev-md-raid.rules $(DESTDIR)$(UDEVDIR)/rules.d/64-md-raid.rules
373056
 
373056
+install-systemd: systemd/mdmon@.service
373056
+	$(INSTALL) -D -m 644 systemd/mdmon@.service $(DESTDIR)$(SYSTEMD_DIR)/mdmon@.service
373056
+
373056
 uninstall:
373056
 	rm -f $(DESTDIR)$(MAN8DIR)/mdadm.8 $(DESTDIR)$(MAN8DIR)/mdmon.8 $(DESTDIR)$(MAN4DIR)/md.4 $(DESTDIR)$(MAN5DIR)/mdadm.conf.5 $(DESTDIR)$(BINDIR)/mdadm
373056
 
373056
diff --git a/systemd/mdmon@.service b/systemd/mdmon@.service
373056
new file mode 100644
373056
index 0000000..ddb475f
373056
--- /dev/null
373056
+++ b/systemd/mdmon@.service
373056
@@ -0,0 +1,18 @@
373056
+#  This file is part of mdadm.
373056
+#
373056
+#  mdadm is free software; you can redistribute it and/or modify it
373056
+#  under the terms of the GNU General Public License as published by
373056
+#  the Free Software Foundation; either version 2 of the License, or
373056
+#  (at your option) any later version.
373056
+
373056
+[Unit]
373056
+Description=MD Metadata Monitor on /dev/%I
373056
+DefaultDependencies=no
373056
+Before=initrd-switch-root.target
373056
+
373056
+[Service]
373056
+ExecStart=/sbin/mdmon %I
373056
+StandardInput=null
373056
+StandardOutput=null
373056
+StandardError=null
373056
+KillMode=none
373056
diff --git a/util.c b/util.c
373056
index e75b754..01af0b5 100644
373056
--- a/util.c
373056
+++ b/util.c
373056
@@ -1660,6 +1660,34 @@ int start_mdmon(int devnum)
373056
 	} else
373056
 		pathbuf[0] = '\0';
373056
 
373056
+	/* First try to run systemctl */
373056
+	switch(fork()) {
373056
+	case 0:
373056
+		/* FIXME yuk. CLOSE_EXEC?? */
373056
+		skipped = 0;
373056
+		for (i = 3; skipped < 20; i++)
373056
+			if (close(i) < 0)
373056
+				skipped++;
373056
+			else
373056
+				skipped = 0;
373056
+
373056
+		snprintf(pathbuf, sizeof(pathbuf), "mdmon@%s.service",
373056
+			 devnum2devname(devnum));
373056
+		status = execl("/usr/bin/systemctl", "systemctl", "start",
373056
+			       pathbuf, NULL);
373056
+		status = execl("/bin/systemctl", "systemctl", "start",
373056
+			       pathbuf, NULL);
373056
+		exit(1);
373056
+	case -1: fprintf(stderr, Name "cannot run mdmon. "
373056
+			 "Array remains readonly\n");
373056
+		return -1;
373056
+	default: /* parent - good */
373056
+		pid = wait(&status);
373056
+		if (pid >= 0 && status == 0)
373056
+			return 0;
373056
+	}
373056
+
373056
+	/* That failed, try running mdmon directly */
373056
 	switch(fork()) {
373056
 	case 0:
373056
 		/* FIXME yuk. CLOSE_EXEC?? */
373056
-- 
373056
1.7.11.7
373056