shared: log error when execve fail
authorMauri de Souza Meneguzzo <mauri870@gmail.com>
Tue, 25 Jun 2024 02:47:15 +0000 (23:47 -0300)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 22 Jul 2024 12:27:30 +0000 (14:27 +0200)
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)

src/shared/exec-util.c
src/shared/spawn-polkit-agent.c

index 996edbf997a60f92deb82f9390430e35228d3aff..6f61eb2c61c990890cb1d3910829eb1eec44772b 100644 (file)
@@ -609,5 +609,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);
 }
index ce3c5fb948646490733513c6240d7b51980cad0a..fd91bd636fc16dfa28474e15e66c8969198c1aa2 100644 (file)
@@ -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);