From 93ef500388db2bf8e85446a3df0b013609cdbd73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Sat, 8 May 2021 13:17:04 +0200 Subject: [PATCH] Don't abuse vfork() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to POSIX.1, "vfork() has the same effect as fork(2), except that the behavior is undefined if the process created by vfork() either modifies any data other than a variable of type pid_t used to store the return value from vfork(), [...], or calls any other function before successfully calling _exit(2) or one of the exec(3) family of functions." These do all three, and work by pure chance (or maybe they don't, but we blisfully don't know). Either way: bad idea to call vfork() from C, unless you're the standard library, and POSIX.1-2008 removes it entirely Reviewed-by: Brian Behlendorf Signed-off-by: Ahelenia ZiemiaƄska Closes #12015 --- lib/libzfs/libzfs_util.c | 2 +- tests/zfs-tests/cmd/xattrtest/xattrtest.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c index 57498ca3cf..6abf21ac30 100644 --- a/lib/libzfs/libzfs_util.c +++ b/lib/libzfs/libzfs_util.c @@ -891,7 +891,7 @@ libzfs_run_process_impl(const char *path, char *argv[], char *env[], int flags, if (lines != NULL && pipe2(link, O_NONBLOCK | O_CLOEXEC) == -1) return (-EPIPE); - pid = vfork(); + pid = fork(); if (pid == 0) { /* Child process */ devnull_fd = open("/dev/null", O_WRONLY | O_CLOEXEC); diff --git a/tests/zfs-tests/cmd/xattrtest/xattrtest.c b/tests/zfs-tests/cmd/xattrtest/xattrtest.c index 8c4cb88955..0b68126c03 100644 --- a/tests/zfs-tests/cmd/xattrtest/xattrtest.c +++ b/tests/zfs-tests/cmd/xattrtest/xattrtest.c @@ -262,7 +262,7 @@ run_process(const char *path, char *argv[]) pid_t pid; int rc, devnull_fd; - pid = vfork(); + pid = fork(); if (pid == 0) { devnull_fd = open("/dev/null", O_WRONLY);