Alexandre Julliard : kernel32: Close the stdio handles when creating a detached process.

Alexandre Julliard julliard at winehq.org
Mon Jan 14 09:33:29 CST 2008


Module: wine
Branch: master
Commit: 5a3132343d9c6f1b87f79034d80ef6595e4a1bbd
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=5a3132343d9c6f1b87f79034d80ef6595e4a1bbd

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Mon Jan 14 15:49:12 2008 +0100

kernel32: Close the stdio handles when creating a detached process.

---

 dlls/kernel32/process.c |   35 +++++++++++++++++++++++++++++++++--
 1 files changed, 33 insertions(+), 2 deletions(-)

diff --git a/dlls/kernel32/process.c b/dlls/kernel32/process.c
index 39e3665..7a25f39 100644
--- a/dlls/kernel32/process.c
+++ b/dlls/kernel32/process.c
@@ -1189,7 +1189,23 @@ static int fork_and_exec( const char *filename, const WCHAR *cmdline,
         char **envp = build_envp( env );
         close( fd[0] );
 
-        if (flags & (CREATE_NEW_PROCESS_GROUP | CREATE_NEW_CONSOLE | DETACHED_PROCESS)) setsid();
+        if (flags & (CREATE_NEW_PROCESS_GROUP | CREATE_NEW_CONSOLE | DETACHED_PROCESS))
+        {
+            int pid;
+            if (!(pid = fork()))
+            {
+                int fd = open( "/dev/null", O_RDWR );
+                setsid();
+                /* close stdin and stdout */
+                if (fd != -1)
+                {
+                    dup2( fd, 0 );
+                    dup2( fd, 1 );
+                    close( fd );
+                }
+            }
+            else if (pid != -1) _exit(0);  /* parent */
+        }
 
         /* Reset signals that we previously set to SIG_IGN */
         signal( SIGPIPE, SIG_DFL );
@@ -1410,7 +1426,22 @@ static BOOL create_process( HANDLE hFile, LPCWSTR filename, LPWSTR cmd_line, LPW
         char preloader_reserve[64], socket_env[64];
         char **argv = build_argv( cmd_line, 1 );
 
-        if (flags & (CREATE_NEW_PROCESS_GROUP | CREATE_NEW_CONSOLE | DETACHED_PROCESS)) setsid();
+        if (flags & (CREATE_NEW_PROCESS_GROUP | CREATE_NEW_CONSOLE | DETACHED_PROCESS))
+        {
+            if (!(pid = fork()))
+            {
+                int fd = open( "/dev/null", O_RDWR );
+                setsid();
+                /* close stdin and stdout */
+                if (fd != -1)
+                {
+                    dup2( fd, 0 );
+                    dup2( fd, 1 );
+                    close( fd );
+                }
+            }
+            else if (pid != -1) _exit(0);  /* parent */
+        }
 
         /* Reset signals that we previously set to SIG_IGN */
         signal( SIGPIPE, SIG_DFL );




More information about the wine-cvs mailing list