aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-07-31 10:31:17 +0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-07-31 10:31:17 +0200
commit50dc1f5b71f7e0e4ba628904b9a47d9f9d875b3e (patch)
tree770054765d335695236e3c1c26f952a9aa76ff29 /src
parent45f9a91e186d91edbf2bed7d27b7fa7227730596 (diff)
Restore default SIGPIPE handler before invoking ‘man’
Fixes NixOS/nixpkgs#3410.
Diffstat (limited to 'src')
-rw-r--r--src/libmain/shared.cc6
-rw-r--r--src/libstore/build.cc12
-rw-r--r--src/libutil/util.cc10
-rw-r--r--src/libutil/util.hh4
4 files changed, 17 insertions, 15 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index 14263446f..47c38e33e 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -244,9 +244,9 @@ static void initAndRun(int argc, char * * argv)
void showManPage(const string & name)
{
- string cmd = "man " + name;
- if (system(cmd.c_str()) != 0)
- throw Error(format("command `%1%' failed") % cmd);
+ restoreSIGPIPE();
+ execlp("man", "man", name.c_str(), NULL);
+ throw SysError(format("command `man %1%' failed") % name.c_str());
}
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 4376a8322..479bc4a24 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -413,18 +413,6 @@ const char * * strings2CharPtrs(const Strings & ss)
}
-/* Restore default handling of SIGPIPE, otherwise some programs will
- randomly say "Broken pipe". */
-static void restoreSIGPIPE()
-{
- struct sigaction act, oact;
- act.sa_handler = SIG_DFL;
- act.sa_flags = 0;
- sigemptyset(&act.sa_mask);
- if (sigaction(SIGPIPE, &act, &oact)) throw SysError("resetting SIGPIPE");
-}
-
-
//////////////////////////////////////////////////////////////////////
diff --git a/src/libutil/util.cc b/src/libutil/util.cc
index aa9d99ec3..f762b79c2 100644
--- a/src/libutil/util.cc
+++ b/src/libutil/util.cc
@@ -927,6 +927,16 @@ void closeOnExec(int fd)
}
+void restoreSIGPIPE()
+{
+ struct sigaction act, oact;
+ act.sa_handler = SIG_DFL;
+ act.sa_flags = 0;
+ sigemptyset(&act.sa_mask);
+ if (sigaction(SIGPIPE, &act, &oact)) throw SysError("resetting SIGPIPE");
+}
+
+
//////////////////////////////////////////////////////////////////////
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index ad0d377a4..64250c522 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -273,6 +273,10 @@ void closeMostFDs(const set<int> & exceptions);
/* Set the close-on-exec flag for the given file descriptor. */
void closeOnExec(int fd);
+/* Restore default handling of SIGPIPE, otherwise some programs will
+ randomly say "Broken pipe". */
+void restoreSIGPIPE();
+
/* User interruption. */