summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-09-17 21:53:20 +0200
committerAnthony G. Basile <blueness@gentoo.org>2014-09-17 20:24:50 -0400
commitbe74fc7ab1d430fceae049b7f8e58bc913d9ecf3 (patch)
tree080e0767de8d2d88ab66051bed6bf10022efea6f
parentfb510149ad14851320b7b4d8c215caacca3bc2b1 (diff)
udev: event - modernize spawn_exec()
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
-rw-r--r--src/udev/udev-event.c15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/udev/udev-event.c b/src/udev/udev-event.c
index 06a1378db9..068e4fb167 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -377,8 +377,7 @@ out:
static int spawn_exec(struct udev_event *event,
const char *cmd, char *const argv[], char **envp, const sigset_t *sigmask,
int fd_stdout, int fd_stderr) {
- int err;
- int fd;
+ _cleanup_close_ int fd = -1;
/* discard child output or connect to pipe */
fd = open("/dev/null", O_RDWR);
@@ -388,19 +387,17 @@ static int spawn_exec(struct udev_event *event,
dup2(fd, STDOUT_FILENO);
if (fd_stderr < 0)
dup2(fd, STDERR_FILENO);
- close(fd);
- } else {
+ } else
log_error("open /dev/null failed: %m");
- }
/* connect pipes to std{out,err} */
if (fd_stdout >= 0) {
dup2(fd_stdout, STDOUT_FILENO);
- close(fd_stdout);
+ safe_close(fd_stdout);
}
if (fd_stderr >= 0) {
dup2(fd_stderr, STDERR_FILENO);
- close(fd_stderr);
+ safe_close(fd_stderr);
}
/* terminate child in case parent goes away */
@@ -413,9 +410,9 @@ static int spawn_exec(struct udev_event *event,
execve(argv[0], argv, envp);
/* exec failed */
- err = -errno;
log_error("failed to execute '%s' '%s': %m", argv[0], cmd);
- return err;
+
+ return -errno;
}
static void spawn_read(struct udev_event *event,