Hi all,

filedescriptors created by the dns subsystem do not have the close on
exec flag set. The attached patch fixes that. Here is also a link to the
fix in my github mirror:
http://github.com/schmir/libevent/commit/d64a0d407ca931062abe6d4405159632d792faaf

Patch is against the patch-1.4 branch.

Cheers,
- Ralf

>From d64a0d407ca931062abe6d4405159632d792faaf Mon Sep 17 00:00:00 2001
From: Ralf Schmitt <r...@systemexit.de>
Date: Wed, 18 Aug 2010 11:51:30 +0200
Subject: [PATCH] set close-on-exec bit for filedescriptors created by dns subsystem


diff --git a/evdns.c b/evdns.c
index d0e233f..fb3227c 100644
--- a/evdns.c
+++ b/evdns.c
@@ -158,6 +158,15 @@ typedef unsigned int uint;
 
 #define CLASS_INET     EVDNS_CLASS_INET
 
+#ifdef HAVE_SETFD
+#define FD_CLOSEONEXEC(x) do { \
+	if (fcntl(x, F_SETFD, 1) == -1) \
+		event_warn("fcntl(%d, F_SETFD)", x); \
+} while (0)
+#else
+#define FD_CLOSEONEXEC(x)
+#endif
+
 struct request {
 	u8 *request;  /* the dns packet data */
 	unsigned int request_len;
@@ -2132,7 +2141,8 @@ _evdns_nameserver_add_impl(unsigned long int address, int port) {
 
 	ns->socket = socket(PF_INET, SOCK_DGRAM, 0);
 	if (ns->socket < 0) { err = 1; goto out1; }
-        evutil_make_socket_nonblocking(ns->socket);
+	FD_CLOSEONEXEC(ns->socket);
+	evutil_make_socket_nonblocking(ns->socket);
 
 	ns->address = address;
 	ns->port = htons(port);
-- 
1.7.2.1

_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://lists.monkey.org:8080/listinfo/libevent-users

Reply via email to