1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-22 17:35:35 +03:00

polkit-agent: modernize code a bit

- Use _cleanup_close_pair_ attribute for the pipe FDs,
- Return earlier on failure in forking polkit agent.
This commit is contained in:
Yu Watanabe 2024-12-03 18:36:15 +09:00
parent 0f81c8406f
commit 388d6c5f37

View File

@ -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]);
pipe_fd[1] = 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);
/* Wait until the agent closes the fd */
(void) fd_wait_for_event(pipe_fd[0], POLLHUP, USEC_INFINITY);
safe_close(pipe_fd[0]);
return r;
return 1;
}
void polkit_agent_close(void) {