1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-25 01:34:28 +03:00

basic/util: check return value of dup2 in fork_agent()

CID #1304689.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2016-04-08 21:08:29 -04:00
parent edfd706d9c
commit 94edd38e1d

View File

@ -419,13 +419,17 @@ int fork_agent(pid_t *pid, const int except[], unsigned n_except, const char *pa
_exit(EXIT_FAILURE);
}
if (!stdout_is_tty)
dup2(fd, STDOUT_FILENO);
if (!stdout_is_tty && dup2(fd, STDOUT_FILENO) < 0) {
log_error_errno(errno, "Failed to dup2 /dev/tty: %m");
_exit(EXIT_FAILURE);
}
if (!stderr_is_tty)
dup2(fd, STDERR_FILENO);
if (!stderr_is_tty && dup2(fd, STDERR_FILENO) < 0) {
log_error_errno(errno, "Failed to dup2 /dev/tty: %m");
_exit(EXIT_FAILURE);
}
if (fd > 2)
if (fd > STDERR_FILENO)
close(fd);
}