Check if other Monitor instance running before fork.

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>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
This commit is contained in:
Blazej Kucman 2020-09-09 10:31:20 +02:00 committed by Jes Sorensen
parent cab9c67d46
commit 7f3b2d1d16
1 changed files with 28 additions and 16 deletions

View File

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