2222#include <sys/types.h>
2323#include <sys/wait.h>
2424
25-
2625#include <linux/limits.h>
2726#include <linux/netlink.h>
2827#include <linux/types.h>
3231
3332/* Synchronisation values. */
3433enum sync_t {
35- SYNC_USERMAP_PLS = 0x40 , /* Request parent to map our users. */
36- SYNC_USERMAP_ACK = 0x41 , /* Mapping finished by the parent. */
37- SYNC_RECVPID_PLS = 0x42 , /* Tell parent we're sending the PID. */
38- SYNC_RECVPID_ACK = 0x43 , /* PID was correctly received by parent. */
39- SYNC_GRANDCHILD = 0x44 , /* The grandchild is ready to run. */
40- SYNC_CHILD_READY = 0x45 , /* The child or grandchild is ready to return. */
34+ SYNC_USERMAP_PLS = 0x40 , /* Request parent to map our users. */
35+ SYNC_USERMAP_ACK = 0x41 , /* Mapping finished by the parent. */
36+ SYNC_RECVPID_PLS = 0x42 , /* Tell parent we're sending the PID. */
37+ SYNC_RECVPID_ACK = 0x43 , /* PID was correctly received by parent. */
38+ SYNC_GRANDCHILD = 0x44 , /* The grandchild is ready to run. */
39+ SYNC_CHILD_READY = 0x45 , /* The child or grandchild is ready to return. */
4140
4241 /* XXX: This doesn't help with segfaults and other such issues. */
43- SYNC_ERR = 0xFF , /* Fatal error, no turning back. The error code follows. */
42+ SYNC_ERR = 0xFF , /* Fatal error, no turning back. The error code follows. */
4443};
4544
4645/* longjmp() arguments. */
@@ -73,7 +72,7 @@ struct nlconfig_t {
7372 char * oom_score_adj ;
7473 size_t oom_score_adj_len ;
7574
76- /* User namespace settings.*/
75+ /* User namespace settings. */
7776 char * uidmap ;
7877 size_t uidmap_len ;
7978 char * gidmap ;
@@ -82,7 +81,7 @@ struct nlconfig_t {
8281 size_t namespaces_len ;
8382 uint8_t is_setgroup ;
8483
85- /* Rootless container settings.*/
84+ /* Rootless container settings. */
8685 uint8_t is_rootless ;
8786 char * uidmappath ;
8887 size_t uidmappath_len ;
@@ -167,7 +166,7 @@ static int write_file(char *data, size_t data_len, char *pathfmt, ...)
167166 goto out ;
168167 }
169168
170- out :
169+ out :
171170 close (fd );
172171 return ret ;
173172}
@@ -184,16 +183,16 @@ static void update_setgroups(int pid, enum policy_t setgroup)
184183 char * policy ;
185184
186185 switch (setgroup ) {
187- case SETGROUPS_ALLOW :
188- policy = "allow" ;
189- break ;
190- case SETGROUPS_DENY :
191- policy = "deny" ;
192- break ;
193- case SETGROUPS_DEFAULT :
194- default :
195- /* Nothing to do. */
196- return ;
186+ case SETGROUPS_ALLOW :
187+ policy = "allow" ;
188+ break ;
189+ case SETGROUPS_DENY :
190+ policy = "deny" ;
191+ break ;
192+ case SETGROUPS_DEFAULT :
193+ default :
194+ /* Nothing to do. */
195+ return ;
197196 }
198197
199198 if (write_file (policy , strlen (policy ), "/proc/%d/setgroups" , pid ) < 0 ) {
@@ -226,14 +225,14 @@ static int try_mapping_tool(const char *app, int pid, char *map, size_t map_len)
226225 if (!child ) {
227226#define MAX_ARGV 20
228227 char * argv [MAX_ARGV ];
229- char * envp [] = {NULL };
228+ char * envp [] = { NULL };
230229 char pid_fmt [16 ];
231230 int argc = 0 ;
232231 char * next ;
233232
234233 snprintf (pid_fmt , 16 , "%d" , pid );
235234
236- argv [argc ++ ] = (char * ) app ;
235+ argv [argc ++ ] = (char * )app ;
237236 argv [argc ++ ] = pid_fmt ;
238237 /*
239238 * Convert the map string into a list of argument that
@@ -319,7 +318,7 @@ static int clone_parent(jmp_buf *env, int jmpval) __attribute__ ((noinline));
319318static int clone_parent (jmp_buf * env , int jmpval )
320319{
321320 struct clone_t ca = {
322- .env = env ,
321+ .env = env ,
323322 .jmpval = jmpval ,
324323 };
325324
@@ -533,7 +532,7 @@ void nsexec(void)
533532 int pipenum ;
534533 jmp_buf env ;
535534 int sync_child_pipe [2 ], sync_grandchild_pipe [2 ];
536- struct nlconfig_t config = {0 };
535+ struct nlconfig_t config = { 0 };
537536
538537 /*
539538 * If we don't have an init pipe, just return to the go routine.
@@ -630,21 +629,21 @@ void nsexec(void)
630629 */
631630
632631 switch (setjmp (env )) {
633- /*
634- * Stage 0: We're in the parent. Our job is just to create a new child
635- * (stage 1: JUMP_CHILD) process and write its uid_map and
636- * gid_map. That process will go on to create a new process, then
637- * it will send us its PID which we will send to the bootstrap
638- * process.
639- */
640- case JUMP_PARENT : {
632+ /*
633+ * Stage 0: We're in the parent. Our job is just to create a new child
634+ * (stage 1: JUMP_CHILD) process and write its uid_map and
635+ * gid_map. That process will go on to create a new process, then
636+ * it will send us its PID which we will send to the bootstrap
637+ * process.
638+ */
639+ case JUMP_PARENT :{
641640 int len ;
642641 pid_t child , first_child = -1 ;
643642 char buf [JSON_MAX ];
644643 bool ready = false;
645644
646645 /* For debugging. */
647- prctl (PR_SET_NAME , (unsigned long ) "runc:[0:PARENT]" , 0 , 0 , 0 );
646+ prctl (PR_SET_NAME , (unsigned long )"runc:[0:PARENT]" , 0 , 0 , 0 );
648647
649648 /* Start the process of getting a container. */
650649 child = clone_parent (& env , JUMP_CHILD );
@@ -702,7 +701,7 @@ void nsexec(void)
702701 bail ("failed to sync with child: write(SYNC_USERMAP_ACK)" );
703702 }
704703 break ;
705- case SYNC_RECVPID_PLS : {
704+ case SYNC_RECVPID_PLS :{
706705 first_child = child ;
707706
708707 /* Get the init_func pid. */
@@ -781,16 +780,16 @@ void nsexec(void)
781780 exit (0 );
782781 }
783782
784- /*
785- * Stage 1: We're in the first child process. Our job is to join any
786- * provided namespaces in the netlink payload and unshare all
787- * of the requested namespaces. If we've been asked to
788- * CLONE_NEWUSER, we will ask our parent (stage 0) to set up
789- * our user mappings for us. Then, we create a new child
790- * (stage 2: JUMP_INIT) for PID namespace. We then send the
791- * child's PID to our parent (stage 0).
792- */
793- case JUMP_CHILD : {
783+ /*
784+ * Stage 1: We're in the first child process. Our job is to join any
785+ * provided namespaces in the netlink payload and unshare all
786+ * of the requested namespaces. If we've been asked to
787+ * CLONE_NEWUSER, we will ask our parent (stage 0) to set up
788+ * our user mappings for us. Then, we create a new child
789+ * (stage 2: JUMP_INIT) for PID namespace. We then send the
790+ * child's PID to our parent (stage 0).
791+ */
792+ case JUMP_CHILD :{
794793 pid_t child ;
795794 enum sync_t s ;
796795
@@ -799,7 +798,7 @@ void nsexec(void)
799798 close (sync_child_pipe [1 ]);
800799
801800 /* For debugging. */
802- prctl (PR_SET_NAME , (unsigned long ) "runc:[1:CHILD]" , 0 , 0 , 0 );
801+ prctl (PR_SET_NAME , (unsigned long )"runc:[1:CHILD]" , 0 , 0 , 0 );
803802
804803 /*
805804 * We need to setns first. We cannot do this earlier (in stage 0)
@@ -901,13 +900,13 @@ void nsexec(void)
901900 exit (0 );
902901 }
903902
904- /*
905- * Stage 2: We're the final child process, and the only process that will
906- * actually return to the Go runtime. Our job is to just do the
907- * final cleanup steps and then return to the Go runtime to allow
908- * init_linux.go to run.
909- */
910- case JUMP_INIT : {
903+ /*
904+ * Stage 2: We're the final child process, and the only process that will
905+ * actually return to the Go runtime. Our job is to just do the
906+ * final cleanup steps and then return to the Go runtime to allow
907+ * init_linux.go to run.
908+ */
909+ case JUMP_INIT :{
911910 /*
912911 * We're inside the child now, having jumped from the
913912 * start_child() code after forking in the parent.
@@ -921,7 +920,7 @@ void nsexec(void)
921920 close (sync_child_pipe [1 ]);
922921
923922 /* For debugging. */
924- prctl (PR_SET_NAME , (unsigned long ) "runc:[2:INIT]" , 0 , 0 , 0 );
923+ prctl (PR_SET_NAME , (unsigned long )"runc:[2:INIT]" , 0 , 0 , 0 );
925924
926925 if (read (syncfd , & s , sizeof (s )) != sizeof (s ))
927926 bail ("failed to sync with parent: read(SYNC_GRANDCHILD)" );
0 commit comments