When forking mdmon we need to close all other fds because we don't
use O_CLOEXEC yet.
Any approach will be fairly arbitrary, but as we can expect fds to be
fairly dense, closing until we find a set number that don't need
closing is possible safer than only closing the first 100.
So keep closing until we find 20 that are already closed.
Signed-off-by: NeilBrown <neilb@suse.de>
int start_mdmon(int devnum)
{
- int i;
+ int i, skipped;
int len;
pid_t pid;
int status;
switch(fork()) {
case 0:
/* FIXME yuk. CLOSE_EXEC?? */
- for (i=3; i < 100; i++)
- close(i);
+ skipped = 0;
+ for (i=3; skipped < 20; i++)
+ if (close(i) < 0)
+ skipped++;
+ else
+ skipped = 0;
+
for (i=0; paths[i]; i++)
if (paths[i][0])
execl(paths[i], "mdmon",