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