summaryrefslogtreecommitdiff
path: root/src/udev/udev-event.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/udev/udev-event.c')
-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,