diff options
author | NeilBrown <neilb@suse.de> | 2011-09-07 05:00:32 +0200 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2011-09-07 05:00:32 +0200 |
commit | 1913c3256bb657954dd84c3a73c11944a225ec04 (patch) | |
tree | ac61232002eced33bac5d92055ec7e4b137cf3e0 /util.c | |
parent | FIX: Prevent using null list pointer (diff) | |
download | mdadm-1913c3256bb657954dd84c3a73c11944a225ec04.tar.xz mdadm-1913c3256bb657954dd84c3a73c11944a225ec04.zip |
start_mdmon: provide more dynamic way to close-all-fds
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>
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -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", |