From: Yu Watanabe Date: Tue, 3 Dec 2024 09:36:15 +0000 (+0900) Subject: polkit-agent: modernize code a bit X-Git-Tag: v258-rc1~1890^2~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=388d6c5f37238a9f5c6a2abe231d9b2633ba8b3b;p=thirdparty%2Fsystemd.git polkit-agent: modernize code a bit - Use _cleanup_close_pair_ attribute for the pipe FDs, - Return earlier on failure in forking polkit agent. --- diff --git a/src/shared/polkit-agent.c b/src/shared/polkit-agent.c index d87eb56164d..4a0d83e8ba9 100644 --- a/src/shared/polkit-agent.c +++ b/src/shared/polkit-agent.c @@ -21,8 +21,9 @@ static pid_t agent_pid = 0; int polkit_agent_open(void) { + _cleanup_close_pair_ int pipe_fd[2] = EBADF_PAIR; char notify_fd[DECIMAL_STR_MAX(int) + 1]; - int pipe_fd[2], r; + int r; if (agent_pid > 0) return 0; @@ -55,19 +56,16 @@ int polkit_agent_open(void) { POLKIT_AGENT_BINARY_PATH, "--notify-fd", notify_fd, "--fallback"); + if (r < 0) + return log_error_errno(r, "Failed to fork polkit agent: %m"); /* Close the writing side, because that's the one for the agent */ - safe_close(pipe_fd[1]); - - if (r < 0) - log_error_errno(r, "Failed to fork polkit agent: %m"); - else - /* Wait until the agent closes the fd */ - (void) fd_wait_for_event(pipe_fd[0], POLLHUP, USEC_INFINITY); + pipe_fd[1] = safe_close(pipe_fd[1]); - safe_close(pipe_fd[0]); + /* Wait until the agent closes the fd */ + (void) fd_wait_for_event(pipe_fd[0], POLLHUP, USEC_INFINITY); - return r; + return 1; } void polkit_agent_close(void) {