diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2021-04-07 13:10:02 +0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2021-04-07 13:10:02 +0200 |
commit | 9b9e703df41d75949272059f9b8bc8b763e91fce (patch) | |
tree | 8ddcd01325ee08d8029e0a86f467390de23c7b39 /src/libutil | |
parent | 8a29052cb2f52ef2c82c36fb3818fd0f66349729 (diff) |
restoreSignals() + restoreAffinity() -> restoreProcessContext()
Diffstat (limited to 'src/libutil')
-rw-r--r-- | src/libutil/util.cc | 14 | ||||
-rw-r--r-- | src/libutil/util.hh | 8 |
2 files changed, 16 insertions, 6 deletions
diff --git a/src/libutil/util.cc b/src/libutil/util.cc index a6fcabbec..06821abb1 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -1116,7 +1116,7 @@ void runProgram2(const RunOptions & options) Strings args_(options.args); args_.push_front(options.program); - restoreSignals(); + restoreProcessContext(); if (options.searchPath) execvp(options.program.c_str(), stringsToCharPtrs(args_).data()); @@ -1612,12 +1612,19 @@ void startSignalHandlerThread() std::thread(signalHandlerThread, set).detach(); } -void restoreSignals() +static void restoreSignals() { if (sigprocmask(SIG_SETMASK, &savedSignalMask, nullptr)) throw SysError("restoring signals"); } +void restoreProcessContext() +{ + restoreSignals(); + + restoreAffinity(); +} + /* RAII helper to automatically deregister a callback. */ struct InterruptCallbackImpl : InterruptCallback { @@ -1680,10 +1687,11 @@ string showBytes(uint64_t bytes) } +// FIXME: move to libstore/build void commonChildInit(Pipe & logPipe) { const static string pathNullDevice = "/dev/null"; - restoreSignals(); + restoreProcessContext(); /* Put the child in a separate session (and thus a separate process group) so that it has no controlling terminal (meaning diff --git a/src/libutil/util.hh b/src/libutil/util.hh index ef5e5012b..4762d1e55 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -300,6 +300,11 @@ std::pair<int, std::string> runProgram(const RunOptions & options); void runProgram2(const RunOptions & options); +/* Restore the original inherited Unix process context (such as signal + masks, stack size, CPU affinity). */ +void restoreProcessContext(); + + class ExecError : public Error { public: @@ -513,9 +518,6 @@ class Callback; on the current thread (and thus any threads created by it). */ void startSignalHandlerThread(); -/* Restore default signal handling. */ -void restoreSignals(); - struct InterruptCallback { virtual ~InterruptCallback() { }; |