Don't assume that mdmon is in the current directory.

Rather, assume that it is in the same directory from which
mdadm was run.  If not, then maybe /sbin or current directory.

Signed-off-by: Neil Brown <neilb@suse.de>
This commit is contained in:
NeilBrown 2008-07-18 16:37:13 +10:00
parent 8850ee3e1e
commit 44d2e36556
1 changed files with 27 additions and 4 deletions

31
util.c
View File

@ -1077,19 +1077,42 @@ int signal_mdmon(int devnum)
int start_mdmon(int devnum)
{
int i;
int len;
char pathbuf[1024];
char *paths[4] = {
pathbuf,
"/sbin/mdmon",
"mdmon",
NULL
};
if (env_no_mdmon())
return 0;
len = readlink("/proc/self/exe", pathbuf, sizeof(pathbuf));
if (len > 0) {
char *sl;
pathbuf[len] = 0;
sl = strrchr(pathbuf, '/');
if (sl)
sl++;
else
sl = pathbuf;
strcpy(sl, "mdmon");
} else
pathbuf[0] = '\0';
switch(fork()) {
case 0:
/* FIXME yuk. CLOSE_EXEC?? */
for (i=3; i < 100; i++)
close(i);
execl("./mdmon", "mdmon",
map_dev(dev2major(devnum),
dev2minor(devnum),
1), NULL);
for (i=0; paths[i]; i++)
if (paths[i][0])
execl(paths[i], "mdmon",
map_dev(dev2major(devnum),
dev2minor(devnum),
1), NULL);
exit(1);
case -1: fprintf(stderr, Name ": cannot run mdmon. "
"Array remains readonly\n");