From 0a6e3ce1fe7706e2ff265b1b8bea2789167a8a11 Mon Sep 17 00:00:00 2001 From: grothoff Date: Mon, 9 Jul 2012 11:48:43 +0000 Subject: -reverting SVN 22558 (new insights...) git-svn-id: https://gnunet.org/svn/gnunet@22568 140774ce-b5e7-0310-ab8b-a85725594a96 --- src/util/os_priority.c | 58 ++++++++++++-------------------------------------- 1 file changed, 14 insertions(+), 44 deletions(-) (limited to 'src/util/os_priority.c') diff --git a/src/util/os_priority.c b/src/util/os_priority.c index ca60f857e1..c9174dee99 100644 --- a/src/util/os_priority.c +++ b/src/util/os_priority.c @@ -961,10 +961,6 @@ start_process (int pipe_control, long lRet; HANDLE stdin_handle; HANDLE stdout_handle; - BOOL bresult; - DWORD error_code; - HANDLE stdih, stdoh, stdeh; - DWORD stdif, stdof, stdef; if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary (filename)) return NULL; /* not executable */ @@ -1087,7 +1083,8 @@ start_process (int pipe_control, memset (&start, 0, sizeof (start)); start.cb = sizeof (start); - start.dwFlags |= STARTF_USESTDHANDLES; + if ((pipe_stdin != NULL) || (pipe_stdout != NULL)) + start.dwFlags |= STARTF_USESTDHANDLES; if (pipe_stdin != NULL) { @@ -1182,54 +1179,24 @@ start_process (int pipe_control, return NULL; } - /* Prevents our std handles from being inherited by the child */ - stdih = GetStdHandle (STD_INPUT_HANDLE); - stdoh = GetStdHandle (STD_OUTPUT_HANDLE); - stdeh = GetStdHandle (STD_ERROR_HANDLE); - if (stdih) + if (!CreateProcessW (wpath, wcmd, NULL, NULL, TRUE, + DETACHED_PROCESS | CREATE_SUSPENDED, env_block, NULL, &start, &proc)) { - GetHandleInformation (stdih, &stdif); - SetHandleInformation (stdih, HANDLE_FLAG_INHERIT, 0); - } - if (stdoh) - { - GetHandleInformation (stdoh, &stdof); - SetHandleInformation (stdoh, HANDLE_FLAG_INHERIT, 0); - } - if (stdeh) - { - GetHandleInformation (stdeh, &stdef); - SetHandleInformation (stdeh, HANDLE_FLAG_INHERIT, 0); - } - - bresult = CreateProcessW (wpath, wcmd, NULL, NULL, TRUE, - DETACHED_PROCESS | CREATE_SUSPENDED, env_block, NULL, &start, &proc); - error_code = GetLastError (); - - if (stdih) - SetHandleInformation (stdih, stdif, stdif); - if (stdoh) - SetHandleInformation (stdoh, stdof, stdof); - if (stdeh) - SetHandleInformation (stdeh, stdef, stdef); - - GNUNET_free (env_block); - GNUNET_free (cmd); - free (wpath); - free (wcmd); - - if (!bresult) - { - SetErrnoFromWinError (error_code); + SetErrnoFromWinError (GetLastError ()); LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "CreateProcess"); - if (NULL != control_pipe) GNUNET_DISK_file_close (control_pipe); if (NULL != lsocks) GNUNET_DISK_pipe_close (lsocks_pipe); + GNUNET_free (env_block); + GNUNET_free (cmd); + free (wpath); + free (wcmd); return NULL; } + GNUNET_free (env_block); + gnunet_proc = GNUNET_malloc (sizeof (struct GNUNET_OS_Process)); gnunet_proc->pid = proc.dwProcessId; gnunet_proc->handle = proc.hProcess; @@ -1239,6 +1206,9 @@ start_process (int pipe_control, ResumeThread (proc.hThread); CloseHandle (proc.hThread); + GNUNET_free (cmd); + free (wpath); + free (wcmd); if (lsocks == NULL || lsocks[0] == INVALID_SOCKET) return gnunet_proc; -- cgit v1.2.3-18-g5258