Re: [PATCH] open: introduce O_NOSTD

From: Florian Weimer
Date: Fri Aug 28 2009 - 08:53:10 EST


* Eric Blake:

> Your version fails to clear the cloexec bit of the final fd if the
> original caller didn't request O_CLOEXEC.

Okay, but you can fix that in a race-free manner (but I thought that
this was implied by open_safer).

> If the caller requested O_CLOEXEC, then your version takes 3, 5, or
> 7 syscalls depending on how many std fds were closed, while my
> version takes 3 syscalls regardless of how many std fds were closed.

I really don't see a way around that. You can't pick a descriptor and
hope that it's unused.

> Also, your suggestion has a definite race in that you are calling
> open() multiple times rather than cloning an existing fd after the
> first open(), such that another process could alter which file is
> visited between your first and last open().

Sure, but this is an unobservable differen.ce

--
Florian Weimer <fweimer@xxxxxx>
BFK edv-consulting GmbH http://www.bfk.de/
Kriegsstraße 100 tel: +49-721-96201-1
D-76133 Karlsruhe fax: +49-721-96201-99
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/