summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2016-04-08 21:08:29 -0400
committerSven Eden <yamakuzure@gmx.net>2017-06-16 10:12:57 +0200
commit794becf1e6b0c357ad0d560b9c53e172cdb86e0b (patch)
treecadff52ee03434e8cdd3aa7609bcfe43d3ae95aa /src
parentc6ec3ad2eb8d451af61a6180047918092c71656e (diff)
basic/util: check return value of dup2 in fork_agent()
CID #1304689.
Diffstat (limited to 'src')
-rw-r--r--src/basic/util.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/basic/util.c b/src/basic/util.c
index b049a4485..c6d3442c9 100644
--- a/src/basic/util.c
+++ b/src/basic/util.c
@@ -424,13 +424,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);
}