aboutsummaryrefslogtreecommitdiff
path: root/src/libmain/shared.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2013-07-30 23:25:37 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2013-07-30 23:37:10 +0200
commit70e68e0ec604124bb248ea4d064307bbf96e7932 (patch)
treeba15bf6c08a80d254f2d2af859c4a8b46ed14f75 /src/libmain/shared.cc
parente87d1a63bdef0ae08f2d94d67fd8daa8fbb63fb4 (diff)
Detect stack overflows
Previously, if the Nix evaluator gets a stack overflow due to a deep or infinite recursion in the Nix expression, the user gets an unhelpful message ("Segmentation fault") that doesn't indicate that the problem is in the user's code rather than Nix itself. Now it prints: error: stack overflow (possible infinite recursion) This only works on x86_64-linux and i686-linux. Fixes #35.
Diffstat (limited to 'src/libmain/shared.cc')
-rw-r--r--src/libmain/shared.cc7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index 4796629dc..ee0dccc9d 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -13,6 +13,7 @@
#include <sys/time.h>
#include <sys/stat.h>
#include <unistd.h>
+#include <signal.h>
#if HAVE_BOEHMGC
#include <gc/gc.h>
@@ -100,6 +101,9 @@ string getArg(const string & opt,
}
+void detectStackOverflow();
+
+
/* Initialize and reorder arguments, then call the actual argument
processor. */
static void initAndRun(int argc, char * * argv)
@@ -131,6 +135,9 @@ static void initAndRun(int argc, char * * argv)
if (sigaction(SIGCHLD, &act, 0))
throw SysError("resetting SIGCHLD");
+ /* Register a SIGSEGV handler to detect stack overflows. */
+ detectStackOverflow();
+
/* There is no privacy in the Nix system ;-) At least not for
now. In particular, store objects should be readable by
everybody. */