[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [Libevent-users] [PATCH] Make evutil_read_file() close-on-exec safe.
On Sat, Feb 11, 2012 at 10:34 AM, Ross Lagerwall
<rosslagerwall@xxxxxxxxx> wrote:
> In a multi-process/threaded environment, ev_util_read_file()
> could leak fds to child processes when not using O_CLOEXEC/FD_CLOEXEC.
Hm. I'm not sure I trust "#ifdef O_CLOEXEC" as a test for whether
open() supports O_CLOEXEC. Generally, I'd prefer a solution that
falls back gracefully if Libevent is built with headers from a newer
libc/kernel and then run on an older kernel. (This is a real concern:
it seems to happen to RHEL/Centos users pretty often.)
Unfortunately, it seems we can't just do a pattern of
if ((fd = open(path, flags|O_CLOEXEC)) == -1) {
fd = open(path, flags);
if (fd == -1) return -1;
fcntl(fd,...)
}
because (if my tests are right) at least some implementations of
open() ignore unrecognized flags.
So given that, maybe the solution you suggest is the best we can do?
Additionally, I see 3 other open()s: two in arc4random.c and one in
devpoll.c. Maybe this means we want an evutil_* wrapper function to
set CLOEXEC on fds.
thoughts?
--
Nick
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users in the body.