bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Fix compilation on Solaris 10


From: Eric Blake
Subject: Re: Fix compilation on Solaris 10
Date: Thu, 28 Feb 2019 09:21:49 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0

On 2/28/19 7:38 AM, coypu@sdf.org wrote:
> Hi folks,
> 
> in Solaris 10 apparently O_CLOEXEC is not defined.
> (got a bug report in http://gnats.netbsd.org/54025)
> 
> Attached is a patch wrapping the code using it in #ifdef O_CLOEXEC.

Incomplete - if you are unable to atomically set the CLOEXEC flag during
open() due to lack of O_CLOEXEC, then you should use
fcntl(F_GETFD)/fcntl(F_SETFD) to set FD_CLOEXEC relatively soon after
the open(), so that the fd is still properly closed on forks either way.

In multi-threaded applications, O_CLOEXEC is essential to avoid data
races where one thread calls fork() in between another window calling
open() vs. fcntl() and thus inadvertently leaking the fd into the child;
but since bash is single-threaded, the race is only possible via signal
handlers, and hopefully bash isn't trying to fork from a signal handler
that might be interrupting the window between open() and fcntl().

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]