diff options
Diffstat (limited to 'src/libmain')
-rw-r--r-- | src/libmain/shared.cc | 27 | ||||
-rw-r--r-- | src/libmain/stack.cc | 4 |
2 files changed, 22 insertions, 9 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index c4b5c210d5be..c83e997b2307 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -11,11 +11,14 @@ #include <exception> #include <algorithm> +#include <cstdlib> #include <sys/time.h> #include <sys/stat.h> #include <unistd.h> #include <signal.h> +extern char * * environ; + namespace nix { @@ -289,8 +292,10 @@ int handleExceptions(const string & programName, std::function<void()> fun) RunPager::RunPager() { - string pager = getEnv("PAGER"); - if (!isatty(STDOUT_FILENO) || pager.empty()) return; + if (!isatty(STDOUT_FILENO)) return; + char * pager = getenv("NIX_PAGER"); + if (!pager) pager = getenv("PAGER"); + if (pager && ((string) pager == "" || (string) pager == "cat")) return; /* Ignore SIGINT. The pager will handle it (and we'll get SIGPIPE). */ @@ -310,7 +315,11 @@ RunPager::RunPager() throw SysError("dupping stdin"); if (!getenv("LESS")) setenv("LESS", "FRSXMK", 1); - execl("/bin/sh", "sh", "-c", pager.c_str(), NULL); + if (pager) + execl("/bin/sh", "sh", "-c", pager, NULL); + execlp("pager", "pager", NULL); + execlp("less", "less", NULL); + execlp("more", "more", NULL); throw SysError(format("executing ‘%1%’") % pager); }); @@ -321,10 +330,14 @@ RunPager::RunPager() RunPager::~RunPager() { - if (pid != -1) { - std::cout.flush(); - close(STDOUT_FILENO); - pid.wait(true); + try { + if (pid != -1) { + std::cout.flush(); + close(STDOUT_FILENO); + pid.wait(true); + } + } catch (...) { + ignoreException(); } } diff --git a/src/libmain/stack.cc b/src/libmain/stack.cc index 64df95547e0b..41b617d98be2 100644 --- a/src/libmain/stack.cc +++ b/src/libmain/stack.cc @@ -18,7 +18,7 @@ static void sigsegvHandler(int signo, siginfo_t * info, void * ctx) the stack pointer. Unfortunately, getting the stack pointer is not portable. */ bool haveSP = true; - char * sp; + char * sp = 0; #if defined(__x86_64__) && defined(REG_RSP) sp = (char *) ((ucontext *) ctx)->uc_mcontext.gregs[REG_RSP]; #elif defined(REG_ESP) @@ -32,7 +32,7 @@ static void sigsegvHandler(int signo, siginfo_t * info, void * ctx) if (diff < 0) diff = -diff; if (diff < 4096) { char msg[] = "error: stack overflow (possible infinite recursion)\n"; - write(2, msg, strlen(msg)); + (void) write(2, msg, strlen(msg)); _exit(1); // maybe abort instead? } } |