2007-03-30 16:24:35 +03:00
|
|
|
|
#include "config.h"
|
|
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
|
#include "shared.hh"
|
|
|
|
|
#include "globals.hh"
|
2006-11-30 19:43:04 +02:00
|
|
|
|
#include "store-api.hh"
|
2006-09-05 00:06:23 +03:00
|
|
|
|
#include "util.hh"
|
2008-08-04 16:44:46 +03:00
|
|
|
|
#include "misc.hh"
|
2006-09-05 00:06:23 +03:00
|
|
|
|
|
2003-07-04 18:42:03 +03:00
|
|
|
|
#include <iostream>
|
2003-07-24 11:53:43 +03:00
|
|
|
|
#include <cctype>
|
2007-05-01 18:16:17 +03:00
|
|
|
|
#include <exception>
|
2014-09-26 15:09:20 +03:00
|
|
|
|
#include <algorithm>
|
2003-07-04 18:42:03 +03:00
|
|
|
|
|
2014-12-14 02:51:14 +02:00
|
|
|
|
#include <cstdlib>
|
2012-12-11 12:49:42 +02:00
|
|
|
|
#include <sys/time.h>
|
2004-03-27 19:58:04 +02:00
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
#include <unistd.h>
|
2013-07-31 00:25:37 +03:00
|
|
|
|
#include <signal.h>
|
2004-03-27 19:58:04 +02:00
|
|
|
|
|
2014-12-05 22:05:24 +02:00
|
|
|
|
extern char * * environ;
|
|
|
|
|
|
2003-07-04 18:42:03 +03:00
|
|
|
|
|
2006-09-05 00:06:23 +03:00
|
|
|
|
namespace nix {
|
2003-07-04 18:42:03 +03:00
|
|
|
|
|
|
|
|
|
|
2004-05-11 21:05:44 +03:00
|
|
|
|
volatile sig_atomic_t blockInt = 0;
|
|
|
|
|
|
|
|
|
|
|
2006-03-11 00:27:26 +02:00
|
|
|
|
static void sigintHandler(int signo)
|
2004-01-15 22:23:55 +02:00
|
|
|
|
{
|
2004-05-11 21:05:44 +03:00
|
|
|
|
if (!blockInt) {
|
|
|
|
|
_isInterrupted = 1;
|
|
|
|
|
blockInt = 1;
|
|
|
|
|
}
|
2004-01-15 22:23:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2013-12-20 14:19:10 +02:00
|
|
|
|
static bool gcWarning = true;
|
|
|
|
|
|
2005-02-01 14:36:25 +02:00
|
|
|
|
void printGCWarning()
|
|
|
|
|
{
|
2013-12-20 14:19:10 +02:00
|
|
|
|
if (!gcWarning) return;
|
2006-08-29 18:40:49 +03:00
|
|
|
|
static bool haveWarned = false;
|
2012-07-31 00:13:25 +03:00
|
|
|
|
warnOnce(haveWarned,
|
2014-08-20 18:00:17 +03:00
|
|
|
|
"you did not specify ‘--add-root’; "
|
2006-08-29 18:40:49 +03:00
|
|
|
|
"the result might be removed by the garbage collector");
|
2005-02-01 14:36:25 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-09-01 00:11:50 +03:00
|
|
|
|
void printMissing(StoreAPI & store, const PathSet & paths)
|
2008-08-04 16:44:46 +03:00
|
|
|
|
{
|
2010-11-17 16:31:42 +02:00
|
|
|
|
unsigned long long downloadSize, narSize;
|
2008-08-04 16:44:46 +03:00
|
|
|
|
PathSet willBuild, willSubstitute, unknown;
|
2011-09-01 00:11:50 +03:00
|
|
|
|
queryMissing(store, paths, willBuild, willSubstitute, unknown, downloadSize, narSize);
|
2012-11-20 01:27:25 +02:00
|
|
|
|
printMissing(willBuild, willSubstitute, unknown, downloadSize, narSize);
|
|
|
|
|
}
|
|
|
|
|
|
2008-08-04 16:44:46 +03:00
|
|
|
|
|
2012-11-20 01:27:25 +02:00
|
|
|
|
void printMissing(const PathSet & willBuild,
|
|
|
|
|
const PathSet & willSubstitute, const PathSet & unknown,
|
|
|
|
|
unsigned long long downloadSize, unsigned long long narSize)
|
|
|
|
|
{
|
2008-08-04 16:44:46 +03:00
|
|
|
|
if (!willBuild.empty()) {
|
2010-11-17 16:31:42 +02:00
|
|
|
|
printMsg(lvlInfo, format("these derivations will be built:"));
|
2014-09-26 15:09:20 +03:00
|
|
|
|
Paths sorted = topoSortPaths(*store, willBuild);
|
|
|
|
|
reverse(sorted.begin(), sorted.end());
|
|
|
|
|
for (auto & i : sorted)
|
|
|
|
|
printMsg(lvlInfo, format(" %1%") % i);
|
2008-08-04 16:44:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!willSubstitute.empty()) {
|
2011-11-29 15:00:41 +02:00
|
|
|
|
printMsg(lvlInfo, format("these paths will be fetched (%.2f MiB download, %.2f MiB unpacked):")
|
2010-11-17 16:31:42 +02:00
|
|
|
|
% (downloadSize / (1024.0 * 1024.0))
|
|
|
|
|
% (narSize / (1024.0 * 1024.0)));
|
2014-09-26 15:09:20 +03:00
|
|
|
|
for (auto & i : willSubstitute)
|
|
|
|
|
printMsg(lvlInfo, format(" %1%") % i);
|
2008-08-04 16:44:46 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!unknown.empty()) {
|
2010-11-17 16:31:42 +02:00
|
|
|
|
printMsg(lvlInfo, format("don't know how to build these paths%1%:")
|
2012-07-31 02:55:41 +03:00
|
|
|
|
% (settings.readOnlyMode ? " (may be caused by read-only store access)" : ""));
|
2014-09-26 15:09:20 +03:00
|
|
|
|
for (auto & i : unknown)
|
|
|
|
|
printMsg(lvlInfo, format(" %1%") % i);
|
2008-08-04 16:44:46 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-03-11 00:27:26 +02:00
|
|
|
|
static void setLogType(string lt)
|
2004-03-22 22:53:49 +02:00
|
|
|
|
{
|
|
|
|
|
if (lt == "pretty") logType = ltPretty;
|
|
|
|
|
else if (lt == "escapes") logType = ltEscapes;
|
|
|
|
|
else if (lt == "flat") logType = ltFlat;
|
|
|
|
|
else throw UsageError("unknown log type");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-07-31 02:55:41 +03:00
|
|
|
|
string getArg(const string & opt,
|
|
|
|
|
Strings::iterator & i, const Strings::iterator & end)
|
|
|
|
|
{
|
|
|
|
|
++i;
|
2014-08-20 18:00:17 +03:00
|
|
|
|
if (i == end) throw UsageError(format("‘%1%’ requires an argument") % opt);
|
2012-07-31 02:55:41 +03:00
|
|
|
|
return *i;
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-03 23:37:06 +03:00
|
|
|
|
|
2013-07-31 00:25:37 +03:00
|
|
|
|
void detectStackOverflow();
|
|
|
|
|
|
|
|
|
|
|
2014-08-13 04:50:44 +03:00
|
|
|
|
void initNix()
|
2003-07-04 18:42:03 +03:00
|
|
|
|
{
|
2014-08-13 04:50:44 +03:00
|
|
|
|
/* Turn on buffering for cerr. */
|
|
|
|
|
#if HAVE_PUBSETBUF
|
|
|
|
|
static char buf[1024];
|
|
|
|
|
std::cerr.rdbuf()->pubsetbuf(buf, sizeof(buf));
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
std::ios::sync_with_stdio(false);
|
|
|
|
|
|
2012-07-31 02:55:41 +03:00
|
|
|
|
settings.processEnvironment();
|
|
|
|
|
settings.loadConfFile();
|
2012-07-31 00:13:25 +03:00
|
|
|
|
|
2004-01-15 22:23:55 +02:00
|
|
|
|
/* Catch SIGINT. */
|
2010-01-12 14:22:38 +02:00
|
|
|
|
struct sigaction act;
|
2004-01-15 22:23:55 +02:00
|
|
|
|
act.sa_handler = sigintHandler;
|
2014-03-29 21:20:14 +02:00
|
|
|
|
sigemptyset(&act.sa_mask);
|
2004-01-15 22:23:55 +02:00
|
|
|
|
act.sa_flags = 0;
|
2010-01-12 14:22:38 +02:00
|
|
|
|
if (sigaction(SIGINT, &act, 0))
|
2004-01-15 22:23:55 +02:00
|
|
|
|
throw SysError("installing handler for SIGINT");
|
2010-01-12 14:22:38 +02:00
|
|
|
|
if (sigaction(SIGTERM, &act, 0))
|
2005-11-04 17:34:09 +02:00
|
|
|
|
throw SysError("installing handler for SIGTERM");
|
2010-01-12 14:22:38 +02:00
|
|
|
|
if (sigaction(SIGHUP, &act, 0))
|
2005-11-04 17:34:09 +02:00
|
|
|
|
throw SysError("installing handler for SIGHUP");
|
2004-01-15 22:23:55 +02:00
|
|
|
|
|
2004-05-13 22:14:49 +03:00
|
|
|
|
/* Ignore SIGPIPE. */
|
|
|
|
|
act.sa_handler = SIG_IGN;
|
|
|
|
|
act.sa_flags = 0;
|
2010-01-12 14:22:38 +02:00
|
|
|
|
if (sigaction(SIGPIPE, &act, 0))
|
2004-05-13 22:14:49 +03:00
|
|
|
|
throw SysError("ignoring SIGPIPE");
|
|
|
|
|
|
2010-01-12 14:22:38 +02:00
|
|
|
|
/* Reset SIGCHLD to its default. */
|
|
|
|
|
act.sa_handler = SIG_DFL;
|
|
|
|
|
act.sa_flags = 0;
|
|
|
|
|
if (sigaction(SIGCHLD, &act, 0))
|
|
|
|
|
throw SysError("resetting SIGCHLD");
|
|
|
|
|
|
2013-07-31 00:25:37 +03:00
|
|
|
|
/* Register a SIGSEGV handler to detect stack overflows. */
|
|
|
|
|
detectStackOverflow();
|
|
|
|
|
|
2004-09-09 17:16:02 +03:00
|
|
|
|
/* There is no privacy in the Nix system ;-) At least not for
|
|
|
|
|
now. In particular, store objects should be readable by
|
2012-10-04 00:30:45 +03:00
|
|
|
|
everybody. */
|
2004-09-09 17:16:02 +03:00
|
|
|
|
umask(0022);
|
|
|
|
|
|
2012-12-11 12:49:42 +02:00
|
|
|
|
/* Initialise the PRNG. */
|
|
|
|
|
struct timeval tv;
|
|
|
|
|
gettimeofday(&tv, 0);
|
|
|
|
|
srandom(tv.tv_usec);
|
|
|
|
|
|
2014-08-13 04:50:44 +03:00
|
|
|
|
if (char *pack = getenv("_NIX_OPTIONS"))
|
|
|
|
|
settings.unpack(pack);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void parseCmdLine(int argc, char * * argv,
|
|
|
|
|
std::function<bool(Strings::iterator & arg, const Strings::iterator & end)> parseArg)
|
|
|
|
|
{
|
2003-07-04 18:42:03 +03:00
|
|
|
|
/* Put the arguments in a vector. */
|
2014-08-13 05:03:05 +03:00
|
|
|
|
Strings args;
|
|
|
|
|
argc--; argv++;
|
2003-07-04 18:42:03 +03:00
|
|
|
|
while (argc--) args.push_back(*argv++);
|
2012-07-31 00:13:25 +03:00
|
|
|
|
|
2014-08-13 05:03:05 +03:00
|
|
|
|
/* Process default options. */
|
2003-12-01 17:55:05 +02:00
|
|
|
|
for (Strings::iterator i = args.begin(); i != args.end(); ++i) {
|
|
|
|
|
string arg = *i;
|
2014-08-13 05:03:05 +03:00
|
|
|
|
|
|
|
|
|
/* Expand compound dash options (i.e., `-qlf' -> `-q -l -f'). */
|
|
|
|
|
if (arg.length() > 2 && arg[0] == '-' && arg[1] != '-' && isalpha(arg[1])) {
|
|
|
|
|
*i = (string) "-" + arg[1];
|
|
|
|
|
auto next = i; ++next;
|
|
|
|
|
for (unsigned int j = 2; j < arg.length(); j++)
|
2003-12-01 17:55:05 +02:00
|
|
|
|
if (isalpha(arg[j]))
|
2014-08-13 05:03:05 +03:00
|
|
|
|
args.insert(next, (string) "-" + arg[j]);
|
|
|
|
|
else {
|
|
|
|
|
args.insert(next, string(arg, j));
|
2003-07-24 11:53:43 +03:00
|
|
|
|
break;
|
|
|
|
|
}
|
2014-08-13 05:03:05 +03:00
|
|
|
|
arg = *i;
|
|
|
|
|
}
|
2003-07-04 18:42:03 +03:00
|
|
|
|
|
2013-03-08 02:24:59 +02:00
|
|
|
|
if (arg == "--verbose" || arg == "-v") verbosity = (Verbosity) (verbosity + 1);
|
|
|
|
|
else if (arg == "--quiet") verbosity = verbosity > lvlError ? (Verbosity) (verbosity - 1) : lvlError;
|
2004-03-22 22:53:49 +02:00
|
|
|
|
else if (arg == "--log-type") {
|
2012-07-31 02:55:41 +03:00
|
|
|
|
string s = getArg(arg, i, args.end());
|
|
|
|
|
setLogType(s);
|
2004-05-12 17:20:32 +03:00
|
|
|
|
}
|
2004-08-18 15:19:06 +03:00
|
|
|
|
else if (arg == "--no-build-output" || arg == "-Q")
|
2012-07-31 02:55:41 +03:00
|
|
|
|
settings.buildVerbosity = lvlVomit;
|
2008-11-12 13:08:27 +02:00
|
|
|
|
else if (arg == "--print-build-trace")
|
2012-07-31 02:55:41 +03:00
|
|
|
|
settings.printBuildTrace = true;
|
2004-05-12 17:20:32 +03:00
|
|
|
|
else if (arg == "--keep-failed" || arg == "-K")
|
2012-07-31 02:55:41 +03:00
|
|
|
|
settings.keepFailed = true;
|
2004-06-25 18:36:09 +03:00
|
|
|
|
else if (arg == "--keep-going" || arg == "-k")
|
2012-07-31 02:55:41 +03:00
|
|
|
|
settings.keepGoing = true;
|
2004-06-28 13:42:57 +03:00
|
|
|
|
else if (arg == "--fallback")
|
2012-08-01 00:56:02 +03:00
|
|
|
|
settings.set("build-fallback", "true");
|
2006-12-08 17:44:00 +02:00
|
|
|
|
else if (arg == "--max-jobs" || arg == "-j")
|
2012-07-31 02:55:41 +03:00
|
|
|
|
settings.set("build-max-jobs", getArg(arg, i, args.end()));
|
2010-08-04 15:23:59 +03:00
|
|
|
|
else if (arg == "--cores")
|
2012-07-31 02:55:41 +03:00
|
|
|
|
settings.set("build-cores", getArg(arg, i, args.end()));
|
2004-10-25 17:38:23 +03:00
|
|
|
|
else if (arg == "--readonly-mode")
|
2012-07-31 02:55:41 +03:00
|
|
|
|
settings.readOnlyMode = true;
|
2006-12-08 17:44:00 +02:00
|
|
|
|
else if (arg == "--max-silent-time")
|
2012-07-31 02:55:41 +03:00
|
|
|
|
settings.set("build-max-silent-time", getArg(arg, i, args.end()));
|
2011-06-30 18:19:13 +03:00
|
|
|
|
else if (arg == "--timeout")
|
2012-07-31 02:55:41 +03:00
|
|
|
|
settings.set("build-timeout", getArg(arg, i, args.end()));
|
2007-11-16 18:15:26 +02:00
|
|
|
|
else if (arg == "--no-build-hook")
|
2012-07-31 02:55:41 +03:00
|
|
|
|
settings.useBuildHook = false;
|
2009-06-30 16:28:29 +03:00
|
|
|
|
else if (arg == "--show-trace")
|
2013-11-12 13:51:59 +02:00
|
|
|
|
settings.showTrace = true;
|
2013-12-20 14:19:10 +02:00
|
|
|
|
else if (arg == "--no-gc-warning")
|
|
|
|
|
gcWarning = false;
|
2009-02-27 13:04:41 +02:00
|
|
|
|
else if (arg == "--option") {
|
2014-08-20 18:00:17 +03:00
|
|
|
|
++i; if (i == args.end()) throw UsageError("‘--option’ requires two arguments");
|
2009-02-27 13:04:41 +02:00
|
|
|
|
string name = *i;
|
2014-08-20 18:00:17 +03:00
|
|
|
|
++i; if (i == args.end()) throw UsageError("‘--option’ requires two arguments");
|
2009-02-27 13:04:41 +02:00
|
|
|
|
string value = *i;
|
2012-07-31 02:55:41 +03:00
|
|
|
|
settings.set(name, value);
|
2009-02-27 13:04:41 +02:00
|
|
|
|
}
|
2014-08-13 04:50:44 +03:00
|
|
|
|
else {
|
|
|
|
|
if (!parseArg(i, args.end()))
|
2014-08-20 18:00:17 +03:00
|
|
|
|
throw UsageError(format("unrecognised option ‘%1%’") % *i);
|
2014-05-23 15:43:55 +03:00
|
|
|
|
}
|
2003-12-01 17:55:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
2012-07-31 02:55:41 +03:00
|
|
|
|
settings.update();
|
2014-08-13 04:50:44 +03:00
|
|
|
|
}
|
2012-07-31 02:55:41 +03:00
|
|
|
|
|
2006-03-01 18:36:35 +02:00
|
|
|
|
|
2014-08-13 04:50:44 +03:00
|
|
|
|
void printVersion(const string & programName)
|
|
|
|
|
{
|
|
|
|
|
std::cout << format("%1% (Nix) %2%") % programName % nixVersion << std::endl;
|
|
|
|
|
throw Exit();
|
2003-07-04 18:42:03 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2012-10-03 23:37:06 +03:00
|
|
|
|
void showManPage(const string & name)
|
|
|
|
|
{
|
2014-07-31 11:31:17 +03:00
|
|
|
|
restoreSIGPIPE();
|
|
|
|
|
execlp("man", "man", name.c_str(), NULL);
|
2014-08-20 18:00:17 +03:00
|
|
|
|
throw SysError(format("command ‘man %1%’ failed") % name.c_str());
|
2012-10-03 23:37:06 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-13 04:50:44 +03:00
|
|
|
|
int handleExceptions(const string & programName, std::function<void()> fun)
|
2003-07-04 18:42:03 +03:00
|
|
|
|
{
|
2014-08-20 17:01:16 +03:00
|
|
|
|
string error = ANSI_RED "error:" ANSI_NORMAL " ";
|
2003-07-04 18:42:03 +03:00
|
|
|
|
try {
|
2004-05-11 21:05:44 +03:00
|
|
|
|
try {
|
2014-08-13 04:50:44 +03:00
|
|
|
|
fun();
|
2004-05-11 21:05:44 +03: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. */
|
|
|
|
|
blockInt = 1; /* ignore further SIGINTs */
|
|
|
|
|
_isInterrupted = 0;
|
|
|
|
|
throw;
|
|
|
|
|
}
|
2014-08-13 04:50:44 +03:00
|
|
|
|
} catch (Exit & e) {
|
|
|
|
|
return e.status;
|
2003-07-04 18:42:03 +03:00
|
|
|
|
} catch (UsageError & e) {
|
2012-07-31 00:13:25 +03:00
|
|
|
|
printMsg(lvlError,
|
2014-10-14 12:41:04 +03:00
|
|
|
|
format(error + "%1%\nTry ‘%2% --help’ for more information.")
|
2014-08-13 04:50:44 +03:00
|
|
|
|
% e.what() % programName);
|
2003-07-04 18:42:03 +03:00
|
|
|
|
return 1;
|
2007-08-12 03:29:28 +03:00
|
|
|
|
} catch (BaseError & e) {
|
2014-08-20 17:01:16 +03:00
|
|
|
|
printMsg(lvlError, format(error + "%1%%2%") % (settings.showTrace ? e.prefix() : "") % e.msg());
|
2013-11-12 13:51:59 +02:00
|
|
|
|
if (e.prefix() != "" && !settings.showTrace)
|
2014-08-20 18:00:17 +03:00
|
|
|
|
printMsg(lvlError, "(use ‘--show-trace’ to show detailed location information)");
|
2010-12-13 18:53:23 +02:00
|
|
|
|
return e.status;
|
2013-10-02 15:34:36 +03:00
|
|
|
|
} catch (std::bad_alloc & e) {
|
2014-08-20 17:01:16 +03:00
|
|
|
|
printMsg(lvlError, error + "out of memory");
|
2013-10-02 15:34:36 +03:00
|
|
|
|
return 1;
|
2006-09-05 00:06:23 +03:00
|
|
|
|
} catch (std::exception & e) {
|
2014-08-20 17:01:16 +03:00
|
|
|
|
printMsg(lvlError, error + e.what());
|
2003-07-04 18:42:03 +03:00
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-13 04:50:44 +03:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-08-20 16:12:58 +03:00
|
|
|
|
RunPager::RunPager()
|
|
|
|
|
{
|
2014-12-10 19:16:05 +02:00
|
|
|
|
if (!isatty(STDOUT_FILENO)) return;
|
2015-01-02 16:26:56 +02:00
|
|
|
|
char * pager = getenv("NIX_PAGER");
|
|
|
|
|
if (!pager) pager = getenv("PAGER");
|
|
|
|
|
if (pager && ((string) pager == "" || (string) pager == "cat")) return;
|
2014-08-20 16:12:58 +03:00
|
|
|
|
|
|
|
|
|
/* Ignore SIGINT. The pager will handle it (and we'll get
|
|
|
|
|
SIGPIPE). */
|
|
|
|
|
struct sigaction act;
|
|
|
|
|
act.sa_handler = SIG_IGN;
|
|
|
|
|
act.sa_flags = 0;
|
|
|
|
|
sigemptyset(&act.sa_mask);
|
|
|
|
|
if (sigaction(SIGINT, &act, 0)) throw SysError("ignoring SIGINT");
|
|
|
|
|
|
|
|
|
|
restoreSIGPIPE();
|
|
|
|
|
|
|
|
|
|
Pipe toPager;
|
|
|
|
|
toPager.create();
|
|
|
|
|
|
2014-12-10 14:48:50 +02:00
|
|
|
|
pid = startProcess([&]() {
|
|
|
|
|
if (dup2(toPager.readSide, STDIN_FILENO) == -1)
|
|
|
|
|
throw SysError("dupping stdin");
|
|
|
|
|
if (!getenv("LESS"))
|
|
|
|
|
setenv("LESS", "FRSXMK", 1);
|
2015-01-02 16:26:56 +02:00
|
|
|
|
if (pager)
|
|
|
|
|
execl("/bin/sh", "sh", "-c", pager, NULL);
|
2014-12-10 19:16:05 +02:00
|
|
|
|
execlp("pager", "pager", NULL);
|
|
|
|
|
execlp("less", "less", NULL);
|
|
|
|
|
execlp("more", "more", NULL);
|
2014-12-10 14:48:50 +02:00
|
|
|
|
throw SysError(format("executing ‘%1%’") % pager);
|
|
|
|
|
});
|
2014-08-20 16:12:58 +03:00
|
|
|
|
|
|
|
|
|
if (dup2(toPager.writeSide, STDOUT_FILENO) == -1)
|
|
|
|
|
throw SysError("dupping stdout");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RunPager::~RunPager()
|
|
|
|
|
{
|
2014-12-12 15:05:23 +02:00
|
|
|
|
try {
|
|
|
|
|
if (pid != -1) {
|
|
|
|
|
std::cout.flush();
|
|
|
|
|
close(STDOUT_FILENO);
|
|
|
|
|
pid.wait(true);
|
|
|
|
|
}
|
|
|
|
|
} catch (...) {
|
|
|
|
|
ignoreException();
|
2014-08-20 16:12:58 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-07-04 18:42:03 +03:00
|
|
|
|
}
|