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

Re: Bug#679198: bash: [on native FreeBSD] unable to set FD_CLOEXEC flag



Control: tags -1 patch

On 03/07/12 17:47, Jonathan Nieder wrote:
> F_GETFL is 3, so fcntl is being called correctly.  But why does
> fcntl(F_GETFL) return 1 (== FD_CLOEXEC)?  This looks like a bug.

On 28/11/12 16:17, Nicolas Boulenguez wrote:
> -       int flags = fcntl(fd, F_GETFL);
> -       if (flags < 0 || fcntl(fd, F_SETFL, flags | FD_CLOEXEC))
> +       int flags = fcntl(fd, F_GETFD);
> +       if (flags < 0 || fcntl(fd, F_SETFD, flags | FD_CLOEXEC))

Of course!  How did we miss that?

The fcntl calls are getting/setting the wrong flags here and returning 1
(== O_WRONLY) rather than 1 (== FD_CLOEXEC).

This explains why it wasn't reproducible on Debian's own kfreebsd
(kernel) builds.  O_CLOEXEC is undefined in GNU/kFreeBSD's glibc and it
doesn't appear in the F_GETFL result.

But when running in a jail on upstream FreeBSD kernels, it must be
getting 0x00100001 (== O_WRONLY | O_CLOEXEC), and then it tries to
F_SETFL with a flag our glibc won't recognise.

Thanks a lot for this Nicolas!

Regards,
-- 
Steven Chamberlain
steven@pyro.eu.org


Reply to: