diff options
author | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-02-15 09:39:28 +0000 |
---|---|---|
committer | charlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-02-15 09:39:28 +0000 |
commit | 0412a621df1b3a95e656308110b56ba0eb91a03e (patch) | |
tree | 38f6bb932b194a9cf72a72ab305f4c9b4bbca977 /gcc/ada/expect.c | |
parent | c5d8a3bc43511a052db85e8ade2b4fe1f5351dd0 (diff) | |
download | gcc-0412a621df1b3a95e656308110b56ba0eb91a03e.tar.gz |
2006-02-13 Pascal Obry <obry@adacore.com>
* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@111066 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/ada/expect.c')
-rw-r--r-- | gcc/ada/expect.c | 56 |
1 files changed, 55 insertions, 1 deletions
diff --git a/gcc/ada/expect.c b/gcc/ada/expect.c index dd03b1ca1f8..6d2cf86e322 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 |