summaryrefslogtreecommitdiff
path: root/mdmon.c
diff options
context:
space:
mode:
authorMariusz Tkaczyk <mariusz.tkaczyk@intel.com>2020-11-04 10:02:36 +0100
committerJes Sorensen <jsorensen@fb.com>2020-11-25 18:15:55 -0500
commitff6bb131a46e1bac84a26e5b2c4bf408c0e56926 (patch)
tree3234e5a3eb4e383a298f4bd27254c812cd222059 /mdmon.c
parenta8f3cfd54e45c8aabc4a99cdc92b6b9080b26607 (diff)
downloadmdadm-ff6bb131a46e1bac84a26e5b2c4bf408c0e56926.tar.gz
mdadm: Unify forks behaviour
If mdadm is run by udev or systemd, it gets a pipe as each stream. Forks in the background may run after an event or service has been processed when udev is detached from pipe. As a result process fails quietly if any message is written. To prevent from it, each fork has to close all parent streams. Leave stderr and stdout opened only for debug purposes. Unify it across all forks. Introduce other descriptors detection by scanning /proc/self/fd directory. Add generic method for managing systemd services. Signed-off-by: Mariusz Tkaczyk <mariusz.tkaczyk@intel.com>
Diffstat (limited to 'mdmon.c')
-rw-r--r--mdmon.c9
1 files changed, 1 insertions, 8 deletions
diff --git a/mdmon.c b/mdmon.c
index ff985d2..c71e62c 100644
--- a/mdmon.c
+++ b/mdmon.c
@@ -546,14 +546,7 @@ static int mdmon(char *devnm, int must_fork, int takeover)
}
setsid();
- close(0);
- open("/dev/null", O_RDWR);
- close(1);
- ignore = dup(0);
-#ifndef DEBUG
- close(2);
- ignore = dup(0);
-#endif
+ manage_fork_fds(0);
/* This silliness is to stop the compiler complaining
* that we ignore 'ignore'