| 1139 | } |
| 1140 | |
| 1141 | static void |
| 1142 | run(char **argv) |
| 1143 | { |
| 1144 | if (!lock_box(false, false)) |
| 1145 | die("Box not found, did you run `%s --init'?", self_name()); |
| 1146 | |
| 1147 | if (chdir(box_dir) < 0) |
| 1148 | die("chdir(%s): %m", box_dir); |
| 1149 | |
| 1150 | if (!inherit_fds) |
| 1151 | { |
| 1152 | keep_fd(lock_fd); |
| 1153 | close_all_fds(); |
| 1154 | } |
| 1155 | |
| 1156 | chowntree("box", box_uid, box_gid, special_files); |
| 1157 | cleanup_ownership = 1; |
| 1158 | |
| 1159 | setup_pipe(error_pipes, 1); |
| 1160 | setup_pipe(status_pipes, 0); |
| 1161 | setup_signals(); |
| 1162 | cg_setup(); |
| 1163 | |
| 1164 | proxy_pid = clone( |
| 1165 | box_proxy, // Function to execute as the body of the new process |
| 1166 | (void*)((uintptr_t)argv & ~(uintptr_t)15), // Pass our stack, aligned to 16-bytes |
| 1167 | SIGCHLD | CLONE_NEWIPC | (share_net ? 0 : CLONE_NEWNET) | CLONE_NEWNS | CLONE_NEWPID, |
| 1168 | argv); // Pass the arguments |
| 1169 | if (proxy_pid < 0) |
| 1170 | die("Cannot run proxy, clone failed: %m"); |
| 1171 | if (!proxy_pid) |
| 1172 | die("Cannot run proxy, clone returned 0"); |
| 1173 | |
| 1174 | pid_t box_pid_inside_ns; |
| 1175 | int n = read(status_pipes[0], &box_pid_inside_ns, sizeof(box_pid_inside_ns)); |
| 1176 | if (n != sizeof(box_pid_inside_ns)) |
| 1177 | die("Proxy failed before it passed box_pid: %m"); |
| 1178 | find_box_pid(); |
| 1179 | msg("Started proxy_pid=%d box_pid=%d box_pid_inside_ns=%d\n", (int) proxy_pid, (int) box_pid, (int) box_pid_inside_ns); |
| 1180 | |
| 1181 | box_keeper(); |
| 1182 | } |
| 1183 | |
| 1184 | static void |
| 1185 | show_version(void) |
no test coverage detected