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 22, 2016
1 parent 4a9f11e commit 64b6ec0
Show file tree
Hide file tree
Showing 7 changed files with 47 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
2 changes: 2 additions & 0 deletions cabal-install/tests/IntegrationTests/custom/segfault.err
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
cabal: Failed to build plain-0.1.0.0. The failure occurred during the
configure step. The build process segfaulted (i.e. SIGSEGV).
3 changes: 3 additions & 0 deletions cabal-install/tests/IntegrationTests/custom/segfault.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
. ./common.sh
cd segfault
! cabal new-build
2 changes: 2 additions & 0 deletions cabal-install/tests/IntegrationTests/custom/segfault/Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- From http://codegolf.stackexchange.com/a/4404
foreign import ccall main::IO()
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
packages: .
11 changes: 11 additions & 0 deletions cabal-install/tests/IntegrationTests/custom/segfault/plain.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
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

0 comments on commit 64b6ec0

Please sign in to comment.