X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fmdadm.git;a=blobdiff_plain;f=mdmon.c;fp=mdmon.c;h=ff985d291ee9045ede3daf68c1184af3ee0384eb;hp=0955fcc54a888557436d13ba018f65157dec6339;hb=d2e11da4b7fd0453e942f43e4196dc63b3dbd708;hpb=69d084784de196acec8ab703cd1b379af211d624 diff --git a/mdmon.c b/mdmon.c index 0955fcc5..ff985d29 100644 --- a/mdmon.c +++ b/mdmon.c @@ -171,6 +171,7 @@ static void try_kill_monitor(pid_t pid, char *devname, int sock) int fd; int n; long fl; + int rv; /* first rule of survival... don't off yourself */ if (pid == getpid()) @@ -201,9 +202,16 @@ static void try_kill_monitor(pid_t pid, char *devname, int sock) fl &= ~O_NONBLOCK; fcntl(sock, F_SETFL, fl); n = read(sock, buf, 100); - /* Ignore result, it is just the wait that - * matters - */ + + /* If there is I/O going on it might took some time to get to + * clean state. Wait for monitor to exit fully to avoid races. + * Ping it with SIGUSR1 in case that it is sleeping */ + for (n = 0; n < 25; n++) { + rv = kill(pid, SIGUSR1); + if (rv < 0) + break; + usleep(200000); + } } void remove_pidfile(char *devname)