|
|
28bab8 |
From c8ef6fff3b051ef970a439115e1630105f87bdce Mon Sep 17 00:00:00 2001
|
|
|
28bab8 |
From: Ernestas Kulik <ekulik@redhat.com>
|
|
|
28bab8 |
Date: Mon, 10 Jun 2019 13:38:34 +0200
|
|
|
28bab8 |
Subject: [PATCH] cli: run-command: Replace use of vfork() with fork()
|
|
|
28bab8 |
|
|
|
28bab8 |
vfork() replacing fork() was most likely an optimization, but, over
|
|
|
28bab8 |
time, changes were added that violate the contract, i.e. the code
|
|
|
28bab8 |
started going things other than exec and exit:
|
|
|
28bab8 |
https://pubs.opengroup.org/onlinepubs/009695399/functions/vfork.html.
|
|
|
28bab8 |
|
|
|
28bab8 |
posix_spawn(), as recommended by Clang, would not be a suitable
|
|
|
28bab8 |
replacement, as we need to call tcsetpgrp() on the child, doing which
|
|
|
28bab8 |
after exec is too late if the goal is to avoid races.
|
|
|
28bab8 |
|
|
|
28bab8 |
Signed-off-by: Ernestas Kulik <ekulik@redhat.com>
|
|
|
28bab8 |
---
|
|
|
28bab8 |
src/cli/run-command.c | 6 +++---
|
|
|
28bab8 |
1 file changed, 3 insertions(+), 3 deletions(-)
|
|
|
28bab8 |
|
|
|
28bab8 |
diff --git a/src/cli/run-command.c b/src/cli/run-command.c
|
|
|
28bab8 |
index 232f725..a8416a0 100644
|
|
|
28bab8 |
--- a/src/cli/run-command.c
|
|
|
28bab8 |
+++ b/src/cli/run-command.c
|
|
|
28bab8 |
@@ -53,10 +53,10 @@ static void start_command(struct command *cmd)
|
|
|
28bab8 |
|
|
|
28bab8 |
fflush(NULL);
|
|
|
28bab8 |
|
|
|
28bab8 |
- cmd->pid = vfork();
|
|
|
28bab8 |
+ cmd->pid = fork();
|
|
|
28bab8 |
if (cmd->pid < 0)
|
|
|
28bab8 |
{
|
|
|
28bab8 |
- perror_msg_and_die("vfork");
|
|
|
28bab8 |
+ perror_msg_and_die("fork");
|
|
|
28bab8 |
}
|
|
|
28bab8 |
if (cmd->pid == 0)
|
|
|
28bab8 |
{
|
|
|
28bab8 |
@@ -85,7 +85,7 @@ static void start_command(struct command *cmd)
|
|
|
28bab8 |
signal(SIGTTOU, SIG_DFL);
|
|
|
28bab8 |
|
|
|
28bab8 |
execvp(cmd->argv[0], cmd->argv);
|
|
|
28bab8 |
- /* Better to use _exit (not exit) after vfork:
|
|
|
28bab8 |
+ /* Better to use _exit (not exit) after fork:
|
|
|
28bab8 |
* we don't want to mess up parent's memory state
|
|
|
28bab8 |
* by running libc cleanup routines.
|
|
|
28bab8 |
*/
|
|
|
28bab8 |
--
|
|
|
28bab8 |
2.21.0
|
|
|
28bab8 |
|