+/* SPDX-License-Identifier: LGPL-2.1+ */
/***
This file is part of systemd.
pipefd[1] = safe_close(pipefd[1]);
- if (dup2(pipefd[0], STDIN_FILENO) != STDIN_FILENO) {
- log_error_errno(errno, "Failed to dup2() fd: %m");
+ r = move_fd(pipefd[0], STDIN_FILENO, false);
+ if (r < 0) {
+ log_error_errno(r, "Failed to move fd: %m");
_exit(EXIT_FAILURE);
}
- if (pipefd[0] != STDIN_FILENO)
- pipefd[0] = safe_close(pipefd[0]);
-
null_fd = open("/dev/null", O_WRONLY|O_NOCTTY);
if (null_fd < 0) {
log_error_errno(errno, "Failed to open /dev/null: %m");
_exit(EXIT_FAILURE);
}
- if (dup2(null_fd, STDOUT_FILENO) != STDOUT_FILENO) {
- log_error_errno(errno, "Failed to dup2() fd: %m");
+ r = move_fd(null_fd, STDOUT_FILENO, false);
+ if (r < 0) {
+ log_error_errno(r, "Failed to move fd: %m");
_exit(EXIT_FAILURE);
}
- if (null_fd != STDOUT_FILENO)
- null_fd = safe_close(null_fd);
-
stdio_unset_cloexec();
if (unshare(CLONE_NEWNET) < 0)
pipefd[0] = safe_close(pipefd[0]);
- if (dup2(pipefd[1], STDOUT_FILENO) != STDOUT_FILENO) {
- log_error_errno(errno, "Failed to dup2() fd: %m");
+ r = move_fd(pipefd[1], STDOUT_FILENO, false);
+ if (r < 0) {
+ log_error_errno(r, "Failed to move fd: %m");
_exit(EXIT_FAILURE);
}
- if (pipefd[1] != STDOUT_FILENO)
- pipefd[1] = safe_close(pipefd[1]);
-
null_fd = open("/dev/null", O_RDONLY|O_NOCTTY);
if (null_fd < 0) {
log_error_errno(errno, "Failed to open /dev/null: %m");
_exit(EXIT_FAILURE);
}
- if (dup2(null_fd, STDIN_FILENO) != STDIN_FILENO) {
- log_error_errno(errno, "Failed to dup2() fd: %m");
+ r = move_fd(null_fd, STDIN_FILENO, false);
+ if (r < 0) {
+ log_error_errno(errno, "Failed to move fd: %m");
_exit(EXIT_FAILURE);
}
- if (null_fd != STDIN_FILENO)
- null_fd = safe_close(null_fd);
-
stdio_unset_cloexec();
if (unshare(CLONE_NEWNET) < 0)