mirror of
git://sourceware.org/git/lvm2.git
synced 2024-12-21 13:34:40 +03:00
cov: daemonize avoid leak of FD on error path
Use our common patter for reopening FDs to /dev/null that avoids leaking FD on error path.
This commit is contained in:
parent
d95b26fae0
commit
d388b36da2
@ -653,18 +653,21 @@ static int _daemonise(struct filemap_monitor *fm)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!_verbose) {
|
if (!_verbose) {
|
||||||
if (close(STDIN_FILENO))
|
if ((fd = open("/dev/null", O_RDWR)) == -1) {
|
||||||
_early_log("Error closing stdin");
|
_early_log("Error opening /dev/null.");
|
||||||
if (close(STDOUT_FILENO))
|
|
||||||
_early_log("Error closing stdout");
|
|
||||||
if (close(STDERR_FILENO))
|
|
||||||
_early_log("Error closing stderr");
|
|
||||||
if ((open("/dev/null", O_RDONLY) < 0) ||
|
|
||||||
(open("/dev/null", O_WRONLY) < 0) ||
|
|
||||||
(open("/dev/null", O_WRONLY) < 0)) {
|
|
||||||
_early_log("Error opening stdio streams.");
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((dup2(fd, STDIN_FILENO) == -1) ||
|
||||||
|
(dup2(fd, STDOUT_FILENO) == -1) ||
|
||||||
|
(dup2(fd, STDERR_FILENO) == -1)) {
|
||||||
|
if (fd > STDERR_FILENO)
|
||||||
|
(void) close(fd);
|
||||||
|
_early_log("Error redirecting stdin/out/err to null.");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (fd > STDERR_FILENO)
|
||||||
|
(void) close(fd);
|
||||||
}
|
}
|
||||||
/* TODO: Use libdaemon/server/daemon-server.c _daemonise() */
|
/* TODO: Use libdaemon/server/daemon-server.c _daemonise() */
|
||||||
for (fd = (int) sysconf(_SC_OPEN_MAX) - 1; fd > STDERR_FILENO; fd--) {
|
for (fd = (int) sysconf(_SC_OPEN_MAX) - 1; fd > STDERR_FILENO; fd--) {
|
||||||
|
Loading…
Reference in New Issue
Block a user