BIN = nsjail
LIBS = kafel/libkafel.a
-SRCS_C = caps.c log.c cgroup.c mount.c pid.c user.c util.c uts.c cpu.c
-SRCS_CXX = cmdline.cc config.cc contain.cc net.cc nsjail.cc sandbox.cc subproc.cc
+SRCS_C = caps.c log.c cgroup.c mount.c pid.c user.c util.c uts.c
+SRCS_CXX = cmdline.cc config.cc contain.cc cpu.cc net.cc nsjail.cc sandbox.cc subproc.cc
SRCS_PROTO = config.proto
SRCS_PB_CXX = $(SRCS_PROTO:.proto=.pb.cc)
SRCS_PB_H = $(SRCS_PROTO:.proto=.pb.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
-cpu.o: cpu.h nsjail.h log.h util.h
cmdline.o: cmdline.h nsjail.h caps.h common.h log.h mount.h user.h util.h
cmdline.o: config.h sandbox.h
config.o: common.h caps.h nsjail.h config.h log.h mount.h user.h util.h
config.o: cmdline.h
-contain.o: contain.h nsjail.h caps.h cgroup.h cpu.h log.h mount.h pid.h
-contain.o: user.h uts.h net.h
+contain.o: contain.h nsjail.h caps.h cgroup.h log.h mount.h pid.h user.h
+contain.o: uts.h cpu.h net.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
sandbox.o: sandbox.h nsjail.h kafel/include/kafel.h log.h
extern "C" {
#include "caps.h"
#include "cgroup.h"
-#include "cpu.h"
#include "log.h"
#include "mount.h"
#include "pid.h"
#include "uts.h"
}
+#include "cpu.h"
#include "net.h"
namespace contain {
static bool containInitMountNs(struct nsjconf_t* nsjconf) { return mountInitNs(nsjconf); }
-static bool containCPU(struct nsjconf_t* nsjconf) { return cpuInit(nsjconf); }
+static bool containCPU(struct nsjconf_t* nsjconf) { return cpu::initCpu(nsjconf); }
static bool containSetLimits(struct nsjconf_t* nsjconf) {
struct rlimit64 rl;
#include <string.h>
#include <unistd.h>
+extern "C" {
#include "log.h"
#include "util.h"
+}
+
+namespace cpu {
-static void cpuSetRandomCpu(cpu_set_t* mask, size_t mask_size, size_t cpu_num) {
+static void setRandomCpu(cpu_set_t* mask, size_t mask_size, size_t cpu_num) {
if ((size_t)CPU_COUNT_S(mask_size, mask) >= cpu_num) {
LOG_F(
"Number of CPUs in the mask '%d' is bigger than number of available CPUs '%zu'",
}
}
-bool cpuInit(struct nsjconf_t* nsjconf) {
+bool initCpu(struct nsjconf_t* nsjconf) {
if (nsjconf->num_cpus < 0) {
PLOG_W("sysconf(_SC_NPROCESSORS_ONLN) returned %ld", nsjconf->num_cpus);
return false;
CPU_ZERO_S(mask_size, mask);
for (size_t i = 0; i < nsjconf->max_cpus; i++) {
- cpuSetRandomCpu(mask, mask_size, nsjconf->num_cpus);
+ setRandomCpu(mask, mask_size, nsjconf->num_cpus);
}
if (sched_setaffinity(0, mask_size, mask) == -1) {
return true;
}
+
+} // namespace cpu
#include "nsjail.h"
-bool cpuInit(struct nsjconf_t* nsjconf);
+namespace cpu {
+
+bool initCpu(struct nsjconf_t* nsjconf);
+
+} // namespace cpu
#endif /* NS_CPU_H */