From 4b4431d78c08cf67b6b036868de371214c9e86aa Mon Sep 17 00:00:00 2001 From: Gionatan Danti Date: Fri, 22 Nov 2024 16:46:52 +0100 Subject: [PATCH] Fix race in libzfs_run_process_impl When replacing a disk, a child process is forked to run a script called zfs_prepare_disk (which can be useful for disk firmware update or health check). By default this script does nothing - it simply returns 0. When testing on a virtual machine, it returns so fast that the parent misses it: when checking, the child already exited. As waitpid returns -1, the parent incorrectly assume that the child process had an error or was killed. This, in turn, leaves the newly added disk in REMOVED or UNAVAIL status rather than completing the replace process. As child should be inspected via waitpid status flag and the relative macros, this patch remove the check around waitpid return code. Signed-off-by: Gionatan Danti --- lib/libzfs/libzfs_util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libzfs/libzfs_util.c b/lib/libzfs/libzfs_util.c index 1f7e7b0e647e..18da0c23a9d6 100644 --- a/lib/libzfs/libzfs_util.c +++ b/lib/libzfs/libzfs_util.c @@ -967,7 +967,7 @@ libzfs_run_process_impl(const char *path, char *argv[], char *env[], int flags, while ((error = waitpid(pid, &status, 0)) == -1 && errno == EINTR) ; - if (error < 0 || !WIFEXITED(status)) + if (!WIFEXITED(status)) return (-1); if (lines != NULL) {