about summary refs log tree commit diff
path: root/src/libmain/shared.cc
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2014-12-10T12·48+0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2014-12-10T12·48+0100
commitad332e17189668d18aeeea2f61384f749d428d6a (patch)
treeeb6770d0795985c71b870960c20bc8058eb2a95b /src/libmain/shared.cc
parent2e98703c0ce2ae0924359cd510e2de1c71cb000c (diff)
Revert "Use posix_spawn to run the pager"
This reverts commit d34d2b2bbf784c0bb420a50905af25e02c6e4989.
Diffstat (limited to 'src/libmain/shared.cc')
-rw-r--r--src/libmain/shared.cc38
1 files changed, 8 insertions, 30 deletions
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index ef4ea370622b..1d50346a1bf8 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -15,7 +15,6 @@
 #include <sys/stat.h>
 #include <unistd.h>
 #include <signal.h>
-#include <spawn.h>
 
 extern char * * environ;
 
@@ -308,35 +307,14 @@ RunPager::RunPager()
     Pipe toPager;
     toPager.create();
 
-    // FIXME: should do this in the child environment.
-    if (!getenv("LESS"))
-        setenv("LESS", "FRSXMK", 1);
-
-    /* Start the pager using posix_spawn. */
-    pid_t pid_;
-    const char * argv[] = { "sh", "-c", pager.c_str(), 0 };
-
-    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_;
+    pid = startProcess([&]() {
+        if (dup2(toPager.readSide, STDIN_FILENO) == -1)
+            throw SysError("dupping stdin");
+        if (!getenv("LESS"))
+            setenv("LESS", "FRSXMK", 1);
+        execl("/bin/sh", "sh", "-c", pager.c_str(), NULL);
+        throw SysError(format("executing ‘%1%’") % pager);
+    });
 
     if (dup2(toPager.writeSide, STDOUT_FILENO) == -1)
         throw SysError("dupping stdout");