Files
lix/lix/libexec/run-pager.cc
T
eldritch horrors d9187b4ee0 libmain: run pagers with a libexec helper
this is mostly a test and example for the libexec helper infrastructure,
but it also lets us simplify pager launching until we we can more easily
handle executable-not-found errors the launch fallbacks would cause when
using runProgram2 instead of fork. ideally we'd use `posix_spawn` later.

fixes #1104

Change-Id: Ia33cc12e8a9d60ffad6f5c055bb1b8b596810e64
2026-01-20 14:02:12 +00:00

20 lines
497 B
C++

#include "common.hh"
LIBEXEC_HELPER(0)
int helperMain(const char * name, std::span<char *> args) noexcept
{
auto pager = args.empty() ? nullptr : args[0];
if (!getenv("LESS")) {
setenv("LESS", "FRSXMK", 1);
}
if (pager) {
execl("/bin/sh", "sh", "-c", pager, nullptr);
}
execlp("pager", "pager", nullptr);
execlp("less", "less", nullptr);
execlp("more", "more", nullptr);
die("could not find a pager to run, please set PAGER or NIX_PAGER");
}