diff options
author | Daniel Mack <github@zonque.org> | 2015-06-24 00:12:28 +0200 |
---|---|---|
committer | Daniel Mack <github@zonque.org> | 2015-06-24 00:12:28 +0200 |
commit | 0891c5ed0b8d9ae20cae585d87da483d5d9c1e67 (patch) | |
tree | 169eab1125e06cc094baeab06173c0f6e5cef949 /src/udev/udev-event.c | |
parent | 3f9340a685ad51d1f7266e22e6f2720b54ae7e9d (diff) | |
parent | 56b13bcc992f296a061d9ae39d9369a8427bca73 (diff) |
Merge pull request #339 from teg/udev-coverity
coverity fixes in udev
Diffstat (limited to 'src/udev/udev-event.c')
-rw-r--r-- | src/udev/udev-event.c | 38 |
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 */ |