Browse Source

Add Setuid.c to make Setuid get tested only once

Caleb James DeLisle 3 years ago
parent
commit
6cd2b27ebc
5 changed files with 61 additions and 23 deletions
  1. 33 0
      util/Setuid.c
  2. 2 21
      util/Setuid.h
  3. 1 1
      util/Setuid_dummy.c
  4. 24 0
      util/Setuid_impl.h
  5. 1 1
      util/Setuid_linux.c

+ 33 - 0
util/Setuid.c

@@ -0,0 +1,33 @@
+/* vim: set expandtab ts=4 sw=4: */
+/*
+ * You may redistribute this program and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+#include "util/Setuid.h"
+#include "util/Js.h"
+
+Js({
+    const done = js.async();
+    const impl = "util/Setuid_" + builder.config.systemName + ".c";
+    require("fs").exists(impl, function (exists) {
+        var out = "";
+        if (!exists) {
+            console.log("No setuid keepNetAdmin");
+            js.linkerDependency("util/Setuid_dummy.c");
+        } else {
+            js.linkerDependency(impl);
+            console.log("Has setuid keepNetAdmin");
+        }
+        done();
+    });
+})
+

+ 2 - 21
util/Setuid.h

@@ -15,27 +15,8 @@
 #ifndef Setuid_H
 #define Setuid_H
 
-#include "memory/Allocator.h"
-#include "exception/Except.h"
+#include "util/Setuid_impl.h"
 #include "util/Linker.h"
-
-Er_DEFUN(void Setuid_preSetuid(struct Allocator* alloc));
-Er_DEFUN(void Setuid_postSetuid(struct Allocator* alloc));
-
-Js({
-    const done = js.async();
-    const impl = "util/Setuid_" + builder.config.systemName + ".c";
-    require("fs").exists(impl, function (exists) {
-        var out = "";
-        if (!exists) {
-            console.log("No setuid keepNetAdmin");
-            js.linkerDependency("util/Setuid_dummy.c");
-        } else {
-            js.linkerDependency(impl);
-            console.log("Has setuid keepNetAdmin");
-        }
-        done();
-    });
-})
+Linker_require("util/Setuid.c")
 
 #endif

+ 1 - 1
util/Setuid_dummy.c

@@ -12,7 +12,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
-#include "util/Setuid.h"
+#include "util/Setuid_impl.h"
 #include "memory/Allocator.h"
 #include "exception/Er.h"
 

+ 24 - 0
util/Setuid_impl.h

@@ -0,0 +1,24 @@
+/* vim: set expandtab ts=4 sw=4: */
+/*
+ * You may redistribute this program and/or modify it under the terms of
+ * the GNU General Public License as published by the Free Software Foundation,
+ * either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <https://www.gnu.org/licenses/>.
+ */
+#ifndef Setuid_impl_H
+#define Setuid_impl_H
+
+#include "memory/Allocator.h"
+#include "exception/Except.h"
+
+Er_DEFUN(void Setuid_preSetuid(struct Allocator* alloc));
+Er_DEFUN(void Setuid_postSetuid(struct Allocator* alloc));
+
+#endif

+ 1 - 1
util/Setuid_linux.c

@@ -12,7 +12,7 @@
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
  */
-#include "util/Setuid.h"
+#include "util/Setuid_impl.h"
 #include "memory/Allocator.h"
 #include "exception/Except.h"