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;
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) {