tree-wide: port various places over to use new rearrange_stdio()
This commit is contained in:
@@ -54,26 +54,12 @@ static int spawn_getent(const char *database, const char *key, pid_t *rpid) {
|
||||
}
|
||||
if (r == 0) {
|
||||
char *empty_env = NULL;
|
||||
int nullfd;
|
||||
|
||||
if (dup3(pipe_fds[1], STDOUT_FILENO, 0) < 0)
|
||||
safe_close(pipe_fds[0]);
|
||||
|
||||
if (rearrange_stdio(-1, pipe_fds[1], -1) < 0)
|
||||
_exit(EXIT_FAILURE);
|
||||
|
||||
safe_close_above_stdio(pipe_fds[0]);
|
||||
safe_close_above_stdio(pipe_fds[1]);
|
||||
|
||||
nullfd = open("/dev/null", O_RDWR);
|
||||
if (nullfd < 0)
|
||||
_exit(EXIT_FAILURE);
|
||||
|
||||
if (dup3(nullfd, STDIN_FILENO, 0) < 0)
|
||||
_exit(EXIT_FAILURE);
|
||||
|
||||
if (dup3(nullfd, STDERR_FILENO, 0) < 0)
|
||||
_exit(EXIT_FAILURE);
|
||||
|
||||
safe_close_above_stdio(nullfd);
|
||||
|
||||
close_all_fds(NULL, 0);
|
||||
|
||||
execle("/usr/bin/getent", "getent", database, key, NULL, &empty_env);
|
||||
|
||||
+7
-15
@@ -2582,23 +2582,15 @@ static int outer_child(
|
||||
return log_error_errno(errno, "PR_SET_PDEATHSIG failed: %m");
|
||||
|
||||
if (interactive) {
|
||||
close_nointr(STDIN_FILENO);
|
||||
close_nointr(STDOUT_FILENO);
|
||||
close_nointr(STDERR_FILENO);
|
||||
int terminal;
|
||||
|
||||
r = open_terminal(console, O_RDWR);
|
||||
if (r != STDIN_FILENO) {
|
||||
if (r >= 0) {
|
||||
safe_close(r);
|
||||
r = -EINVAL;
|
||||
}
|
||||
terminal = open_terminal(console, O_RDWR);
|
||||
if (terminal < 0)
|
||||
return log_error_errno(terminal, "Failed to open console: %m");
|
||||
|
||||
return log_error_errno(r, "Failed to open console: %m");
|
||||
}
|
||||
|
||||
if (dup2(STDIN_FILENO, STDOUT_FILENO) != STDOUT_FILENO ||
|
||||
dup2(STDIN_FILENO, STDERR_FILENO) != STDERR_FILENO)
|
||||
return log_error_errno(errno, "Failed to duplicate console: %m");
|
||||
r = rearrange_stdio(terminal, terminal, terminal); /* invalidates 'terminal' on success and failure */
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to move console to stdin/stdout/stderr: %m");
|
||||
}
|
||||
|
||||
r = reset_audit_loginuid();
|
||||
|
||||
Reference in New Issue
Block a user