summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorVincent Torri <vincent dot torri at gmail dot com>2015-09-27 10:08:26 +0200
committerCedric BAIL <cedric@osg.samsung.com>2015-10-12 17:21:59 -0700
commitdd45d7f7445b4ea0238a9ec229011016a8586706 (patch)
treeae5ba180ed13c5c2b1b06e088e8afbd19b15e0b7 /src/lib
parentf1a2c22dc35db870cd5eb16031fb2143100413eb (diff)
ecore_exe: make sure that ReadFile() will not hang
When child process exits, ReadFile() will hang if those pipes are maintained Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/ecore/ecore_exe_private.h2
-rw-r--r--src/lib/ecore/ecore_exe_win32.c24
2 files changed, 16 insertions, 10 deletions
diff --git a/src/lib/ecore/ecore_exe_private.h b/src/lib/ecore/ecore_exe_private.h
index f10c396109..66c6d4f65a 100644
--- a/src/lib/ecore/ecore_exe_private.h
+++ b/src/lib/ecore/ecore_exe_private.h
@@ -83,7 +83,6 @@ struct _Ecore_Exe_Data
83 struct 83 struct
84 { 84 {
85 HANDLE child_pipe; 85 HANDLE child_pipe;
86 HANDLE child_pipe_x;
87 HANDLE thread; 86 HANDLE thread;
88 void *data_buf; 87 void *data_buf;
89 DWORD data_size; 88 DWORD data_size;
@@ -100,7 +99,6 @@ struct _Ecore_Exe_Data
100 struct 99 struct
101 { 100 {
102 HANDLE child_pipe; 101 HANDLE child_pipe;
103 HANDLE child_pipe_x;
104 HANDLE thread; 102 HANDLE thread;
105 void *data_buf; 103 void *data_buf;
106 DWORD data_size; 104 DWORD data_size;
diff --git a/src/lib/ecore/ecore_exe_win32.c b/src/lib/ecore/ecore_exe_win32.c
index 24782e2dfa..eba7913fa2 100644
--- a/src/lib/ecore/ecore_exe_win32.c
+++ b/src/lib/ecore/ecore_exe_win32.c
@@ -389,6 +389,8 @@ _impl_ecore_exe_eo_base_finalize(Eo *obj, Ecore_Exe_Data *exe)
389 char exe_cmd_buf[1024]; 389 char exe_cmd_buf[1024];
390 SECURITY_ATTRIBUTES sa; 390 SECURITY_ATTRIBUTES sa;
391 STARTUPINFO si; 391 STARTUPINFO si;
392 HANDLE child_pipe_read;
393 HANDLE child_pipe_error;
392 PROCESS_INFORMATION pi; 394 PROCESS_INFORMATION pi;
393 Ecore_Exe_Event_Add *e; 395 Ecore_Exe_Event_Add *e;
394 Eina_Bool use_sh = EINA_FALSE; 396 Eina_Bool use_sh = EINA_FALSE;
@@ -446,7 +448,7 @@ _impl_ecore_exe_eo_base_finalize(Eo *obj, Ecore_Exe_Data *exe)
446 /* stdout pipe */ 448 /* stdout pipe */
447 if (exe->flags & ECORE_EXE_PIPE_READ) 449 if (exe->flags & ECORE_EXE_PIPE_READ)
448 { 450 {
449 if (!CreatePipe(&exe->pipe_read.child_pipe, &exe->pipe_read.child_pipe_x, &sa, 0)) 451 if (!CreatePipe(&exe->pipe_read.child_pipe, &child_pipe_read, &sa, 0))
450 goto error; 452 goto error;
451 if (!SetHandleInformation(exe->pipe_read.child_pipe, HANDLE_FLAG_INHERIT, 0)) 453 if (!SetHandleInformation(exe->pipe_read.child_pipe, HANDLE_FLAG_INHERIT, 0))
452 goto error; 454 goto error;
@@ -460,7 +462,7 @@ _impl_ecore_exe_eo_base_finalize(Eo *obj, Ecore_Exe_Data *exe)
460 /* stderr pipe */ 462 /* stderr pipe */
461 if (exe->flags & ECORE_EXE_PIPE_ERROR) 463 if (exe->flags & ECORE_EXE_PIPE_ERROR)
462 { 464 {
463 if (!CreatePipe(&exe->pipe_error.child_pipe, &exe->pipe_error.child_pipe_x, &sa, 0)) 465 if (!CreatePipe(&exe->pipe_error.child_pipe, &child_pipe_error, &sa, 0))
464 goto error; 466 goto error;
465 if (!SetHandleInformation(exe->pipe_error.child_pipe, HANDLE_FLAG_INHERIT, 0)) 467 if (!SetHandleInformation(exe->pipe_error.child_pipe, HANDLE_FLAG_INHERIT, 0))
466 goto error; 468 goto error;
@@ -486,9 +488,9 @@ _impl_ecore_exe_eo_base_finalize(Eo *obj, Ecore_Exe_Data *exe)
486 488
487 ZeroMemory(&si, sizeof(STARTUPINFO)); 489 ZeroMemory(&si, sizeof(STARTUPINFO));
488 si.cb = sizeof(STARTUPINFO); 490 si.cb = sizeof(STARTUPINFO);
489 si.hStdOutput = exe->pipe_read.child_pipe_x; 491 si.hStdOutput = child_pipe_read;
490 si.hStdInput = exe->pipe_write.child_pipe; 492 si.hStdInput = exe->pipe_write.child_pipe;
491 si.hStdError = exe->pipe_error.child_pipe_x; 493 si.hStdError = child_pipe_error;
492 si.dwFlags |= STARTF_USESTDHANDLES; 494 si.dwFlags |= STARTF_USESTDHANDLES;
493 495
494 DBG("CreateProcess: shell:%s child:%s", use_sh ? "yes" : "no", exe->cmd); 496 DBG("CreateProcess: shell:%s child:%s", use_sh ? "yes" : "no", exe->cmd);
@@ -499,6 +501,16 @@ _impl_ecore_exe_eo_base_finalize(Eo *obj, Ecore_Exe_Data *exe)
499 goto error; 501 goto error;
500 } 502 }
501 503
504 /*
505 * Close pipe handles (do not continue to modify the parent).
506 * We need to make sure that no handles to the write end of the
507 * output and error pipes are maintained in this process or else
508 * the pipe will not close when the child process exits and the
509 * ReadFile will hang.
510 */
511 CloseHandle(child_pipe_read);
512 CloseHandle(child_pipe_error);
513
502 /* be sure that the child process is running */ 514 /* be sure that the child process is running */
503 /* FIXME: This does not work if the child is an EFL-based app */ 515 /* FIXME: This does not work if the child is an EFL-based app */
504 /* if (WaitForInputIdle(pi.hProcess, INFINITE) == WAIT_FAILED) */ 516 /* if (WaitForInputIdle(pi.hProcess, INFINITE) == WAIT_FAILED) */
@@ -700,13 +712,9 @@ _impl_ecore_exe_eo_base_destructor(Eo *obj, Ecore_Exe_Data *exe)
700 _ecore_exe_threads_terminate(obj); 712 _ecore_exe_threads_terminate(obj);
701 if (exe->pipe_error.child_pipe) 713 if (exe->pipe_error.child_pipe)
702 CloseHandle(exe->pipe_error.child_pipe); 714 CloseHandle(exe->pipe_error.child_pipe);
703 if (exe->pipe_error.child_pipe_x)
704 CloseHandle(exe->pipe_error.child_pipe_x);
705 715
706 if (exe->pipe_read.child_pipe) 716 if (exe->pipe_read.child_pipe)
707 CloseHandle(exe->pipe_read.child_pipe); 717 CloseHandle(exe->pipe_read.child_pipe);
708 if (exe->pipe_read.child_pipe_x)
709 CloseHandle(exe->pipe_read.child_pipe_x);
710 718
711 if (exe->cmd) 719 if (exe->cmd)
712 free(exe->cmd); 720 free(exe->cmd);