Skip to contentSkip to conversation

unix exec: avoid atexit handlers when child execvp fails

PATCH In review Dimitri John Ledkov 2 participants 2 messages Apr 29, 2021 – May 4, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 unix exec: avoid atexit handlers when child execvp fails

Functions grub_util_exec_pipe() and grub_util_exec_pipe_stderr() currently call execvp(). If the call fails for any reason, the child currently calls exit(127). This in turn executes the parents atexit() handlers from the forked child, and then the same handlers are called again from parent. This is usually not desired, and can lead to deadlocks, and undesired behaviour.

This patch fixes up "unix exec: avoid atexit handlers when child exits" further.

Fixes e75cf4a58b5eaf482804e5e1b2cc7d4399df350e

---
 grub-core/osdep/unix/exec.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
grub-core/osdep/unix/exec.c +2 -2
index db3259f650..e8db9202fb 100644
@@ -188,7 +188,7 @@ grub_util_exec_pipe (const char *const *argv, int *fd)
       close (pipe_fd[1]);
 
       execvp ((char *) argv[0], (char **) argv);
-      exit (127);
+      _exit (127);
     }
   else
     {
@@ -234,7 +234,7 @@ grub_util_exec_pipe_stderr (const char *const *argv, int *fd)
       close (pipe_fd[1]);
 
       execvp ((char *) argv[0], (char **) argv);
-      exit (127);
+      _exit (127);
     }
   else
     {
Signature · 1 line
2.27.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Dimitri John Ledkov

Functions grub_util_exec_pipe() and grub_util_exec_pipe_stderr() currently call execvp(). If the call fails for any reason, the child currently calls exit(127). This in turn executes the parents atexit() handlers from the forked child, and then the same handlers are called again from parent. This is usually not desired, and can lead to deadlocks, and undesired behaviour.

Quoted 6 lines

This patch fixes up "unix exec: avoid atexit handlers when child exits" further.

Fixes e75cf4a58b5eaf482804e5e1b2cc7d4399df350e

Daniel