about summary refs log tree commit diff
path: root/src/libmain/setuid-common.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/libmain/setuid-common.hh')
-rw-r--r--src/libmain/setuid-common.hh22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/libmain/setuid-common.hh b/src/libmain/setuid-common.hh
new file mode 100644
index 000000000000..a3e840996161
--- /dev/null
+++ b/src/libmain/setuid-common.hh
@@ -0,0 +1,22 @@
+/* Code shared between libmain and nix-setuid-helper. */
+
+extern char * * environ;
+
+
+namespace nix {
+    
+
+void setuidCleanup()
+{
+    /* Don't trust the environment. */
+    environ = 0;
+
+    /* Make sure that file descriptors 0, 1, 2 are open. */
+    for (int fd = 0; fd <= 2; ++fd) {
+        struct stat st;
+        if (fstat(fd, &st) == -1) abort();
+    }
+}
+
+ 
+}