aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2017-02-04 00:05:27 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2017-02-04 00:05:27 +0300
commit967f48c3c9fe62db608cef3b41cc23fd61a5a0be (patch)
tree4d5c298da3204deb4ef3e84b338f5800bcc3ccfd
parent25124e68a4337680776a8f46188c070ed5791fd9 (diff)
Make bpkg to ignore SIGPIPE
-rw-r--r--bpkg/bpkg.cxx15
1 files changed, 14 insertions, 1 deletions
diff --git a/bpkg/bpkg.cxx b/bpkg/bpkg.cxx
index ffdc9c2..7e60725 100644
--- a/bpkg/bpkg.cxx
+++ b/bpkg/bpkg.cxx
@@ -2,7 +2,9 @@
// copyright : Copyright (c) 2014-2017 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
-#ifdef _WIN32
+#ifndef _WIN32
+# include <signal.h> // signal()
+#else
# include <stdlib.h> // getenv(), _putenv()
#endif
@@ -130,6 +132,17 @@ try
}
#endif
+ // On POSIX ignore SIGPIPE which is signaled to a pipe-writing process if
+ // the pipe reading end is closed. Note that by default this signal
+ // terminates a process. Also note that there is no way to disable this
+ // behavior on a file descriptor basis or for the write() function call.
+ //
+#ifndef _WIN32
+ if (signal (SIGPIPE, SIG_IGN) == SIG_ERR)
+ fail << "unable to ignore broken pipe (SIGPIPE) signal: "
+ << system_error (errno, system_category ()); // Sanitize.
+#endif
+
argv_file_scanner scan (argc, argv, "--options-file");
// First parse common options and --version/--help.