Revert "Use posix_spawn to run the pager"

This reverts commit d34d2b2bbf.
This commit is contained in:
Eelco Dolstra 2014-12-10 13:48:50 +01:00
parent 2e98703c0c
commit ad332e1718
3 changed files with 10 additions and 39 deletions

View file

@ -15,7 +15,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <signal.h> #include <signal.h>
#include <spawn.h>
extern char * * environ; extern char * * environ;
@ -308,35 +307,14 @@ RunPager::RunPager()
Pipe toPager; Pipe toPager;
toPager.create(); toPager.create();
// FIXME: should do this in the child environment. pid = startProcess([&]() {
if (!getenv("LESS")) if (dup2(toPager.readSide, STDIN_FILENO) == -1)
setenv("LESS", "FRSXMK", 1); throw SysError("dupping stdin");
if (!getenv("LESS"))
/* Start the pager using posix_spawn. */ setenv("LESS", "FRSXMK", 1);
pid_t pid_; execl("/bin/sh", "sh", "-c", pager.c_str(), NULL);
const char * argv[] = { "sh", "-c", pager.c_str(), 0 }; throw SysError(format("executing %1%") % pager);
});
posix_spawn_file_actions_t fileActions;
int err = posix_spawn_file_actions_init(&fileActions);
if (err) throw SysError(err, "creating POSIX file actions");
err = posix_spawn_file_actions_adddup2(&fileActions, toPager.readSide, STDIN_FILENO);
if (err) throw SysError(err, "adding to POSIX file actions");
posix_spawnattr_t spawnAttrs;
err = posix_spawnattr_init(&spawnAttrs);
if (err) throw SysError(err, "creating POSIX spawn attrs");
#ifdef POSIX_SPAWN_USEVFORK
err = posix_spawnattr_setflags(&spawnAttrs, POSIX_SPAWN_USEVFORK);
if (err) throw SysError(err, "setting POSIX spawn attr flag");
#endif
err = posix_spawn(&pid_, "/bin/sh", &fileActions, &spawnAttrs, (char * const *) argv, environ);
posix_spawn_file_actions_destroy(&fileActions);
posix_spawnattr_destroy(&spawnAttrs);
if (err) throw SysError(err, format("running %1%") % pager);
pid = pid_;
if (dup2(toPager.writeSide, STDOUT_FILENO) == -1) if (dup2(toPager.writeSide, STDOUT_FILENO) == -1)
throw SysError("dupping stdout"); throw SysError("dupping stdout");

View file

@ -73,7 +73,6 @@ class SysError : public Error
public: public:
int errNo; int errNo;
SysError(const FormatOrString & fs); SysError(const FormatOrString & fs);
SysError(int errNo, const FormatOrString & fs);
}; };

View file

@ -45,14 +45,8 @@ BaseError & BaseError::addPrefix(const FormatOrString & fs)
SysError::SysError(const FormatOrString & fs) SysError::SysError(const FormatOrString & fs)
: SysError(errno, fs) : Error(format("%1%: %2%") % fs.s % strerror(errno))
{ , errNo(errno)
}
SysError::SysError(int errNo, const FormatOrString & fs)
: Error(format("%1%: %2%") % fs.s % strerror(errNo))
, errNo(errNo)
{ {
} }