Commit ffe7773c authored by Herbert Valerio Riedel's avatar Herbert Valerio Riedel 🕺
Browse files

Change exit code encoding of `waitForProcess` yet again

This changes the exit code encoding from `(128+signum)`
(as introduced via 54038240

) to

{{{#!hs
if coredump then 0x8000 else 0 .|. signum `shiftL` 8 .|. exitstatus
}}}

in order to address the `process`-package part of #7229
Signed-off-by: Herbert Valerio Riedel's avatarHerbert Valerio Riedel <hvr@gnu.org>
parent 0f1fe271
......@@ -320,16 +320,25 @@ runInteractiveProcess1 fun cmd = do
{- | Waits for the specified process to terminate, and returns its exit code.
GHC Note: in order to call @waitForProcess@ without blocking all the
other threads in the system, you must compile the program with
@-threaded@.
On Unix systems, if the process died as the result of a signal,
then the exit code returned is @ExitFailure (128 + signal)@ where
@signal@ is the signal number. The signal numbers are
platform-specific, so to test for a specific signal use the
constants provided by @System.Posix.Signals@ in the @unix@
package.
GHC Note: in order to call @waitForProcess@ without blocking all the
other threads in the system, you must compile the program with
@-threaded@.
(/Since: 1.2.0.0/) On Unix systems, if the process died as the result
of a signal, then the exit code returned is
@
'ExitFailure' ((if /coredump/ then 0x8000 else 0) .|. /signum/ `shiftL` 8)
@
where @/coredump/@ is @True@ if a core file was created and @/signum/@
is the signal number. The signal numbers are platform-specific, so to
test for a specific signal use the constants provided by
@System.Posix.Signals@ in the @unix@ package. This encoding avoids to
overlap with non-signal exit codes, as the exit codes reported for
normal (other than 'ExitSuccess') process termination are in the range
@1-255@.
-}
waitForProcess
:: ProcessHandle
......
......@@ -22,12 +22,18 @@
UNIX versions
------------------------------------------------------------------------- */
//
// If a process terminates with a signal, the exit status we return to
// via the System.Process API follows the Unix shell convention of
// (128 + signal).
//
#define TERMSIG_STATUS(r) ((r) | 0x80)
// If a process was terminated by a signal, the exit status we return
// via the System.Process API is (signum << 8), and if a core-file has
// been generated (and reported by the OS) the 16th bit (i.e. 0x8000)
// is additionally set; this encoding avoids collision with normal
// process termination status codes, as according to
// http://pubs.opengroup.org/onlinepubs/9699919799/functions/wait.html
// WEXITSTATUS(s) returns an 8-bit value. See also #7229.
#if defined(WCOREDUMP)
#define TERMSIG_EXITSTATUS(s) ((WCOREDUMP(s) ? 0x8000 : 0) | (WTERMSIG(s) << 8))
#else
#define TERMSIG_EXITSTATUS(s) (WTERMSIG(s) << 8)
#endif
static long max_fd = 0;
......@@ -342,7 +348,7 @@ getProcessExitCode (ProcHandle handle, int *pExitCode)
else
if (WIFSIGNALED(wstat))
{
*pExitCode = TERMSIG_STATUS(WTERMSIG(wstat));
*pExitCode = TERMSIG_EXITSTATUS(wstat);
return 1;
}
else
......@@ -378,7 +384,7 @@ int waitForProcess (ProcHandle handle, int *pret)
else {
if (WIFSIGNALED(wstat))
{
*pret = TERMSIG_STATUS(WTERMSIG(wstat));
*pret = TERMSIG_EXITSTATUS(wstat);
return 0;
}
else
......
......@@ -4,7 +4,8 @@
* Remove NHC specific code
* Add support for `base-4.7.0.0`
* Improve `showCommandForUser` to reduce redundant quoting
* Use `ExitFailure (128+signal)` on Unix when a proc terminates due to a signal
* Use `ExitFailure (shiftL signum 8)` on Unix when a proc is terminated due to a signal;
sets also `bit 15` if a core file was generated.
* Deprecate `module System.Cmd`
* On non-Windows, the child thread now comunicates any errors back
to the parent thread via pipes.
......
ExitFailure 129
Just (ExitFailure 129)
Just (ExitFailure 129)
ExitFailure 256
Just (ExitFailure 256)
Just (ExitFailure 256)
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