[commit: packages/process] master: Change the unix ExitCode encoding again! Now simply -signum (3ebbe13)

git at git.haskell.org git at git.haskell.org
Thu Nov 14 17:41:53 UTC 2013


Repository : ssh://git@git.haskell.org/process

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/3ebbe13a82b4f4beb382bb8a07f98e57a8354a85/process

>---------------------------------------------------------------

commit 3ebbe13a82b4f4beb382bb8a07f98e57a8354a85
Author: Duncan Coutts <duncan at well-typed.com>
Date:   Thu Nov 14 13:59:57 2013 +0000

    Change the unix ExitCode encoding again! Now simply -signum
    
    So rather than a bitfield encoding, covering normal exit codes, signals
    and core dumps, we now simply use negative numbers for signal exit
    codes. We thus do not report core dumps by this mechanism.
    
    This encoding is a lot simpler to explain and use. It also happens to be
    the same encoding as Python's subprocess package uses.
    
    Anyone who cares about core dumps can still use the unix package.


>---------------------------------------------------------------

3ebbe13a82b4f4beb382bb8a07f98e57a8354a85
 System/Process.hs       |   20 ++++++--------------
 cbits/runProcess.c      |   14 +++-----------
 changelog               |    4 ++--
 tests/process009.stdout |    6 +++---
 4 files changed, 14 insertions(+), 30 deletions(-)

diff --git a/System/Process.hs b/System/Process.hs
index 0eb8aeb..b507c62 100644
--- a/System/Process.hs
+++ b/System/Process.hs
@@ -324,20 +324,12 @@ GHC Note: in order to call @waitForProcess@ without blocking all the
 other threads in the system, you must compile the program with
 @-threaded at .
 
-(/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
- at 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
- at 1-255@.
+(/Since: 1.2.0.0/) On Unix systems, a negative value @'ExitFailure' -/signum/@
+indicates that the child was terminated by signal @/signum/@.
+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.
+Note: core dumps are not reported, use @System.Posix.Process@ if you need this
+detail.
 
 -}
 waitForProcess
diff --git a/cbits/runProcess.c b/cbits/runProcess.c
index 796b697..2db88f5 100644
--- a/cbits/runProcess.c
+++ b/cbits/runProcess.c
@@ -23,17 +23,9 @@
    ------------------------------------------------------------------------- */
 
 // 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
+// via the System.Process API is (-signum). This encoding avoids collision with
+// normal process termination status codes. See also #7229.
+#define TERMSIG_EXITSTATUS(s) (-(WTERMSIG(s)))
 
 static long max_fd = 0;
 
diff --git a/changelog b/changelog
index dbe7ef2..542b995 100644
--- a/changelog
+++ b/changelog
@@ -4,8 +4,8 @@
         * Remove NHC specific code
         * Add support for `base-4.7.0.0`
         * Improve `showCommandForUser` to reduce redundant quoting
-        * 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.
+        * Use `ExitFailure (-signum)` on Unix when a proc is terminated due to
+          a signal.
         * Deprecate `module System.Cmd`
         * On non-Windows, the child thread now comunicates any errors back
         to the parent thread via pipes.
diff --git a/tests/process009.stdout b/tests/process009.stdout
index b7c54b9..751a73a 100644
--- a/tests/process009.stdout
+++ b/tests/process009.stdout
@@ -1,3 +1,3 @@
-ExitFailure 256
-Just (ExitFailure 256)
-Just (ExitFailure 256)
+ExitFailure (-1)
+Just (ExitFailure (-1))
+Just (ExitFailure (-1))



More information about the ghc-commits mailing list