expect.c (__gnat_kill): Fix implementation...
2005-11-14 Pascal Obry <obry@adacore.com> * expect.c (__gnat_kill) [Win32]: Fix implementation, the pid returned by spawnve is a process handle, no need to convert. Add a parameter close to control wether the process handle must be closed. (__gnat_waitpid): Fix implementation, the pid returned by spawnve is a process handle, not need to convert. (__gnat_kill) [*]: Add dummy parameter close to match the Win32 spec. * g-expect.adb: (Kill): Document the new close parameter. (Close): Do not release the process handle in the kill there as waitpid() is using it. (Send_Signal): Release the process handle. From-SVN: r106974
This commit is contained in:
parent
6ce0c3f5ed
commit
379ecbfacf
|
@ -6,7 +6,7 @@
|
|||
* *
|
||||
* C Implementation File *
|
||||
* *
|
||||
* Copyright (C) 2001-2005 Ada Core Technologies, Inc. *
|
||||
* Copyright (C) 2001-2005, AdaCore *
|
||||
* *
|
||||
* GNAT is free software; you can redistribute it and/or modify it under *
|
||||
* terms of the GNU General Public License as published by the Free Soft- *
|
||||
|
@ -76,17 +76,15 @@
|
|||
#include <process.h>
|
||||
|
||||
void
|
||||
__gnat_kill (int pid, int sig)
|
||||
__gnat_kill (int pid, int sig, int close)
|
||||
{
|
||||
HANDLE process_handle;
|
||||
|
||||
if (sig == 9)
|
||||
{
|
||||
process_handle = OpenProcess (PROCESS_TERMINATE, FALSE, pid);
|
||||
if (process_handle != NULL)
|
||||
if ((HANDLE)pid != NULL)
|
||||
{
|
||||
TerminateProcess (process_handle, 0);
|
||||
CloseHandle (process_handle);
|
||||
TerminateProcess ((HANDLE)pid, 0);
|
||||
if (close)
|
||||
CloseHandle ((HANDLE)pid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -94,17 +92,14 @@ __gnat_kill (int pid, int sig)
|
|||
int
|
||||
__gnat_waitpid (int pid)
|
||||
{
|
||||
HANDLE process_handle;
|
||||
DWORD exitcode = 1;
|
||||
DWORD res;
|
||||
|
||||
process_handle = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, pid);
|
||||
|
||||
if (process_handle != NULL)
|
||||
if ((HANDLE)pid != NULL)
|
||||
{
|
||||
res = WaitForSingleObject (process_handle, INFINITE);
|
||||
GetExitCodeProcess (process_handle, &exitcode);
|
||||
CloseHandle (process_handle);
|
||||
res = WaitForSingleObject ((HANDLE)pid, INFINITE);
|
||||
GetExitCodeProcess ((HANDLE)pid, &exitcode);
|
||||
CloseHandle ((HANDLE)pid);
|
||||
}
|
||||
|
||||
return (int) exitcode;
|
||||
|
@ -337,7 +332,7 @@ typedef long fd_mask;
|
|||
#endif /* !NO_FD_SET */
|
||||
|
||||
void
|
||||
__gnat_kill (int pid, int sig)
|
||||
__gnat_kill (int pid, int sig, int close)
|
||||
{
|
||||
kill (pid, sig);
|
||||
}
|
||||
|
@ -456,7 +451,7 @@ __gnat_expect_poll (int *fd, int num_fd, int timeout, int *is_set)
|
|||
#else
|
||||
|
||||
void
|
||||
__gnat_kill (int pid, int sig)
|
||||
__gnat_kill (int pid, int sig, int close)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
-- --
|
||||
-- B o d y --
|
||||
-- --
|
||||
-- Copyright (C) 2000-2005 Ada Core Technologies, Inc. --
|
||||
-- Copyright (C) 2000-2005, AdaCore --
|
||||
-- --
|
||||
-- GNAT is free software; you can redistribute it and/or modify it under --
|
||||
-- terms of the GNU General Public License as published by the Free Soft- --
|
||||
|
@ -89,8 +89,9 @@ package body GNAT.Expect is
|
|||
procedure Dup2 (Old_Fd, New_Fd : File_Descriptor);
|
||||
pragma Import (C, Dup2);
|
||||
|
||||
procedure Kill (Pid : Process_Id; Sig_Num : Integer);
|
||||
procedure Kill (Pid : Process_Id; Sig_Num : Integer; Close : Integer);
|
||||
pragma Import (C, Kill, "__gnat_kill");
|
||||
-- if Close is set to 1 all OS resources used by the Pid must be freed
|
||||
|
||||
function Create_Pipe (Pipe : access Pipe_Type) return Integer;
|
||||
pragma Import (C, Create_Pipe, "__gnat_pipe");
|
||||
|
@ -221,7 +222,7 @@ package body GNAT.Expect is
|
|||
|
||||
-- ??? Should have timeouts for different signals
|
||||
|
||||
Kill (Descriptor.Pid, 9);
|
||||
Kill (Descriptor.Pid, 9, 0);
|
||||
|
||||
GNAT.OS_Lib.Free (Descriptor.Buffer);
|
||||
Descriptor.Buffer_Size := 0;
|
||||
|
@ -339,10 +340,11 @@ package body GNAT.Expect is
|
|||
return;
|
||||
end if;
|
||||
|
||||
-- Calculate the timeout for the next turn.
|
||||
-- Calculate the timeout for the next turn
|
||||
|
||||
-- Note that Timeout is, from the caller's perspective, the maximum
|
||||
-- time until a match, not the maximum time until some output is
|
||||
-- read, and thus can not be reused as is for Expect_Internal.
|
||||
-- read, and thus cannot be reused as is for Expect_Internal.
|
||||
|
||||
if Timeout /= -1 then
|
||||
Timeout_Tmp := Integer (Try_Until - Clock) * 1000;
|
||||
|
@ -1148,7 +1150,7 @@ package body GNAT.Expect is
|
|||
Signal : Integer)
|
||||
is
|
||||
begin
|
||||
Kill (Descriptor.Pid, Signal);
|
||||
Kill (Descriptor.Pid, Signal, 1);
|
||||
-- ??? Need to check process status here
|
||||
end Send_Signal;
|
||||
|
||||
|
|
Loading…
Reference in New Issue