summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Gundersen <teg@jklm.no>2014-09-17 21:53:20 +0200
committerTom Gundersen <teg@jklm.no>2014-09-17 22:19:53 +0200
commit19c784c414e6f2b35a268034905e1db226e905f6 (patch)
tree75a0ec3ee1c547697b7855106dd4771d4ace0258
parent3f796750b192e62701e91a95f85389f876d1059b (diff)
udev: event - modernize spawn_exec()
-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 c8b142077e..dc1f682bfe 100644
--- a/src/udev/udev-event.c
+++ b/src/udev/udev-event.c
@@ -376,8 +376,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);
@@ -387,19 +386,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 */
@@ -412,9 +409,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,