Commit 379ecbfa by Pascal Obry Committed by Arnaud Charlet

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
parent 6ce0c3f5
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* * * *
* C Implementation File * * 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 * * 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- * * terms of the GNU General Public License as published by the Free Soft- *
...@@ -76,17 +76,15 @@ ...@@ -76,17 +76,15 @@
#include <process.h> #include <process.h>
void void
__gnat_kill (int pid, int sig) __gnat_kill (int pid, int sig, int close)
{ {
HANDLE process_handle;
if (sig == 9) if (sig == 9)
{ {
process_handle = OpenProcess (PROCESS_TERMINATE, FALSE, pid); if ((HANDLE)pid != NULL)
if (process_handle != NULL)
{ {
TerminateProcess (process_handle, 0); TerminateProcess ((HANDLE)pid, 0);
CloseHandle (process_handle); if (close)
CloseHandle ((HANDLE)pid);
} }
} }
} }
...@@ -94,17 +92,14 @@ __gnat_kill (int pid, int sig) ...@@ -94,17 +92,14 @@ __gnat_kill (int pid, int sig)
int int
__gnat_waitpid (int pid) __gnat_waitpid (int pid)
{ {
HANDLE process_handle;
DWORD exitcode = 1; DWORD exitcode = 1;
DWORD res; DWORD res;
process_handle = OpenProcess (PROCESS_QUERY_INFORMATION, FALSE, pid); if ((HANDLE)pid != NULL)
if (process_handle != NULL)
{ {
res = WaitForSingleObject (process_handle, INFINITE); res = WaitForSingleObject ((HANDLE)pid, INFINITE);
GetExitCodeProcess (process_handle, &exitcode); GetExitCodeProcess ((HANDLE)pid, &exitcode);
CloseHandle (process_handle); CloseHandle ((HANDLE)pid);
} }
return (int) exitcode; return (int) exitcode;
...@@ -337,7 +332,7 @@ typedef long fd_mask; ...@@ -337,7 +332,7 @@ typedef long fd_mask;
#endif /* !NO_FD_SET */ #endif /* !NO_FD_SET */
void void
__gnat_kill (int pid, int sig) __gnat_kill (int pid, int sig, int close)
{ {
kill (pid, sig); kill (pid, sig);
} }
...@@ -456,7 +451,7 @@ __gnat_expect_poll (int *fd, int num_fd, int timeout, int *is_set) ...@@ -456,7 +451,7 @@ __gnat_expect_poll (int *fd, int num_fd, int timeout, int *is_set)
#else #else
void void
__gnat_kill (int pid, int sig) __gnat_kill (int pid, int sig, int close)
{ {
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- 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 -- -- 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- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -89,8 +89,9 @@ package body GNAT.Expect is ...@@ -89,8 +89,9 @@ package body GNAT.Expect is
procedure Dup2 (Old_Fd, New_Fd : File_Descriptor); procedure Dup2 (Old_Fd, New_Fd : File_Descriptor);
pragma Import (C, Dup2); 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"); 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; function Create_Pipe (Pipe : access Pipe_Type) return Integer;
pragma Import (C, Create_Pipe, "__gnat_pipe"); pragma Import (C, Create_Pipe, "__gnat_pipe");
...@@ -221,7 +222,7 @@ package body GNAT.Expect is ...@@ -221,7 +222,7 @@ package body GNAT.Expect is
-- ??? Should have timeouts for different signals -- ??? Should have timeouts for different signals
Kill (Descriptor.Pid, 9); Kill (Descriptor.Pid, 9, 0);
GNAT.OS_Lib.Free (Descriptor.Buffer); GNAT.OS_Lib.Free (Descriptor.Buffer);
Descriptor.Buffer_Size := 0; Descriptor.Buffer_Size := 0;
...@@ -339,10 +340,11 @@ package body GNAT.Expect is ...@@ -339,10 +340,11 @@ package body GNAT.Expect is
return; return;
end if; 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 -- Note that Timeout is, from the caller's perspective, the maximum
-- time until a match, not the maximum time until some output is -- 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 if Timeout /= -1 then
Timeout_Tmp := Integer (Try_Until - Clock) * 1000; Timeout_Tmp := Integer (Try_Until - Clock) * 1000;
...@@ -1148,7 +1150,7 @@ package body GNAT.Expect is ...@@ -1148,7 +1150,7 @@ package body GNAT.Expect is
Signal : Integer) Signal : Integer)
is is
begin begin
Kill (Descriptor.Pid, Signal); Kill (Descriptor.Pid, Signal, 1);
-- ??? Need to check process status here -- ??? Need to check process status here
end Send_Signal; end Send_Signal;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment