about summary refs log tree commit diff
path: root/src/libstore/build.cc
diff options
context:
space:
mode:
authorGraham Christensen <graham@grahamc.com>2019-05-11T20·35-0400
committerGraham Christensen <graham@grahamc.com>2019-05-12T17·17-0400
commitb4a05edbfe49f87555fd284dfb0d6c56ed43217d (patch)
tree447fd9d1be15f15f1cb0c8020b63b95acb74933b /src/libstore/build.cc
parentdde8eeb39ae9fb73011462c74e5fa6405e432147 (diff)
runProgram: support gid, uid, chdir
Diffstat (limited to 'src/libstore/build.cc')
-rw-r--r--src/libstore/build.cc36
1 files changed, 16 insertions, 20 deletions
diff --git a/src/libstore/build.cc b/src/libstore/build.cc
index 8397cd0d1d..8902e22bd8 100644
--- a/src/libstore/build.cc
+++ b/src/libstore/build.cc
@@ -465,26 +465,22 @@ void handleDiffHook(bool allowVfork, uid_t uid, uid_t gid, Path tryA, Path tryB,
 {
     auto diffHook = settings.diffHook;
     if (diffHook != "" && settings.runDiffHook) {
-        auto wrapper = [&]() {
-            if (chdir("/") == -1)
-                throw SysError("chdir / failed");
-            if (setgid(gid) == -1)
-                throw SysError("setgid failed");
-            if (setgroups(0, 0) == -1)
-                throw SysError("setgroups failed");
-            if (setuid(uid) == -1)
-                throw SysError("setuid failed");
-
-            try {
-                auto diff = runProgram(diffHook, true, {tryA, tryB, drvPath, tmpDir});
-                if (diff != "")
-                    printError(chomp(diff));
-            } catch (Error & error) {
-                printError("diff hook execution failed: %s", error.what());
-            }
-        };
-
-        doFork(allowVfork, wrapper);
+        try {
+            RunOptions diffHookOptions(diffHook,{tryA, tryB, drvPath, tmpDir});
+            diffHookOptions.searchPath = true;
+            diffHookOptions.uid = uid;
+            diffHookOptions.gid = gid;
+            diffHookOptions.chdir = "/";
+
+            auto diffRes = runProgram(diffHookOptions);
+            if (!statusOk(diffRes.first))
+                throw ExecError(diffRes.first, fmt("diff-hook program '%1%' %2%", diffHook, statusToString(diffRes.first)));
+
+            if (diffRes.second != "")
+                printError(chomp(diffRes.second));
+        } catch (Error & error) {
+            printError("diff hook execution failed: %s", error.what());
+        }
     }
 }