From 6fedb7aa0f76c34bccedd14095bcc7824006489d Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 14 Nov 2008 15:46:45 +0000 Subject: * Restore SIGPIPE to SIG_DFL when running the builder. This prevents subtle and often hard-to-reproduce bugs where programs in pipes either barf with a "Broken pipe" message or not, depending on the exact timing conditions. This particularly happened in GNU M4 (and Bison, which uses M4). --- src/libstore/build.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/libstore') diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 436cf4762ddd..a1c99cddd040 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -361,6 +361,15 @@ 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; + if (sigaction(SIGPIPE, &act, &oact)) throw SysError("resetting SIGPIPE"); +} ////////////////////////////////////////////////////////////////////// @@ -514,6 +523,8 @@ static void runSetuidHelper(const string & command, args.push_back(arg.c_str()); args.push_back(0); + restoreSIGPIPE(); + execve(program.c_str(), (char * *) &args[0], 0); throw SysError(format("executing `%1%'") % program); } @@ -1878,6 +1889,8 @@ void DerivationGoal::startBuilder() args.push_back(i->c_str()); args.push_back(0); + restoreSIGPIPE(); + /* Execute the program. This should not return. */ execve(program.c_str(), (char * *) &args[0], (char * *) envArr); -- cgit 1.4.1