|
@@ -155,19 +155,18 @@ sock_drain(tor_socket_t fd)
|
|
|
/** Allocate a new set of alert sockets, and set the appropriate function
|
|
|
* pointers, in <b>socks_out</b>. */
|
|
|
int
|
|
|
-alert_sockets_create(alert_sockets_t *socks_out)
|
|
|
+alert_sockets_create(alert_sockets_t *socks_out, uint32_t flags)
|
|
|
{
|
|
|
- tor_socket_t socks[2];
|
|
|
+ tor_socket_t socks[2] = { TOR_INVALID_SOCKET, TOR_INVALID_SOCKET };
|
|
|
|
|
|
#ifdef HAVE_EVENTFD
|
|
|
/* First, we try the Linux eventfd() syscall. This gives a 64-bit counter
|
|
|
* associated with a single file descriptor. */
|
|
|
#if defined(EFD_CLOEXEC) && defined(EFD_NONBLOCK)
|
|
|
- socks[0] = eventfd(0, EFD_CLOEXEC|EFD_NONBLOCK);
|
|
|
-#else
|
|
|
- socks[0] = -1;
|
|
|
+ if (!(flags & ASOCKS_NOEVENTFD2))
|
|
|
+ socks[0] = eventfd(0, EFD_CLOEXEC|EFD_NONBLOCK);
|
|
|
#endif
|
|
|
- if (socks[0] < 0) {
|
|
|
+ if (socks[0] < 0 && !(flags & ASOCKS_NOEVENTFD)) {
|
|
|
socks[0] = eventfd(0,0);
|
|
|
if (socks[0] >= 0) {
|
|
|
if (fcntl(socks[0], F_SETFD, FD_CLOEXEC) < 0 ||
|
|
@@ -188,7 +187,8 @@ alert_sockets_create(alert_sockets_t *socks_out)
|
|
|
#ifdef HAVE_PIPE2
|
|
|
/* Now we're going to try pipes. First type the pipe2() syscall, if we
|
|
|
* have it, so we can save some calls... */
|
|
|
- if (pipe2(socks, O_NONBLOCK|O_CLOEXEC) == 0) {
|
|
|
+ if (!(flags & ASOCKS_NOPIPE2) &&
|
|
|
+ pipe2(socks, O_NONBLOCK|O_CLOEXEC) == 0) {
|
|
|
socks_out->read_fd = socks[0];
|
|
|
socks_out->write_fd = socks[1];
|
|
|
socks_out->alert_fn = pipe_alert;
|
|
@@ -200,7 +200,8 @@ alert_sockets_create(alert_sockets_t *socks_out)
|
|
|
#ifdef HAVE_PIPE
|
|
|
/* Now try the regular pipe() syscall. Pipes have a bit lower overhead than
|
|
|
* socketpairs, fwict. */
|
|
|
- if (pipe(socks) == 0) {
|
|
|
+ if (!(flags & ASOCKS_NOPIPE) &&
|
|
|
+ pipe(socks) == 0) {
|
|
|
if (fcntl(socks[0], F_SETFD, FD_CLOEXEC) < 0 ||
|
|
|
fcntl(socks[1], F_SETFD, FD_CLOEXEC) < 0 ||
|
|
|
set_socket_nonblocking(socks[0]) < 0 ||
|
|
@@ -218,7 +219,8 @@ alert_sockets_create(alert_sockets_t *socks_out)
|
|
|
#endif
|
|
|
|
|
|
/* If nothing else worked, fall back on socketpair(). */
|
|
|
- if (tor_socketpair(AF_UNIX, SOCK_STREAM, 0, socks) == 0) {
|
|
|
+ if (!(flags & ASOCKS_NOSOCKETPAIR) &&
|
|
|
+ tor_socketpair(AF_UNIX, SOCK_STREAM, 0, socks) == 0) {
|
|
|
if (set_socket_nonblocking(socks[0]) < 0 ||
|
|
|
set_socket_nonblocking(socks[1])) {
|
|
|
tor_close_socket(socks[0]);
|