Skip to content

Commit

Permalink
shared: log error when execve fail
Browse files Browse the repository at this point in the history
If there is an error with the execv call in fork_agent the
program exits without any meaningful log message. Log the
command and errno so the user gets more information about
the failure.

Fixes: #33418

Signed-off-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
(cherry picked from commit a408d4453145621902b9a3ef78a552f83b09bd8d)
(cherry picked from commit 7fcfb73d71ed1d4230f58de1a94790e0c28719ea)
(cherry picked from commit 76fe6eb)
  • Loading branch information
mauri870 authored and bluca committed Jul 24, 2024
1 parent 11f8b33 commit 8e8efdd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/shared/exec-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,5 +601,6 @@ int fork_agent(const char *name, const int except[], size_t n_except, pid_t *ret
va_end(ap);

execv(path, l);
log_error_errno(errno, "Failed to execute %s: %m", path);
_exit(EXIT_FAILURE);
}
11 changes: 8 additions & 3 deletions src/shared/spawn-polkit-agent.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,21 @@ int polkit_agent_open(void) {
xsprintf(notify_fd, "%i", pipe_fd[1]);

r = fork_agent("(polkit-agent)",
&pipe_fd[1], 1,
&pipe_fd[1],
1,
&agent_pid,
POLKIT_AGENT_BINARY_PATH,
POLKIT_AGENT_BINARY_PATH, "--notify-fd", notify_fd, "--fallback", NULL);
POLKIT_AGENT_BINARY_PATH,
"--notify-fd",
notify_fd,
"--fallback",
NULL);

/* 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 TTY ask password agent: %m");
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);
Expand Down

0 comments on commit 8e8efdd

Please sign in to comment.