From 0273bbb409468d108c9f1c316c7d1e9f554c7275 Mon Sep 17 00:00:00 2001 From: Pascal Obry Date: Wed, 15 Feb 2006 10:39:28 +0100 Subject: [PATCH] expect.c (__gnat_expect_portable_execvp): New implementation. 2006-02-13 Pascal Obry * expect.c (__gnat_expect_portable_execvp): New implementation. The previous implementation was using the C runtime spawnve routine but the corresponding wait was using directly the Win32 API. This was causing some times a lock when waiting for an event using WaitForSingleObject in __gnat_waitpid. This new implementation uses the Win32 CreateProcess routine. Avoiding mixing C runtime and Win32 API fixes this problem. From-SVN: r111066 --- gcc/ada/expect.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/gcc/ada/expect.c b/gcc/ada/expect.c index dd03b1c..6d2cf86 100644 --- a/gcc/ada/expect.c +++ b/gcc/ada/expect.c @@ -114,7 +114,61 @@ __gnat_expect_fork (void) void __gnat_expect_portable_execvp (int *pid, char *cmd, char *argv[]) { - *pid = (int) spawnve (_P_NOWAIT, cmd, argv, NULL); + BOOL result; + STARTUPINFO SI; + PROCESS_INFORMATION PI; + SECURITY_ATTRIBUTES SA; + int csize = 1; + char *full_command; + int k; + + /* compute the total command line length. */ + k = 0; + while (argv[k]) + { + csize += strlen (argv[k]) + 1; + k++; + } + + full_command = (char *) malloc (csize); + full_command[0] = '\0'; + + /* Startup info. */ + SI.cb = sizeof (STARTUPINFO); + SI.lpReserved = NULL; + SI.lpReserved2 = NULL; + SI.lpDesktop = NULL; + SI.cbReserved2 = 0; + SI.lpTitle = NULL; + SI.dwFlags = 0; + SI.wShowWindow = SW_HIDE; + + /* Security attributes. */ + SA.nLength = sizeof (SECURITY_ATTRIBUTES); + SA.bInheritHandle = TRUE; + SA.lpSecurityDescriptor = NULL; + + k = 0; + while (argv[k]) + { + strcat (full_command, argv[k]); + strcat (full_command, " "); + k++; + } + + result = CreateProcess + (NULL, (char *) full_command, &SA, NULL, TRUE, + GetPriorityClass (GetCurrentProcess()), NULL, NULL, &SI, &PI); + + free (full_command); + + if (result == TRUE) + { + CloseHandle (PI.hThread); + *pid = (int) PI.hProcess; + } + else + *pid = -1; } int -- 2.7.4