dcavalca / rpms / mdadm

Forked from rpms/mdadm 3 years ago
Clone

Blame SOURCES/0095-Check-if-other-Monitor-instance-running-before-fork.patch

790dca
From 7f3b2d1d1621cbdc60b5af4a41445391010fe9e1 Mon Sep 17 00:00:00 2001
790dca
From: Blazej Kucman <blazej.kucman@intel.com>
790dca
Date: Wed, 9 Sep 2020 10:31:20 +0200
790dca
Subject: [PATCH 095/108] Check if other Monitor instance running before fork.
790dca
790dca
Make error message visible to the user.
790dca
790dca
Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
790dca
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
790dca
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
790dca
---
790dca
 Monitor.c | 44 ++++++++++++++++++++++++++++----------------
790dca
 1 file changed, 28 insertions(+), 16 deletions(-)
790dca
790dca
diff --git a/Monitor.c b/Monitor.c
790dca
index 0fb4f77..7fd4808 100644
790dca
--- a/Monitor.c
790dca
+++ b/Monitor.c
790dca
@@ -63,6 +63,7 @@ struct alert_info {
790dca
 };
790dca
 static int make_daemon(char *pidfile);
790dca
 static int check_one_sharer(int scan);
790dca
+static void write_autorebuild_pid(void);
790dca
 static void alert(char *event, char *dev, char *disc, struct alert_info *info);
790dca
 static int check_array(struct state *st, struct mdstat_ent *mdstat,
790dca
 		       int test, struct alert_info *info,
790dca
@@ -153,6 +154,11 @@ int Monitor(struct mddev_dev *devlist,
790dca
 	info.mailfrom = mailfrom;
790dca
 	info.dosyslog = dosyslog;
790dca
 
790dca
+	if (share){
790dca
+		if (check_one_sharer(c->scan))
790dca
+			return 1;
790dca
+	}
790dca
+
790dca
 	if (daemonise) {
790dca
 		int rv = make_daemon(pidfile);
790dca
 		if (rv >= 0)
790dca
@@ -160,8 +166,7 @@ int Monitor(struct mddev_dev *devlist,
790dca
 	}
790dca
 
790dca
 	if (share)
790dca
-		if (check_one_sharer(c->scan))
790dca
-			return 1;
790dca
+		write_autorebuild_pid();
790dca
 
790dca
 	if (devlist == NULL) {
790dca
 		mdlist = conf_get_ident(NULL);
790dca
@@ -328,8 +333,8 @@ static int check_one_sharer(int scan)
790dca
 	int pid;
790dca
 	FILE *comm_fp;
790dca
 	FILE *fp;
790dca
-	char comm_path[100];
790dca
-	char path[100];
790dca
+	char comm_path[PATH_MAX];
790dca
+	char path[PATH_MAX];
790dca
 	char comm[20];
790dca
 
790dca
 	sprintf(path, "%s/autorebuild.pid", MDMON_DIR);
790dca
@@ -356,21 +361,28 @@ static int check_one_sharer(int scan)
790dca
 		}
790dca
 		fclose(fp);
790dca
 	}
790dca
-	if (scan) {
790dca
-		if (mkdir(MDMON_DIR, S_IRWXU) < 0 && errno != EEXIST) {
790dca
+	return 0;
790dca
+}
790dca
+
790dca
+static void write_autorebuild_pid()
790dca
+{
790dca
+	char path[PATH_MAX];
790dca
+	int pid;
790dca
+	FILE *fp;
790dca
+	sprintf(path, "%s/autorebuild.pid", MDMON_DIR);
790dca
+
790dca
+	if (mkdir(MDMON_DIR, S_IRWXU) < 0 && errno != EEXIST) {
790dca
+		pr_err("Can't create autorebuild.pid file\n");
790dca
+	} else {
790dca
+		fp = fopen(path, "w");
790dca
+		if (!fp)
790dca
 			pr_err("Can't create autorebuild.pid file\n");
790dca
-		} else {
790dca
-			fp = fopen(path, "w");
790dca
-			if (!fp)
790dca
-				pr_err("Cannot create autorebuild.pidfile\n");
790dca
-			else {
790dca
-				pid = getpid();
790dca
-				fprintf(fp, "%d\n", pid);
790dca
-				fclose(fp);
790dca
-			}
790dca
+		else {
790dca
+			pid = getpid();
790dca
+			fprintf(fp, "%d\n", pid);
790dca
+			fclose(fp);
790dca
 		}
790dca
 	}
790dca
-	return 0;
790dca
 }
790dca
 
790dca
 static void alert(char *event, char *dev, char *disc, struct alert_info *info)
790dca
-- 
790dca
2.7.5
790dca