2006-09-04 21:06:23 +00:00
|
|
|
|
#include "globals.hh"
|
2016-02-09 20:07:48 +00:00
|
|
|
|
#include "shared.hh"
|
2006-11-30 17:43:04 +00:00
|
|
|
|
#include "store-api.hh"
|
2006-09-04 21:06:23 +00:00
|
|
|
|
#include "util.hh"
|
|
|
|
|
|
2016-02-22 13:49:15 +00:00
|
|
|
|
#include <algorithm>
|
2003-07-24 08:53:43 +00:00
|
|
|
|
#include <cctype>
|
2007-05-01 15:16:17 +00:00
|
|
|
|
#include <exception>
|
2016-02-22 13:49:15 +00:00
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <mutex>
|
2003-07-04 15:42:03 +00:00
|
|
|
|
|
2014-12-14 00:51:14 +00:00
|
|
|
|
#include <cstdlib>
|
2012-12-11 10:49:42 +00:00
|
|
|
|
#include <sys/time.h>
|
2004-03-27 17:58:04 +00:00
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <unistd.h>
|
2013-07-30 21:25:37 +00:00
|
|
|
|
#include <signal.h>
|
2004-03-27 17:58:04 +00:00
|
|
|
|
|
2016-02-22 13:49:15 +00:00
|
|
|
|
#include <openssl/crypto.h>
|
2014-12-05 20:05:24 +00:00
|
|
|
|
|
2003-07-04 15:42:03 +00:00
|
|
|
|
|
2006-09-04 21:06:23 +00:00
|
|
|
|
namespace nix {
|
2003-07-04 15:42:03 +00:00
|
|
|
|
|
|
|
|
|
|
2013-12-20 12:19:10 +00:00
|
|
|
|
static bool gcWarning = true;
|
|
|
|
|
|
2005-02-01 12:36:25 +00:00
|
|
|
|
void printGCWarning()
|
|
|
|
|
{
|
2013-12-20 12:19:10 +00:00
|
|
|
|
if (!gcWarning) return;
|
2006-08-29 15:40:49 +00:00
|
|
|
|
static bool haveWarned = false;
|
2012-07-30 21:13:25 +00:00
|
|
|
|
warnOnce(haveWarned,
|
2017-07-30 11:27:57 +00:00
|
|
|
|
"you did not specify '--add-root'; "
|
2006-08-29 15:40:49 +00:00
|
|
|
|
"the result might be removed by the garbage collector");
|
2005-02-01 12:36:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-08-31 15:57:04 +00:00
|
|
|
|
void printMissing(ref<Store> store, const PathSet & paths, Verbosity lvl)
|
2008-08-04 13:44:46 +00:00
|
|
|
|
{
|
2010-11-17 14:31:42 +00:00
|
|
|
|
unsigned long long downloadSize, narSize;
|
2008-08-04 13:44:46 +00:00
|
|
|
|
PathSet willBuild, willSubstitute, unknown;
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 13:28:26 +00:00
|
|
|
|
store->queryMissing(paths, willBuild, willSubstitute, unknown, downloadSize, narSize);
|
2017-08-31 15:57:04 +00:00
|
|
|
|
printMissing(store, willBuild, willSubstitute, unknown, downloadSize, narSize, lvl);
|
2012-11-19 23:27:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2008-08-04 13:44:46 +00:00
|
|
|
|
|
2016-02-04 13:48:42 +00:00
|
|
|
|
void printMissing(ref<Store> store, const PathSet & willBuild,
|
2012-11-19 23:27:25 +00:00
|
|
|
|
const PathSet & willSubstitute, const PathSet & unknown,
|
2017-08-31 15:57:04 +00:00
|
|
|
|
unsigned long long downloadSize, unsigned long long narSize, Verbosity lvl)
|
2012-11-19 23:27:25 +00:00
|
|
|
|
{
|
2008-08-04 13:44:46 +00:00
|
|
|
|
if (!willBuild.empty()) {
|
2017-08-31 15:57:04 +00:00
|
|
|
|
printMsg(lvl, "these derivations will be built:");
|
Eliminate the "store" global variable
Also, move a few free-standing functions into StoreAPI and Derivation.
Also, introduce a non-nullable smart pointer, ref<T>, which is just a
wrapper around std::shared_ptr ensuring that the pointer is never
null. (For reference-counted values, this is better than passing a
"T&", because the latter doesn't maintain the refcount. Usually, the
caller will have a shared_ptr keeping the value alive, but that's not
always the case, e.g., when passing a reference to a std::thread via
std::bind.)
2016-02-04 13:28:26 +00:00
|
|
|
|
Paths sorted = store->topoSortPaths(willBuild);
|
2014-09-26 12:09:20 +00:00
|
|
|
|
reverse(sorted.begin(), sorted.end());
|
|
|
|
|
for (auto & i : sorted)
|
2017-08-31 15:57:04 +00:00
|
|
|
|
printMsg(lvl, fmt(" %s", i));
|
2008-08-04 13:44:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!willSubstitute.empty()) {
|
2017-08-31 15:57:04 +00:00
|
|
|
|
printMsg(lvl, fmt("these paths will be fetched (%.2f MiB download, %.2f MiB unpacked):",
|
|
|
|
|
downloadSize / (1024.0 * 1024.0),
|
|
|
|
|
narSize / (1024.0 * 1024.0)));
|
2014-09-26 12:09:20 +00:00
|
|
|
|
for (auto & i : willSubstitute)
|
2017-08-31 15:57:04 +00:00
|
|
|
|
printMsg(lvl, fmt(" %s", i));
|
2008-08-04 13:44:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!unknown.empty()) {
|
2017-08-31 15:57:04 +00:00
|
|
|
|
printMsg(lvl, fmt("don't know how to build these paths%s:",
|
|
|
|
|
(settings.readOnlyMode ? " (may be caused by read-only store access)" : "")));
|
2014-09-26 12:09:20 +00:00
|
|
|
|
for (auto & i : unknown)
|
2017-08-31 15:57:04 +00:00
|
|
|
|
printMsg(lvl, fmt(" %s", i));
|
2008-08-04 13:44:46 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-07-30 23:55:41 +00:00
|
|
|
|
string getArg(const string & opt,
|
|
|
|
|
Strings::iterator & i, const Strings::iterator & end)
|
|
|
|
|
{
|
|
|
|
|
++i;
|
2017-07-30 11:27:57 +00:00
|
|
|
|
if (i == end) throw UsageError(format("'%1%' requires an argument") % opt);
|
2012-07-30 23:55:41 +00:00
|
|
|
|
return *i;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-03 20:37:06 +00:00
|
|
|
|
|
2016-02-22 13:49:15 +00:00
|
|
|
|
/* OpenSSL is not thread-safe by default - it will randomly crash
|
|
|
|
|
unless the user supplies a mutex locking function. So let's do
|
|
|
|
|
that. */
|
|
|
|
|
static std::vector<std::mutex> opensslLocks;
|
|
|
|
|
|
|
|
|
|
static void opensslLockCallback(int mode, int type, const char * file, int line)
|
|
|
|
|
{
|
|
|
|
|
if (mode & CRYPTO_LOCK)
|
|
|
|
|
opensslLocks[type].lock();
|
|
|
|
|
else
|
|
|
|
|
opensslLocks[type].unlock();
|
|
|
|
|
}
|
2013-07-30 21:25:37 +00:00
|
|
|
|
|
|
|
|
|
|
2017-01-25 12:37:02 +00:00
|
|
|
|
static void sigHandler(int signo) { }
|
|
|
|
|
|
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
void initNix()
|
2003-07-04 15:42:03 +00:00
|
|
|
|
{
|
2014-08-13 01:50:44 +00:00
|
|
|
|
/* Turn on buffering for cerr. */
|
|
|
|
|
#if HAVE_PUBSETBUF
|
|
|
|
|
static char buf[1024];
|
|
|
|
|
std::cerr.rdbuf()->pubsetbuf(buf, sizeof(buf));
|
|
|
|
|
#endif
|
|
|
|
|
|
2016-02-22 13:49:15 +00:00
|
|
|
|
/* Initialise OpenSSL locking. */
|
|
|
|
|
opensslLocks = std::vector<std::mutex>(CRYPTO_num_locks());
|
|
|
|
|
CRYPTO_set_locking_callback(opensslLockCallback);
|
2015-07-19 23:39:48 +00:00
|
|
|
|
|
2012-07-30 23:55:41 +00:00
|
|
|
|
settings.loadConfFile();
|
2012-07-30 21:13:25 +00:00
|
|
|
|
|
2017-01-17 17:21:02 +00:00
|
|
|
|
startSignalHandlerThread();
|
2004-01-15 20:23:55 +00:00
|
|
|
|
|
2017-02-01 12:00:21 +00:00
|
|
|
|
/* Reset SIGCHLD to its default. */
|
2017-01-17 17:21:02 +00:00
|
|
|
|
struct sigaction act;
|
|
|
|
|
sigemptyset(&act.sa_mask);
|
2010-01-12 12:22:38 +00:00
|
|
|
|
act.sa_handler = SIG_DFL;
|
|
|
|
|
act.sa_flags = 0;
|
|
|
|
|
if (sigaction(SIGCHLD, &act, 0))
|
|
|
|
|
throw SysError("resetting SIGCHLD");
|
|
|
|
|
|
2017-01-25 12:37:02 +00:00
|
|
|
|
/* Install a dummy SIGUSR1 handler for use with pthread_kill(). */
|
|
|
|
|
act.sa_handler = sigHandler;
|
|
|
|
|
if (sigaction(SIGUSR1, &act, 0)) throw SysError("handling SIGUSR1");
|
|
|
|
|
|
2013-07-30 21:25:37 +00:00
|
|
|
|
/* Register a SIGSEGV handler to detect stack overflows. */
|
|
|
|
|
detectStackOverflow();
|
|
|
|
|
|
2004-09-09 14:16:02 +00:00
|
|
|
|
/* There is no privacy in the Nix system ;-) At least not for
|
|
|
|
|
now. In particular, store objects should be readable by
|
2012-10-03 21:30:45 +00:00
|
|
|
|
everybody. */
|
2004-09-09 14:16:02 +00:00
|
|
|
|
umask(0022);
|
|
|
|
|
|
2012-12-11 10:49:42 +00:00
|
|
|
|
/* Initialise the PRNG. */
|
|
|
|
|
struct timeval tv;
|
|
|
|
|
gettimeofday(&tv, 0);
|
|
|
|
|
srandom(tv.tv_usec);
|
2017-06-12 15:43:19 +00:00
|
|
|
|
|
|
|
|
|
/* On macOS, don't use the per-session TMPDIR (as set e.g. by
|
|
|
|
|
sshd). This breaks build users because they don't have access
|
|
|
|
|
to the TMPDIR, in particular in ‘nix-store --serve’. */
|
|
|
|
|
#if __APPLE__
|
|
|
|
|
if (getuid() == 0 && hasPrefix(getEnv("TMPDIR"), "/var/folders/"))
|
|
|
|
|
unsetenv("TMPDIR");
|
|
|
|
|
#endif
|
2014-08-13 01:50:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-10-24 10:45:11 +00:00
|
|
|
|
LegacyArgs::LegacyArgs(const std::string & programName,
|
|
|
|
|
std::function<bool(Strings::iterator & arg, const Strings::iterator & end)> parseArg)
|
|
|
|
|
: MixCommonArgs(programName), parseArg(parseArg)
|
2014-08-13 01:50:44 +00:00
|
|
|
|
{
|
2017-10-24 10:45:11 +00:00
|
|
|
|
mkFlag()
|
|
|
|
|
.longName("no-build-output")
|
|
|
|
|
.shortName('Q')
|
|
|
|
|
.description("do not show build output")
|
|
|
|
|
.set(&settings.verboseBuild, false);
|
|
|
|
|
|
|
|
|
|
mkFlag()
|
|
|
|
|
.longName("keep-failed")
|
|
|
|
|
.shortName('K')
|
|
|
|
|
.description("keep temporary directories of failed builds")
|
|
|
|
|
.set(&(bool&) settings.keepFailed, true);
|
|
|
|
|
|
|
|
|
|
mkFlag()
|
|
|
|
|
.longName("keep-going")
|
|
|
|
|
.shortName('k')
|
|
|
|
|
.description("keep going after a build fails")
|
|
|
|
|
.set(&(bool&) settings.keepGoing, true);
|
|
|
|
|
|
|
|
|
|
mkFlag()
|
|
|
|
|
.longName("fallback")
|
|
|
|
|
.description("build from source if substitution fails")
|
|
|
|
|
.set(&(bool&) settings.tryFallback, true);
|
|
|
|
|
|
|
|
|
|
mkFlag1('j', "max-jobs", "jobs", "maximum number of parallel builds", [=](std::string s) {
|
|
|
|
|
settings.set("max-jobs", s);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
auto intSettingAlias = [&](char shortName, const std::string & longName,
|
|
|
|
|
const std::string & description, const std::string & dest) {
|
|
|
|
|
mkFlag<unsigned int>(shortName, longName, description, [=](unsigned int n) {
|
|
|
|
|
settings.set(dest, std::to_string(n));
|
2016-02-09 20:07:48 +00:00
|
|
|
|
});
|
2017-10-24 10:45:11 +00:00
|
|
|
|
};
|
2016-02-09 20:07:48 +00:00
|
|
|
|
|
2017-10-24 10:45:11 +00:00
|
|
|
|
intSettingAlias(0, "cores", "maximum number of CPU cores to use inside a build", "cores");
|
|
|
|
|
intSettingAlias(0, "max-silent-time", "number of seconds of silence before a build is killed", "max-silent-time");
|
|
|
|
|
intSettingAlias(0, "timeout", "number of seconds before a build is killed", "timeout");
|
2017-02-28 11:54:50 +00:00
|
|
|
|
|
2017-10-24 10:45:11 +00:00
|
|
|
|
mkFlag(0, "readonly-mode", "do not write to the Nix store",
|
|
|
|
|
&settings.readOnlyMode);
|
2016-02-09 20:07:48 +00:00
|
|
|
|
|
2017-10-24 10:45:11 +00:00
|
|
|
|
mkFlag(0, "show-trace", "show Nix expression stack trace in evaluation errors",
|
|
|
|
|
&settings.showTrace);
|
2016-02-09 20:07:48 +00:00
|
|
|
|
|
2017-10-24 10:45:11 +00:00
|
|
|
|
mkFlag(0, "no-gc-warning", "disable warning about not using '--add-root'",
|
|
|
|
|
&gcWarning, false);
|
2017-10-24 13:41:11 +00:00
|
|
|
|
|
|
|
|
|
mkFlag()
|
|
|
|
|
.longName("store")
|
|
|
|
|
.label("store-uri")
|
|
|
|
|
.description("URI of the Nix store to use")
|
|
|
|
|
.dest(&(std::string&) settings.storeUri);
|
2017-10-24 10:45:11 +00:00
|
|
|
|
}
|
2016-02-09 20:07:48 +00:00
|
|
|
|
|
|
|
|
|
|
2017-10-24 10:45:11 +00:00
|
|
|
|
bool LegacyArgs::processFlag(Strings::iterator & pos, Strings::iterator end)
|
|
|
|
|
{
|
|
|
|
|
if (MixCommonArgs::processFlag(pos, end)) return true;
|
|
|
|
|
bool res = parseArg(pos, end);
|
|
|
|
|
if (res) ++pos;
|
|
|
|
|
return res;
|
|
|
|
|
}
|
2016-02-09 20:07:48 +00:00
|
|
|
|
|
2003-12-01 15:55:05 +00:00
|
|
|
|
|
2017-10-24 10:45:11 +00:00
|
|
|
|
bool LegacyArgs::processArgs(const Strings & args, bool finish)
|
|
|
|
|
{
|
|
|
|
|
if (args.empty()) return true;
|
|
|
|
|
assert(args.size() == 1);
|
|
|
|
|
Strings ss(args);
|
|
|
|
|
auto pos = ss.begin();
|
|
|
|
|
if (!parseArg(pos, ss.end()))
|
|
|
|
|
throw UsageError(format("unexpected argument '%1%'") % args.front());
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-02-09 20:07:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void parseCmdLine(int argc, char * * argv,
|
|
|
|
|
std::function<bool(Strings::iterator & arg, const Strings::iterator & end)> parseArg)
|
|
|
|
|
{
|
2017-07-25 13:09:06 +00:00
|
|
|
|
parseCmdLine(baseNameOf(argv[0]), argvToStrings(argc, argv), parseArg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void parseCmdLine(const string & programName, const Strings & args,
|
|
|
|
|
std::function<bool(Strings::iterator & arg, const Strings::iterator & end)> parseArg)
|
|
|
|
|
{
|
|
|
|
|
LegacyArgs(programName, parseArg).parseCmdline(args);
|
2014-08-13 01:50:44 +00:00
|
|
|
|
}
|
2012-07-30 23:55:41 +00:00
|
|
|
|
|
2006-03-01 16:36:35 +00:00
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
void printVersion(const string & programName)
|
|
|
|
|
{
|
|
|
|
|
std::cout << format("%1% (Nix) %2%") % programName % nixVersion << std::endl;
|
2015-07-23 12:19:49 +00:00
|
|
|
|
if (verbosity > lvlInfo) {
|
|
|
|
|
Strings cfg;
|
|
|
|
|
#if HAVE_BOEHMGC
|
|
|
|
|
cfg.push_back("gc");
|
|
|
|
|
#endif
|
|
|
|
|
#if HAVE_SODIUM
|
|
|
|
|
cfg.push_back("signed-caches");
|
|
|
|
|
#endif
|
|
|
|
|
std::cout << "Features: " << concatStringsSep(", ", cfg) << "\n";
|
|
|
|
|
std::cout << "Configuration file: " << settings.nixConfDir + "/nix.conf" << "\n";
|
|
|
|
|
std::cout << "Store directory: " << settings.nixStore << "\n";
|
|
|
|
|
std::cout << "State directory: " << settings.nixStateDir << "\n";
|
|
|
|
|
}
|
2014-08-13 01:50:44 +00:00
|
|
|
|
throw Exit();
|
2003-07-04 15:42:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-10-03 20:37:06 +00:00
|
|
|
|
void showManPage(const string & name)
|
|
|
|
|
{
|
2017-02-01 12:00:21 +00:00
|
|
|
|
restoreSignals();
|
2014-07-31 08:31:17 +00:00
|
|
|
|
execlp("man", "man", name.c_str(), NULL);
|
2017-07-30 11:27:57 +00:00
|
|
|
|
throw SysError(format("command 'man %1%' failed") % name.c_str());
|
2012-10-03 20:37:06 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
int handleExceptions(const string & programName, std::function<void()> fun)
|
2003-07-04 15:42:03 +00:00
|
|
|
|
{
|
2017-01-25 12:37:02 +00:00
|
|
|
|
ReceiveInterrupts receiveInterrupts; // FIXME: need better place for this
|
|
|
|
|
|
2014-08-20 14:01:16 +00:00
|
|
|
|
string error = ANSI_RED "error:" ANSI_NORMAL " ";
|
2003-07-04 15:42:03 +00:00
|
|
|
|
try {
|
2004-05-11 18:05:44 +00:00
|
|
|
|
try {
|
2014-08-13 01:50:44 +00:00
|
|
|
|
fun();
|
2004-05-11 18:05:44 +00:00
|
|
|
|
} catch (...) {
|
|
|
|
|
/* Subtle: we have to make sure that any `interrupted'
|
|
|
|
|
condition is discharged before we reach printMsg()
|
|
|
|
|
below, since otherwise it will throw an (uncaught)
|
|
|
|
|
exception. */
|
2017-04-21 14:28:10 +00:00
|
|
|
|
setInterruptThrown();
|
2004-05-11 18:05:44 +00:00
|
|
|
|
throw;
|
|
|
|
|
}
|
2014-08-13 01:50:44 +00:00
|
|
|
|
} catch (Exit & e) {
|
|
|
|
|
return e.status;
|
2003-07-04 15:42:03 +00:00
|
|
|
|
} catch (UsageError & e) {
|
2016-09-21 14:11:01 +00:00
|
|
|
|
printError(
|
2017-07-30 11:27:57 +00:00
|
|
|
|
format(error + "%1%\nTry '%2% --help' for more information.")
|
2014-08-13 01:50:44 +00:00
|
|
|
|
% e.what() % programName);
|
2003-07-04 15:42:03 +00:00
|
|
|
|
return 1;
|
2007-08-12 00:29:28 +00:00
|
|
|
|
} catch (BaseError & e) {
|
2016-09-21 14:11:01 +00:00
|
|
|
|
printError(format(error + "%1%%2%") % (settings.showTrace ? e.prefix() : "") % e.msg());
|
2013-11-12 11:51:59 +00:00
|
|
|
|
if (e.prefix() != "" && !settings.showTrace)
|
2017-07-30 11:27:57 +00:00
|
|
|
|
printError("(use '--show-trace' to show detailed location information)");
|
2010-12-13 16:53:23 +00:00
|
|
|
|
return e.status;
|
2013-10-02 12:34:36 +00:00
|
|
|
|
} catch (std::bad_alloc & e) {
|
2016-09-21 14:11:01 +00:00
|
|
|
|
printError(error + "out of memory");
|
2013-10-02 12:34:36 +00:00
|
|
|
|
return 1;
|
2006-09-04 21:06:23 +00:00
|
|
|
|
} catch (std::exception & e) {
|
2016-09-21 14:11:01 +00:00
|
|
|
|
printError(error + e.what());
|
2003-07-04 15:42:03 +00:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-13 01:50:44 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-20 13:12:58 +00:00
|
|
|
|
RunPager::RunPager()
|
|
|
|
|
{
|
2014-12-10 17:16:05 +00:00
|
|
|
|
if (!isatty(STDOUT_FILENO)) return;
|
2015-01-02 14:26:56 +00:00
|
|
|
|
char * pager = getenv("NIX_PAGER");
|
|
|
|
|
if (!pager) pager = getenv("PAGER");
|
|
|
|
|
if (pager && ((string) pager == "" || (string) pager == "cat")) return;
|
2014-08-20 13:12:58 +00:00
|
|
|
|
|
|
|
|
|
Pipe toPager;
|
|
|
|
|
toPager.create();
|
|
|
|
|
|
2014-12-10 12:48:50 +00:00
|
|
|
|
pid = startProcess([&]() {
|
2016-07-11 19:44:44 +00:00
|
|
|
|
if (dup2(toPager.readSide.get(), STDIN_FILENO) == -1)
|
2014-12-10 12:48:50 +00:00
|
|
|
|
throw SysError("dupping stdin");
|
|
|
|
|
if (!getenv("LESS"))
|
|
|
|
|
setenv("LESS", "FRSXMK", 1);
|
2017-02-01 12:00:21 +00:00
|
|
|
|
restoreSignals();
|
2015-01-02 14:26:56 +00:00
|
|
|
|
if (pager)
|
|
|
|
|
execl("/bin/sh", "sh", "-c", pager, NULL);
|
2014-12-10 17:16:05 +00:00
|
|
|
|
execlp("pager", "pager", NULL);
|
|
|
|
|
execlp("less", "less", NULL);
|
|
|
|
|
execlp("more", "more", NULL);
|
2017-07-30 11:27:57 +00:00
|
|
|
|
throw SysError(format("executing '%1%'") % pager);
|
2014-12-10 12:48:50 +00:00
|
|
|
|
});
|
2014-08-20 13:12:58 +00:00
|
|
|
|
|
2017-02-01 12:00:21 +00:00
|
|
|
|
pid.setKillSignal(SIGINT);
|
|
|
|
|
|
2016-07-11 19:44:44 +00:00
|
|
|
|
if (dup2(toPager.writeSide.get(), STDOUT_FILENO) == -1)
|
2014-08-20 13:12:58 +00:00
|
|
|
|
throw SysError("dupping stdout");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RunPager::~RunPager()
|
|
|
|
|
{
|
2014-12-12 13:05:23 +00:00
|
|
|
|
try {
|
|
|
|
|
if (pid != -1) {
|
|
|
|
|
std::cout.flush();
|
|
|
|
|
close(STDOUT_FILENO);
|
2017-01-19 15:58:39 +00:00
|
|
|
|
pid.wait();
|
2014-12-12 13:05:23 +00:00
|
|
|
|
}
|
|
|
|
|
} catch (...) {
|
2017-03-16 09:52:28 +00:00
|
|
|
|
ignoreException();
|
2014-08-20 13:12:58 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2015-05-21 13:21:38 +00:00
|
|
|
|
string showBytes(unsigned long long bytes)
|
|
|
|
|
{
|
|
|
|
|
return (format("%.2f MiB") % (bytes / (1024.0 * 1024.0))).str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PrintFreed::~PrintFreed()
|
|
|
|
|
{
|
|
|
|
|
if (show)
|
|
|
|
|
std::cout << format("%1% store paths deleted, %2% freed\n")
|
|
|
|
|
% results.paths.size()
|
|
|
|
|
% showBytes(results.bytesFreed);
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-07 20:42:34 +00:00
|
|
|
|
Exit::~Exit() { }
|
2015-05-21 13:21:38 +00:00
|
|
|
|
|
2003-07-04 15:42:03 +00:00
|
|
|
|
}
|