summaryrefslogtreecommitdiff
path: root/src/udev
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2015-06-23 17:03:19 +0200
committerTom Gundersen <teg@jklm.no>2015-06-23 17:20:12 +0200
commitf6e0a35376dcab1455af698cf3f3be5e810c0f20 (patch)
tree8a4b4b29f35f40bdfdd38ade0d7b9d523741c909 /src/udev
parente448a1c3a3eac4d73261bf8648110fc9f7aae806 (diff)
udev: event - check return code of dup2()
This fixes CID#1304688.
Diffstat (limited to 'src/udev')
-rw-r--r--src/udev/udev-event.c38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
index 5516a792eb..1092071e26 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -389,26 +389,44 @@ static int spawn_exec(struct udev_event *event,
const char *cmd, char *const argv[], char **envp,
int fd_stdout, int fd_stderr) {
_cleanup_close_ int fd = -1;
+ int r;
/* discard child output or connect to pipe */
fd = open("/dev/null", O_RDWR);
if (fd >= 0) {
- dup2(fd, STDIN_FILENO);
- if (fd_stdout < 0)
- dup2(fd, STDOUT_FILENO);
- if (fd_stderr < 0)
- dup2(fd, STDERR_FILENO);
+ r = dup2(fd, STDIN_FILENO);
+ if (r < 0)
+ log_warning_errno(errno, "redirecting stdin failed: %m");
+
+ if (fd_stdout < 0) {
+ r = dup2(fd, STDOUT_FILENO);
+ if (r < 0)
+ log_warning_errno(errno, "redirecting stdout failed: %m");
+ }
+
+ if (fd_stderr < 0) {
+ r = dup2(fd, STDERR_FILENO);
+ if (r < 0)
+ log_warning_errno(errno, "redirecting stderr failed: %m");
+ }
} else
- log_error_errno(errno, "open /dev/null failed: %m");
+ log_warning_errno(errno, "open /dev/null failed: %m");
/* connect pipes to std{out,err} */
if (fd_stdout >= 0) {
- dup2(fd_stdout, STDOUT_FILENO);
- safe_close(fd_stdout);
+ r = dup2(fd_stdout, STDOUT_FILENO);
+ if (r < 0)
+ log_warning_errno(errno, "redirecting stdout failed: %m");
+
+ fd_stdout = safe_close(fd_stdout);
}
+
if (fd_stderr >= 0) {
- dup2(fd_stderr, STDERR_FILENO);
- safe_close(fd_stderr);
+ r = dup2(fd_stderr, STDERR_FILENO);
+ if (r < 0)
+ log_warning_errno(errno, "redirecting stdout failed: %m");
+
+ fd_stderr = safe_close(fd_stderr);
}
/* terminate child in case parent goes away */