linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
To: jes@trained-monkey.org
Cc: linux-raid@vger.kernel.org
Subject: [PATCH 4/4] Check if other Monitor instance running before fork.
Date: Wed,  9 Sep 2020 10:31:20 +0200	[thread overview]
Message-ID: <20200909083120.10396-5-mariusz.tkaczyk@intel.com> (raw)
In-Reply-To: <20200909083120.10396-1-mariusz.tkaczyk@intel.com>

From: Blazej Kucman <blazej.kucman@intel.com>

Make error message visible to the user.

Signed-off-by: Blazej Kucman <blazej.kucman@intel.com>
Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
---
 Monitor.c | 44 ++++++++++++++++++++++++++++----------------
 1 file changed, 28 insertions(+), 16 deletions(-)

diff --git a/Monitor.c b/Monitor.c
index 0fb4f77d..7fd48084 100644
--- a/Monitor.c
+++ b/Monitor.c
@@ -63,6 +63,7 @@ struct alert_info {
 };
 static int make_daemon(char *pidfile);
 static int check_one_sharer(int scan);
+static void write_autorebuild_pid(void);
 static void alert(char *event, char *dev, char *disc, struct alert_info *info);
 static int check_array(struct state *st, struct mdstat_ent *mdstat,
 		       int test, struct alert_info *info,
@@ -153,6 +154,11 @@ int Monitor(struct mddev_dev *devlist,
 	info.mailfrom = mailfrom;
 	info.dosyslog = dosyslog;
 
+	if (share){
+		if (check_one_sharer(c->scan))
+			return 1;
+	}
+
 	if (daemonise) {
 		int rv = make_daemon(pidfile);
 		if (rv >= 0)
@@ -160,8 +166,7 @@ int Monitor(struct mddev_dev *devlist,
 	}
 
 	if (share)
-		if (check_one_sharer(c->scan))
-			return 1;
+		write_autorebuild_pid();
 
 	if (devlist == NULL) {
 		mdlist = conf_get_ident(NULL);
@@ -328,8 +333,8 @@ static int check_one_sharer(int scan)
 	int pid;
 	FILE *comm_fp;
 	FILE *fp;
-	char comm_path[100];
-	char path[100];
+	char comm_path[PATH_MAX];
+	char path[PATH_MAX];
 	char comm[20];
 
 	sprintf(path, "%s/autorebuild.pid", MDMON_DIR);
@@ -356,21 +361,28 @@ static int check_one_sharer(int scan)
 		}
 		fclose(fp);
 	}
-	if (scan) {
-		if (mkdir(MDMON_DIR, S_IRWXU) < 0 && errno != EEXIST) {
+	return 0;
+}
+
+static void write_autorebuild_pid()
+{
+	char path[PATH_MAX];
+	int pid;
+	FILE *fp;
+	sprintf(path, "%s/autorebuild.pid", MDMON_DIR);
+
+	if (mkdir(MDMON_DIR, S_IRWXU) < 0 && errno != EEXIST) {
+		pr_err("Can't create autorebuild.pid file\n");
+	} else {
+		fp = fopen(path, "w");
+		if (!fp)
 			pr_err("Can't create autorebuild.pid file\n");
-		} else {
-			fp = fopen(path, "w");
-			if (!fp)
-				pr_err("Cannot create autorebuild.pidfile\n");
-			else {
-				pid = getpid();
-				fprintf(fp, "%d\n", pid);
-				fclose(fp);
-			}
+		else {
+			pid = getpid();
+			fprintf(fp, "%d\n", pid);
+			fclose(fp);
 		}
 	}
-	return 0;
 }
 
 static void alert(char *event, char *dev, char *disc, struct alert_info *info)
-- 
2.25.0


  parent reply	other threads:[~2020-09-09  8:32 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-09  8:31 [PATCH 0/4] mdmonitor improvements Mariusz Tkaczyk
2020-09-09  8:31 ` [PATCH 3/4] mdmonitor: set small delay once Mariusz Tkaczyk
2020-09-15 11:33   ` Nix
2020-10-14 15:35     ` Jes Sorensen
2020-09-09  8:31 ` Mariusz Tkaczyk [this message]
2020-10-14 15:38   ` [PATCH 4/4] Check if other Monitor instance running before fork Jes Sorensen
2020-09-29 14:34 ` [PATCH 0/4] mdmonitor improvements Tkaczyk, Mariusz
2020-10-14 15:30   ` Jes Sorensen
     [not found] ` <20200909083120.10396-2-mariusz.tkaczyk@intel.com>
2020-10-14 15:34   ` [PATCH 1/4] Monitor: refresh mdstat fd after select Jes Sorensen
     [not found] ` <20200909083120.10396-3-mariusz.tkaczyk@intel.com>
2020-10-14 15:34   ` [PATCH 2/4] Monitor: stop notifing about containers Jes Sorensen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200909083120.10396-5-mariusz.tkaczyk@intel.com \
    --to=mariusz.tkaczyk@intel.com \
    --cc=jes@trained-monkey.org \
    --cc=linux-raid@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).