]> git.ipfire.org Git - thirdparty/mdadm.git/commitdiff
start_mdmon: provide more dynamic way to close-all-fds
authorNeilBrown <neilb@suse.de>
Wed, 7 Sep 2011 03:00:32 +0000 (13:00 +1000)
committerNeilBrown <neilb@suse.de>
Wed, 7 Sep 2011 03:00:32 +0000 (13:00 +1000)
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>
util.c

diff --git a/util.c b/util.c
index ce0323964562361ecb061227ad461304d58656fd..5617d0293c32683c6b7efe39f87ef324258fdadd 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1573,7 +1573,7 @@ int mdmon_running(int devnum)
 
 int start_mdmon(int devnum)
 {
-       int i;
+       int i, skipped;
        int len;
        pid_t pid;      
        int status;
@@ -1604,8 +1604,13 @@ int start_mdmon(int devnum)
        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",