[Ada] Fix exit status of GNAT.Expect.Close call on running process
authorDmitriy Anisimkov <anisimko@adacore.com>
Wed, 15 Dec 2021 13:26:50 +0000 (19:26 +0600)
committerPierre-Marie de Rodat <derodat@adacore.com>
Fri, 7 Jan 2022 16:24:10 +0000 (16:24 +0000)
gcc/ada/

* expect.c (__gnat_waitpid): Use macros WIFEXITED, WEXITSTATUS,
WIFSIGNALED, WTERMSIG, WIFSTOPPED, WSTOPSIG to get exit status
or signal that caused the child process to terminate/stop.  Do
not process exit status in case of error in waitpid call.
* adaint.c (__gnat_kill): Use of GenerateConsoleCtrlEvent is
removed in Windows variant as it actually is not working and was
terminating the calling process.  Set signal number into exit
code parameter of TerminateProcess to work the same like in
Linux.

gcc/ada/adaint.c
gcc/ada/expect.c

index 6781728f45e2024b86a11c4cb52a68dbff946ae9..2db35283eac25fae1b410d4f0f3f8b96837cba05 100644 (file)
@@ -3562,18 +3562,8 @@ __gnat_kill (int pid, int sig, int close ATTRIBUTE_UNUSED)
   HANDLE h = OpenProcess (PROCESS_ALL_ACCESS, FALSE, pid);
   if (h == NULL)
     return;
-  if (sig == 9)
-    {
-      TerminateProcess (h, 1);
-    }
-  else if (sig == SIGINT)
-    GenerateConsoleCtrlEvent (CTRL_C_EVENT, pid);
-  else if (sig == SIGBREAK)
-    GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, pid);
-  /* ??? The last two alternatives don't really work. SIGBREAK requires setting
-     up process groups at start time which we don't do; treating SIGINT is just
-     not possible apparently. So we really only support signal 9. Fortunately
-     that's all we use in GNAT.Expect */
+
+  TerminateProcess (h, sig);
 
   CloseHandle (h);
 #elif defined (__vxworks)
index a92c465a473bacc5a33ca4567e728f19724d9547..86cbcba0e6450460cf3f45c4355ae62524ba8ae1 100644 (file)
@@ -345,8 +345,17 @@ __gnat_waitpid (int pid)
 {
   int status = 0;
 
-  waitpid (pid, &status, 0);
-  status = WEXITSTATUS (status);
+  if (waitpid (pid, &status, 0) == -1) {
+     return -1;
+  }
+
+  if WIFEXITED (status) {
+     status = WEXITSTATUS (status);
+  } else if WIFSIGNALED (status) {
+     status = WTERMSIG (status);
+  } else if WIFSTOPPED (status) {
+     status = WSTOPSIG (status);
+  }
 
   return status;
 }