uts: move to C++
authorRobert Swiecki <robert@swiecki.net>
Fri, 9 Feb 2018 16:59:51 +0000 (17:59 +0100)
committerRobert Swiecki <robert@swiecki.net>
Fri, 9 Feb 2018 16:59:51 +0000 (17:59 +0100)
Makefile
contain.cc
uts.c [deleted file]
uts.cc [new file with mode: 0644]
uts.h

index ba6ccd1426d26e373109b6380f41ccb2907a4136..4df5306f178c1146bee2cd3ab6e3cf3a2ddfd719 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -35,8 +35,8 @@ LDFLAGS += -pie -Wl,-z,noexecstack -lpthread $(shell pkg-config --libs protobuf)
 
 BIN = nsjail
 LIBS = kafel/libkafel.a
-SRCS_C = log.c cgroup.c mount.c user.c util.c uts.c
-SRCS_CXX = caps.cc cmdline.cc config.cc contain.cc cpu.cc net.cc nsjail.cc pid.cc sandbox.cc subproc.cc
+SRCS_C = log.c cgroup.c mount.c user.c util.c
+SRCS_CXX = caps.cc cmdline.cc config.cc contain.cc cpu.cc net.cc nsjail.cc pid.cc sandbox.cc subproc.cc uts.cc
 SRCS_PROTO = config.proto
 SRCS_PB_CXX = $(SRCS_PROTO:.proto=.pb.cc)
 SRCS_PB_H = $(SRCS_PROTO:.proto=.pb.h)
@@ -102,14 +102,13 @@ cgroup.o: cgroup.h nsjail.h log.h util.h
 mount.o: mount.h nsjail.h common.h log.h subproc.h util.h
 user.o: user.h nsjail.h common.h log.h subproc.h util.h
 util.o: util.h nsjail.h common.h log.h
-uts.o: uts.h nsjail.h log.h
 caps.o: caps.h nsjail.h common.h log.h util.h
 cmdline.o: cmdline.h nsjail.h common.h log.h mount.h user.h util.h caps.h
 cmdline.o: config.h sandbox.h
 config.o: common.h config.h nsjail.h log.h mount.h user.h util.h caps.h
 config.o: cmdline.h
-contain.o: contain.h nsjail.h cgroup.h log.h mount.h user.h uts.h caps.h
-contain.o: cpu.h net.h pid.h
+contain.o: contain.h nsjail.h cgroup.h log.h mount.h user.h caps.h cpu.h
+contain.o: net.h pid.h uts.h
 cpu.o: cpu.h nsjail.h log.h util.h
 net.o: net.h nsjail.h log.h subproc.h
 nsjail.o: nsjail.h cmdline.h common.h log.h net.h subproc.h util.h
@@ -117,3 +116,4 @@ pid.o: pid.h nsjail.h log.h subproc.h
 sandbox.o: sandbox.h nsjail.h kafel/include/kafel.h log.h
 subproc.o: subproc.h nsjail.h contain.h net.h sandbox.h cgroup.h common.h
 subproc.o: log.h user.h util.h
+uts.o: uts.h nsjail.h log.h
index 4851150a14e5aad0754b4b44861043e34153e310..bcc039f654b4989a16a0d87ebf1c519e7bdcde0f 100644 (file)
@@ -42,13 +42,13 @@ extern "C" {
 #include "log.h"
 #include "mount.h"
 #include "user.h"
-#include "uts.h"
 }
 
 #include "caps.h"
 #include "cpu.h"
 #include "net.h"
 #include "pid.h"
+#include "uts.h"
 
 namespace contain {
 
@@ -58,7 +58,7 @@ static bool containInitPidNs(struct nsjconf_t* nsjconf) { return pid::initNs(nsj
 
 static bool containInitNetNs(struct nsjconf_t* nsjconf) { return net::initNsFromChild(nsjconf); }
 
-static bool containInitUtsNs(struct nsjconf_t* nsjconf) { return utsInitNs(nsjconf); }
+static bool containInitUtsNs(struct nsjconf_t* nsjconf) { return uts::initNs(nsjconf); }
 
 static bool containInitCgroupNs(void) { return cgroupInitNs(); }
 
diff --git a/uts.c b/uts.c
deleted file mode 100644 (file)
index 6f8d1d7..0000000
--- a/uts.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
-
-   nsjail - CLONE_NEWUTS routines
-   -----------------------------------------
-
-   Copyright 2014 Google Inc. All Rights Reserved.
-
-   Licensed under the Apache License, Version 2.0 (the "License");
-   you may not use this file except in compliance with the License.
-   You may obtain a copy of the License at
-
-     http://www.apache.org/licenses/LICENSE-2.0
-
-   Unless required by applicable law or agreed to in writing, software
-   distributed under the License is distributed on an "AS IS" BASIS,
-   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-   See the License for the specific language governing permissions and
-   limitations under the License.
-
-*/
-
-#include "uts.h"
-
-#include <string.h>
-#include <unistd.h>
-
-#include "log.h"
-
-bool utsInitNs(struct nsjconf_t* nsjconf) {
-       if (nsjconf->clone_newuts == false) {
-               return true;
-       }
-
-       LOG_D("Setting hostname to '%s'", nsjconf->hostname);
-       if (sethostname(nsjconf->hostname, strlen(nsjconf->hostname)) == -1) {
-               PLOG_E("sethostname('%s')", nsjconf->hostname);
-               return false;
-       }
-       return true;
-}
diff --git a/uts.cc b/uts.cc
new file mode 100644 (file)
index 0000000..c9129e7
--- /dev/null
+++ b/uts.cc
@@ -0,0 +1,46 @@
+/*
+
+   nsjail - CLONE_NEWUTS routines
+   -----------------------------------------
+
+   Copyright 2014 Google Inc. All Rights Reserved.
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
+*/
+
+#include "uts.h"
+
+#include <string.h>
+#include <unistd.h>
+
+extern "C" {
+#include "log.h"
+}
+
+namespace uts {
+
+bool initNs(struct nsjconf_t* nsjconf) {
+       if (nsjconf->clone_newuts == false) {
+               return true;
+       }
+
+       LOG_D("Setting hostname to '%s'", nsjconf->hostname);
+       if (sethostname(nsjconf->hostname, strlen(nsjconf->hostname)) == -1) {
+               PLOG_E("sethostname('%s')", nsjconf->hostname);
+               return false;
+       }
+       return true;
+}
+
+}  // namespace uts
diff --git a/uts.h b/uts.h
index 636118b4d4c3aab5a68ebdb39affac280e7ceec8..ba423272088d7a439e437ed4ec1102b0c60c74e1 100644 (file)
--- a/uts.h
+++ b/uts.h
 
 #include "nsjail.h"
 
-bool utsInitNs(struct nsjconf_t* nsjconf);
+namespace uts {
+
+bool initNs(struct nsjconf_t* nsjconf);
+
+}  // namespace uts
 
 #endif /* NS_UTS_H */