Skip to content

Commit c4fc3bd

Browse files
authored
Merge pull request #3712 from ezyang/pr/setup-segfault-msg
Give an explicit message when SIGSEGV happens.
2 parents 6cca0e7 + b45df92 commit c4fc3bd

File tree

7 files changed

+60
-4
lines changed

7 files changed

+60
-4
lines changed

cabal-install/Distribution/Client/ProjectBuilding.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,8 @@ rebuildTargets verbosity
690690
InstallPlan.execute jobControl keepGoing
691691
(BuildFailure Nothing . DependentFailed . packageId)
692692
installPlan $ \pkg ->
693-
handle (return . Left) $ fmap Right $ --TODO: review exception handling
693+
--TODO: review exception handling
694+
handle (\(e :: BuildFailure) -> return (Left e)) $ fmap Right $
694695

695696
let uid = installedUnitId pkg
696697
Just pkgBuildStatus = Map.lookup uid pkgsBuildStatus in

cabal-install/Distribution/Client/ProjectOrchestration.hs

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ import Data.Either
9393
import Control.Exception (Exception(..))
9494
import System.Exit (ExitCode(..), exitFailure)
9595
#ifdef MIN_VERSION_unix
96-
import System.Posix.Signals (sigKILL)
96+
import System.Posix.Signals (sigKILL, sigSEGV)
9797
#endif
9898

9999

@@ -586,11 +586,14 @@ reportBuildFailures verbosity plan buildOutcomes
586586
| otherwise
587587
= False
588588

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

592595
isFailureSelfExplanatory (ConfigureFailed e)
593-
| Just (ExitFailure _) <- fromException e = True
596+
| Just (ExitFailure 1) <- fromException e = True
594597

595598
isFailureSelfExplanatory _ = False
596599

@@ -651,7 +654,27 @@ reportBuildFailures verbosity plan buildOutcomes
651654
Just (ExitFailure 1) -> ""
652655

653656
#ifdef MIN_VERSION_unix
657+
-- Note [Positive "signal" exit code]
658+
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
659+
-- What's the business with the test for negative and positive
660+
-- signal values? The API for process specifies that if the
661+
-- process died due to a signal, it returns a *negative* exit
662+
-- code. So that's the negative test.
663+
--
664+
-- What about the positive test? Well, when we find out that
665+
-- a process died due to a signal, we ourselves exit with that
666+
-- exit code. However, we don't "kill ourselves" with the
667+
-- signal; we just exit with the same code as the signal: thus
668+
-- the caller sees a *positive* exit code. So that's what
669+
-- happens when we get a positive exit code.
654670
Just (ExitFailure n)
671+
| -n == fromIntegral sigSEGV ->
672+
" The build process segfaulted (i.e. SIGSEGV)."
673+
674+
| n == fromIntegral sigSEGV ->
675+
" The build process terminated with exit code " ++ show n
676+
++ " which may be because some part of it segfaulted. (i.e. SIGSEGV)."
677+
655678
| -n == fromIntegral sigKILL ->
656679
" The build process was killed (i.e. SIGKILL). " ++ explanation
657680

cabal-install/cabal-install.cabal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Extra-Source-Files:
3535
tests/IntegrationTests/custom/plain/A.hs
3636
tests/IntegrationTests/custom/plain/Setup.hs
3737
tests/IntegrationTests/custom/plain/plain.cabal
38+
tests/IntegrationTests/custom/segfault.sh
39+
tests/IntegrationTests/custom/segfault/Setup.hs
40+
tests/IntegrationTests/custom/segfault/cabal.project
41+
tests/IntegrationTests/custom/segfault/plain.cabal
3842
tests/IntegrationTests/exec/Foo.hs
3943
tests/IntegrationTests/exec/My.hs
4044
tests/IntegrationTests/exec/adds_sandbox_bin_directory_to_path.out
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
. ./common.sh
2+
if [ "x$(uname)" != "xLinux" ]; then
3+
exit
4+
fi
5+
# Older GHCs don't report exit via signal adequately
6+
require_ghc_ge 708
7+
cd segfault
8+
! cabal new-build 2> log
9+
cat log
10+
grep SIGSEGV log
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import System.Posix.Signals
2+
3+
main = putStrLn "Quitting..." >> raiseSignal sigSEGV
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
packages: .
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
name: plain
2+
version: 0.1.0.0
3+
license: BSD3
4+
author: Edward Z. Yang
5+
maintainer: [email protected]
6+
build-type: Custom
7+
cabal-version: >=1.10
8+
9+
library
10+
build-depends: base
11+
default-language: Haskell2010
12+
13+
custom-setup
14+
setup-depends: base, unix

0 commit comments

Comments
 (0)