]> git.ipfire.org Git - thirdparty/tor.git/commit
If SOCK_CLOEXEC and friends fail, fall back to regular socket() calls
authorNick Mathewson <nickm@torproject.org>
Tue, 14 Feb 2012 15:34:06 +0000 (10:34 -0500)
committerNick Mathewson <nickm@torproject.org>
Tue, 14 Feb 2012 15:34:06 +0000 (10:34 -0500)
commit077b9f19a4a9486e5cd411a6fce0dec68fc2250c
tree4112a1319f731aaff04116515ae0a5e2e85bbf5e
parenta31fb42d2e5aed07748effc5ec765b7478a84bba
If SOCK_CLOEXEC and friends fail, fall back to regular socket() calls

Since 0.2.3.1-alpha, we've supported the Linux extensions to socket(),
open(), socketpair(), and accept() that enable us to create an fd and
make it close-on-exec with a single syscall.  This not only saves us a
syscall (big deal), but makes us less vulnerable to race conditions
where we open a socket and then exec before we can make it
close-on-exec.

But these extensions are not supported on all Linuxes: They were added
between 2.6.23 or so and 2.6.28 or so.  If you were to build your Tor
against a recent Linux's kernel headers, and then run it with a older
kernel, you would find yourselve unable to open sockets.  Ouch!

The solution here is that, when one of these syscalls fails with
EINVAL, we should try again in the portable way.  This adds an extra
syscall in the case where we built with new headers and are running
with old ones, but it will at least allow Tor to work.

Fixes bug 5112; bugfix on 0.2.3.1-alpha.
changes/bug5112 [new file with mode: 0644]
src/common/compat.c