[2/3] testbot/testagentd: Child processes should not inherit the server's sockets (and other file descriptors).

Francois Gouget fgouget at codeweavers.com
Sat Apr 12 10:45:11 CDT 2014


---

Otherwise they may keep the sockets open until they exit.

 testbot/src/testagentd/platform_windows.c |  2 +-
 testbot/src/testagentd/testagentd.c       | 13 +++++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/testbot/src/testagentd/platform_windows.c b/testbot/src/testagentd/platform_windows.c
index 9dda56a..89e435d 100644
--- a/testbot/src/testagentd/platform_windows.c
+++ b/testbot/src/testagentd/platform_windows.c
@@ -126,7 +126,7 @@ uint64_t platform_run(char** argv, uint32_t flags, char** redirects)
     si.hStdInput = fhs[0];
     si.hStdOutput = fhs[1];
     si.hStdError = fhs[2];
-    if (!CreateProcessA(NULL, cmdline, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS,
+    if (!CreateProcessA(NULL, cmdline, NULL, NULL, FALSE, NORMAL_PRIORITY_CLASS,
                         NULL, NULL, &si, &pi))
     {
         set_status(ST_ERROR, "could not run '%s': %lu", cmdline, GetLastError());
diff --git a/testbot/src/testagentd/testagentd.c b/testbot/src/testagentd/testagentd.c
index 42583cf..f5b0280 100644
--- a/testbot/src/testagentd/testagentd.c
+++ b/testbot/src/testagentd/testagentd.c
@@ -1067,7 +1067,7 @@ int main(int argc, char** argv)
     char* opt_port = NULL;
     char* opt_srchost = NULL;
     struct addrinfo *addresses, *addrp;
-    int rc, addrlen;
+    int rc, sockflags, addrlen;
     int opt_usage = 0;
     SOCKET master;
     int on = 1;
@@ -1171,6 +1171,11 @@ int main(int argc, char** argv)
     }
 
     /* Bind to the host in a protocol neutral way */
+#ifdef SOCK_CLOEXEC
+    sockflags = SOCK_CLOEXEC;
+#else
+    sockflags = 0;
+#endif
     rc = ta_getaddrinfo(NULL, opt_port, &addresses);
     if (rc)
     {
@@ -1182,7 +1187,8 @@ int main(int argc, char** argv)
         debug("trying family=%d\n", addrp->ai_family);
         if (addrp->ai_family != PF_INET)
             continue;
-        master = socket(addrp->ai_family, addrp->ai_socktype, addrp->ai_protocol);
+        master = socket(addrp->ai_family, addrp->ai_socktype | sockflags,
+                        addrp->ai_protocol);
         if (master < 0)
             continue;
         setsockopt(master, SOL_SOCKET, SO_REUSEADDR, (void*)&on, sizeof(on));
@@ -1211,6 +1217,9 @@ int main(int argc, char** argv)
         SOCKET client;
         debug("Waiting in accept()\n");
         client = accept(master, NULL, NULL);
+#ifdef O_CLOEXEC
+        fcntl(client, F_SETFL, fcntl(client, F_GETFL, 0) | O_CLOEXEC);
+#endif
         if (client >= 0)
         {
             if (is_host_allowed(client, opt_srchost, addrlen))
-- 
1.9.1




More information about the wine-patches mailing list