Skip to content

Commit

Permalink
Give an explicit message when SIGSEGV happens.
Browse files Browse the repository at this point in the history
Fixes haskell#767.

Signed-off-by: Edward Z. Yang <[email protected]>
  • Loading branch information
ezyang committed Aug 24, 2016
1 parent 6cca0e7 commit b45df92
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cabal-install/Distribution/Client/ProjectBuilding.hs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,8 @@ rebuildTargets verbosity
InstallPlan.execute jobControl keepGoing
(BuildFailure Nothing . DependentFailed . packageId)
installPlan $ \pkg ->
handle (return . Left) $ fmap Right $ --TODO: review exception handling
--TODO: review exception handling
handle (\(e :: BuildFailure) -> return (Left e)) $ fmap Right $

let uid = installedUnitId pkg
Just pkgBuildStatus = Map.lookup uid pkgsBuildStatus in
Expand Down
29 changes: 26 additions & 3 deletions cabal-install/Distribution/Client/ProjectOrchestration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ import Data.Either
import Control.Exception (Exception(..))
import System.Exit (ExitCode(..), exitFailure)
#ifdef MIN_VERSION_unix
import System.Posix.Signals (sigKILL)
import System.Posix.Signals (sigKILL, sigSEGV)
#endif


Expand Down Expand Up @@ -586,11 +586,14 @@ reportBuildFailures verbosity plan buildOutcomes
| otherwise
= False

-- NB: if the Setup script segfaulted or was interrupted,
-- we should give more detailed information. So only
-- assume that exit code 1 is "pedestrian failure."
isFailureSelfExplanatory (BuildFailed e)
| Just (ExitFailure _) <- fromException e = True
| Just (ExitFailure 1) <- fromException e = True

isFailureSelfExplanatory (ConfigureFailed e)
| Just (ExitFailure _) <- fromException e = True
| Just (ExitFailure 1) <- fromException e = True

isFailureSelfExplanatory _ = False

Expand Down Expand Up @@ -651,7 +654,27 @@ reportBuildFailures verbosity plan buildOutcomes
Just (ExitFailure 1) -> ""

#ifdef MIN_VERSION_unix
-- Note [Positive "signal" exit code]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- What's the business with the test for negative and positive
-- signal values? The API for process specifies that if the
-- process died due to a signal, it returns a *negative* exit
-- code. So that's the negative test.
--
-- What about the positive test? Well, when we find out that
-- a process died due to a signal, we ourselves exit with that
-- exit code. However, we don't "kill ourselves" with the
-- signal; we just exit with the same code as the signal: thus
-- the caller sees a *positive* exit code. So that's what
-- happens when we get a positive exit code.
Just (ExitFailure n)
| -n == fromIntegral sigSEGV ->
" The build process segfaulted (i.e. SIGSEGV)."

| n == fromIntegral sigSEGV ->
" The build process terminated with exit code " ++ show n
++ " which may be because some part of it segfaulted. (i.e. SIGSEGV)."

| -n == fromIntegral sigKILL ->
" The build process was killed (i.e. SIGKILL). " ++ explanation

Expand Down
4 changes: 4 additions & 0 deletions cabal-install/cabal-install.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ Extra-Source-Files:
tests/IntegrationTests/custom/plain/A.hs
tests/IntegrationTests/custom/plain/Setup.hs
tests/IntegrationTests/custom/plain/plain.cabal
tests/IntegrationTests/custom/segfault.sh
tests/IntegrationTests/custom/segfault/Setup.hs
tests/IntegrationTests/custom/segfault/cabal.project
tests/IntegrationTests/custom/segfault/plain.cabal
tests/IntegrationTests/exec/Foo.hs
tests/IntegrationTests/exec/My.hs
tests/IntegrationTests/exec/adds_sandbox_bin_directory_to_path.out
Expand Down
10 changes: 10 additions & 0 deletions cabal-install/tests/IntegrationTests/custom/segfault.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
. ./common.sh
if [ "x$(uname)" != "xLinux" ]; then
exit
fi
# Older GHCs don't report exit via signal adequately
require_ghc_ge 708
cd segfault
! cabal new-build 2> log
cat log
grep SIGSEGV log
3 changes: 3 additions & 0 deletions cabal-install/tests/IntegrationTests/custom/segfault/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import System.Posix.Signals

main = putStrLn "Quitting..." >> raiseSignal sigSEGV
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
14 changes: 14 additions & 0 deletions cabal-install/tests/IntegrationTests/custom/segfault/plain.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: plain
version: 0.1.0.0
license: BSD3
author: Edward Z. Yang
maintainer: [email protected]
build-type: Custom
cabal-version: >=1.10

library
build-depends: base
default-language: Haskell2010

custom-setup
setup-depends: base, unix

0 comments on commit b45df92

Please sign in to comment.