summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorVarriount <Varriount@users.noreply.github.com>2014-05-21 17:54:55 -0400
committerVarriount <Varriount@users.noreply.github.com>2014-05-21 17:54:55 -0400
commitc40f2d682e017321388a73136655c313e876d638 (patch)
tree467664092b488798f65d667057fadf2f5fb30d4a /lib
parent2fa739a2e82c9276724b3ac3b2c1bab05d43df9c (diff)
parent9428bedcc84bfc4cffca7014897410025e9fb658 (diff)
downloadNim-c40f2d682e017321388a73136655c313e876d638.tar.gz
Merge pull request #1169 from Araq/sigpipe
Fixes #1168
Diffstat (limited to 'lib')
-rw-r--r--lib/system/ansi_c.nim3
-rw-r--r--lib/system/excpt.nim10
2 files changed, 12 insertions, 1 deletions
diff --git a/lib/system/ansi_c.nim b/lib/system/ansi_c.nim
index 2d33965e3..5111bc3cf 100644
--- a/lib/system/ansi_c.nim
+++ b/lib/system/ansi_c.nim
@@ -57,6 +57,7 @@ when not defined(SIGINT):
         SIGINT = cint(2)
         SIGSEGV = cint(11)
         SIGTERM = cint(15)
+        SIGPIPE = cint(13)
     else:
       {.error: "SIGABRT not ported to your platform".}
   else:
@@ -66,6 +67,8 @@ when not defined(SIGINT):
       SIGABRT {.importc: "SIGABRT", nodecl.}: cint
       SIGFPE {.importc: "SIGFPE", nodecl.}: cint
       SIGILL {.importc: "SIGILL", nodecl.}: cint
+    when defined(macosx) or defined(linux):
+      var SIGPIPE {.importc: "SIGPIPE", nodecl.}: cint
 
 when defined(macosx):
   when NoFakeVars:
diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim
index 2dc134eaf..63a61183f 100644
--- a/lib/system/excpt.nim
+++ b/lib/system/excpt.nim
@@ -298,7 +298,13 @@ when not defined(noSignalHandler):
       elif s == SIGILL: action("SIGILL: Illegal operation.\n")
       elif s == SIGBUS: 
         action("SIGBUS: Illegal storage access. (Attempt to read from nil?)\n")
-      else: action("unknown signal\n")
+      else:
+        block platformSpecificSignal:
+          when defined(SIGPIPE):
+            if s == SIGPIPE:
+              action("SIGPIPE: Pipe closed.\n")
+              break platformSpecificSignal
+          action("unknown signal\n")
 
     # print stack trace and quit
     when hasSomeStackTrace:
@@ -323,6 +329,8 @@ when not defined(noSignalHandler):
     c_signal(SIGFPE, signalHandler)
     c_signal(SIGILL, signalHandler)
     c_signal(SIGBUS, signalHandler)
+    when defined(SIGPIPE):
+      c_signal(SIGPIPE, signalHandler)
 
   registerSignalHandler() # call it in initialization section