@@ -64,18 +64,19 @@ static bool addPidToTaskList(const std::string& cgroup_path, pid_t pid) {
6464 return writeToCgroup (tasks_path, pid_str, " '" + tasks_path + " ' task list" );
6565}
6666
67- static bool initNsFromParentMem (nsjconf_t * nsjconf , pid_t pid) {
68- size_t memsw_max = nsjconf-> cgroup_mem_memsw_max ;
69- if (nsjconf-> cgroup_mem_swap_max >= (ssize_t )0 ) {
70- memsw_max = nsjconf-> cgroup_mem_swap_max + nsjconf-> cgroup_mem_max ;
67+ static bool initNsFromParentMem (nsj_t * nsj , pid_t pid) {
68+ size_t memsw_max = nsj-> njc . cgroup_mem_memsw_max () ;
69+ if (nsj-> njc . cgroup_mem_swap_max () >= (ssize_t )0 ) {
70+ memsw_max = nsj-> njc . cgroup_mem_swap_max () + nsj-> njc . cgroup_mem_max () ;
7171 }
7272
73- if (nsjconf-> cgroup_mem_max == (size_t )0 && memsw_max == (size_t )0 ) {
73+ if (nsj-> njc . cgroup_mem_max () == (size_t )0 && memsw_max == (size_t )0 ) {
7474 return true ;
7575 }
7676
77- std::string mem_cgroup_path = nsjconf->cgroup_mem_mount + ' /' + nsjconf->cgroup_mem_parent +
78- " /NSJAIL." + std::to_string (pid);
77+ std::string mem_cgroup_path = nsj->njc .cgroup_mem_mount () + ' /' +
78+ nsj->njc .cgroup_mem_parent () + " /NSJAIL." +
79+ std::to_string (pid);
7980 RETURN_ON_FAILURE (createCgroup (mem_cgroup_path, pid));
8081
8182 /*
@@ -84,8 +85,8 @@ static bool initNsFromParentMem(nsjconf_t* nsjconf, pid_t pid) {
8485 RETURN_ON_FAILURE (writeToCgroup (
8586 mem_cgroup_path + " /memory.oom_control" , " 0" , " memory cgroup oom control" ));
8687
87- if (nsjconf-> cgroup_mem_max > (size_t )0 ) {
88- std::string mem_max_str = std::to_string (nsjconf-> cgroup_mem_max );
88+ if (nsj-> njc . cgroup_mem_max () > (size_t )0 ) {
89+ std::string mem_max_str = std::to_string (nsj-> njc . cgroup_mem_max () );
8990 RETURN_ON_FAILURE (writeToCgroup (mem_cgroup_path + " /memory.limit_in_bytes" ,
9091 mem_max_str, " memory cgroup max limit" ));
9192 }
@@ -99,37 +100,37 @@ static bool initNsFromParentMem(nsjconf_t* nsjconf, pid_t pid) {
99100 return addPidToTaskList (mem_cgroup_path, pid);
100101}
101102
102- static bool initNsFromParentPids (nsjconf_t * nsjconf , pid_t pid) {
103- if (nsjconf-> cgroup_pids_max == 0U ) {
103+ static bool initNsFromParentPids (nsj_t * nsj , pid_t pid) {
104+ if (nsj-> njc . cgroup_pids_max () == 0U ) {
104105 return true ;
105106 }
106107
107- std::string pids_cgroup_path = nsjconf-> cgroup_pids_mount + ' /' +
108- nsjconf-> cgroup_pids_parent + " /NSJAIL." +
108+ std::string pids_cgroup_path = nsj-> njc . cgroup_pids_mount () + ' /' +
109+ nsj-> njc . cgroup_pids_parent () + " /NSJAIL." +
109110 std::to_string (pid);
110111 RETURN_ON_FAILURE (createCgroup (pids_cgroup_path, pid));
111112
112- std::string pids_max_str = std::to_string (nsjconf-> cgroup_pids_max );
113+ std::string pids_max_str = std::to_string (nsj-> njc . cgroup_pids_max () );
113114 RETURN_ON_FAILURE (
114115 writeToCgroup (pids_cgroup_path + " /pids.max" , pids_max_str, " pids cgroup max limit" ));
115116
116117 return addPidToTaskList (pids_cgroup_path, pid);
117118}
118119
119- static bool initNsFromParentNetCls (nsjconf_t * nsjconf , pid_t pid) {
120- if (nsjconf-> cgroup_net_cls_classid == 0U ) {
120+ static bool initNsFromParentNetCls (nsj_t * nsj , pid_t pid) {
121+ if (nsj-> njc . cgroup_net_cls_classid () == 0U ) {
121122 return true ;
122123 }
123124
124- std::string net_cls_cgroup_path = nsjconf-> cgroup_net_cls_mount + ' /' +
125- nsjconf-> cgroup_net_cls_parent + " /NSJAIL." +
125+ std::string net_cls_cgroup_path = nsj-> njc . cgroup_net_cls_mount () + ' /' +
126+ nsj-> njc . cgroup_net_cls_parent () + " /NSJAIL." +
126127 std::to_string (pid);
127128 RETURN_ON_FAILURE (createCgroup (net_cls_cgroup_path, pid));
128129
129130 std::string net_cls_classid_str;
130131 {
131132 std::stringstream ss;
132- ss << " 0x" << std::hex << nsjconf-> cgroup_net_cls_classid ;
133+ ss << " 0x" << std::hex << nsj-> njc . cgroup_net_cls_classid () ;
133134 net_cls_classid_str = ss.str ();
134135 }
135136 RETURN_ON_FAILURE (writeToCgroup (net_cls_cgroup_path + " /net_cls.classid" ,
@@ -138,30 +139,31 @@ static bool initNsFromParentNetCls(nsjconf_t* nsjconf, pid_t pid) {
138139 return addPidToTaskList (net_cls_cgroup_path, pid);
139140}
140141
141- static bool initNsFromParentCpu (nsjconf_t * nsjconf , pid_t pid) {
142- if (nsjconf-> cgroup_cpu_ms_per_sec == 0U ) {
142+ static bool initNsFromParentCpu (nsj_t * nsj , pid_t pid) {
143+ if (nsj-> njc . cgroup_cpu_ms_per_sec () == 0U ) {
143144 return true ;
144145 }
145146
146- std::string cpu_cgroup_path = nsjconf->cgroup_cpu_mount + ' /' + nsjconf->cgroup_cpu_parent +
147- " /NSJAIL." + std::to_string (pid);
147+ std::string cpu_cgroup_path = nsj->njc .cgroup_cpu_mount () + ' /' +
148+ nsj->njc .cgroup_cpu_parent () + " /NSJAIL." +
149+ std::to_string (pid);
148150 RETURN_ON_FAILURE (createCgroup (cpu_cgroup_path, pid));
149151
150152 RETURN_ON_FAILURE (
151153 writeToCgroup (cpu_cgroup_path + " /cpu.cfs_period_us" , " 1000000" , " cpu period" ));
152154
153- std::string cpu_ms_per_sec_str = std::to_string (nsjconf-> cgroup_cpu_ms_per_sec * 1000U );
155+ std::string cpu_ms_per_sec_str = std::to_string (nsj-> njc . cgroup_cpu_ms_per_sec () * 1000U );
154156 RETURN_ON_FAILURE (
155157 writeToCgroup (cpu_cgroup_path + " /cpu.cfs_quota_us" , cpu_ms_per_sec_str, " cpu quota" ));
156158
157159 return addPidToTaskList (cpu_cgroup_path, pid);
158160}
159161
160- bool initNsFromParent (nsjconf_t * nsjconf , pid_t pid) {
161- RETURN_ON_FAILURE (initNsFromParentMem (nsjconf , pid));
162- RETURN_ON_FAILURE (initNsFromParentPids (nsjconf , pid));
163- RETURN_ON_FAILURE (initNsFromParentNetCls (nsjconf , pid));
164- return initNsFromParentCpu (nsjconf , pid);
162+ bool initNsFromParent (nsj_t * nsj , pid_t pid) {
163+ RETURN_ON_FAILURE (initNsFromParentMem (nsj , pid));
164+ RETURN_ON_FAILURE (initNsFromParentPids (nsj , pid));
165+ RETURN_ON_FAILURE (initNsFromParentNetCls (nsj , pid));
166+ return initNsFromParentCpu (nsj , pid);
165167}
166168
167169static void removeCgroup (const std::string& cgroup_path) {
@@ -171,34 +173,39 @@ static void removeCgroup(const std::string& cgroup_path) {
171173 }
172174}
173175
174- void finishFromParent (nsjconf_t * nsjconf, pid_t pid) {
175- if (nsjconf->cgroup_mem_max != (size_t )0 || nsjconf->cgroup_mem_memsw_max != (size_t )0 ) {
176- std::string mem_cgroup_path = nsjconf->cgroup_mem_mount + ' /' +
177- nsjconf->cgroup_mem_parent + " /NSJAIL." +
176+ void finishFromParent (nsj_t * nsj, pid_t pid) {
177+ if (nsj->njc .cgroup_mem_max () != (size_t )0 ||
178+ nsj->njc .cgroup_mem_memsw_max () != (size_t )0 ) {
179+ std::string mem_cgroup_path = nsj->njc .cgroup_mem_mount () + ' /' +
180+ nsj->njc .cgroup_mem_parent () + " /NSJAIL." +
178181 std::to_string (pid);
179182 removeCgroup (mem_cgroup_path);
180183 }
181- if (nsjconf-> cgroup_pids_max != 0U ) {
182- std::string pids_cgroup_path = nsjconf-> cgroup_pids_mount + ' /' +
183- nsjconf-> cgroup_pids_parent + " /NSJAIL." +
184+ if (nsj-> njc . cgroup_pids_max () != 0U ) {
185+ std::string pids_cgroup_path = nsj-> njc . cgroup_pids_mount () + ' /' +
186+ nsj-> njc . cgroup_pids_parent () + " /NSJAIL." +
184187 std::to_string (pid);
185188 removeCgroup (pids_cgroup_path);
186189 }
187- if (nsjconf-> cgroup_net_cls_classid != 0U ) {
188- std::string net_cls_cgroup_path = nsjconf-> cgroup_net_cls_mount + ' /' +
189- nsjconf-> cgroup_net_cls_parent + " /NSJAIL." +
190+ if (nsj-> njc . cgroup_net_cls_classid () != 0U ) {
191+ std::string net_cls_cgroup_path = nsj-> njc . cgroup_net_cls_mount () + ' /' +
192+ nsj-> njc . cgroup_net_cls_parent () + " /NSJAIL." +
190193 std::to_string (pid);
191194 removeCgroup (net_cls_cgroup_path);
192195 }
193- if (nsjconf-> cgroup_cpu_ms_per_sec != 0U ) {
194- std::string cpu_cgroup_path = nsjconf-> cgroup_cpu_mount + ' /' +
195- nsjconf-> cgroup_cpu_parent + " /NSJAIL." +
196+ if (nsj-> njc . cgroup_cpu_ms_per_sec () != 0U ) {
197+ std::string cpu_cgroup_path = nsj-> njc . cgroup_cpu_mount () + ' /' +
198+ nsj-> njc . cgroup_cpu_parent () + " /NSJAIL." +
196199 std::to_string (pid);
197200 removeCgroup (cpu_cgroup_path);
198201 }
199202}
200203
201- bool initNs (void ) {
204+ bool initUser (nsj_t * nsj) {
205+ return true ;
206+ }
207+
208+ bool initNs () {
202209 return true ;
203210}
204211
0 commit comments