On Thu, Mar 23, 2023 at 01:10:04PM +0100, Laszlo Ersek wrote:
> Per POSIX, execvp() is not safe to call in a child process forked from a
> multi-threaded process. We can now replace the execvp() call in the child
> process with a call to our fork-safe (async-signal-safe) variant.
> 
> Prepare our internal execvpe context on the parent's construction path,
> use the context in the child, and release the context in the parent on the
> way out, regardless of whether the handler as a whole succeeded or not.
> (The context is only a temporary resource.)
> 
> Signed-off-by: Laszlo Ersek <ler...@redhat.com>
> Reviewed-by: Richard W.M. Jones <rjo...@redhat.com>
> ---

>  
> -    environ = env.ptr;
> -    execvp (h->argv.ptr[0], h->argv.ptr);
> +    (void)nbd_internal_fork_safe_execvpe (&execvpe_ctx, &h->argv, env.ptr);
>      nbd_internal_fork_safe_perror (h->argv.ptr[0]);
>      if (errno == ENOENT)

I had to check that nbd_internal_fork_safe_perror() preserves errno -
but fortunately it does (it's always a good idea for functions
designed to be used on cleanup handling paths to behave that way).

Reviewed-by: Eric Blake <ebl...@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
_______________________________________________
Libguestfs mailing list
Libguestfs@redhat.com
https://listman.redhat.com/mailman/listinfo/libguestfs

Reply via email to