/** * Fork and run parent and child process. * * The parent is the b2g process and child for Nuwa. */ static int RunProcesses(int argc, const char *argv[], FdArray& aReservedFds) { /* * The original main() of the b2g process. It is renamed to * b2g_main() for the b2g loader. */ int b2g_main(int argc, const char *argv[]); int ipcSockets[2] = {-1, -1}; int r = socketpair(AF_LOCAL, SOCK_STREAM, 0, ipcSockets); ASSERT(r == 0); int parentSock = ipcSockets[0]; int childSock = ipcSockets[1]; r = fcntl(parentSock, F_SETFL, O_NONBLOCK); ASSERT(r != -1); r = fcntl(childSock, F_SETFL, O_NONBLOCK); ASSERT(r != -1); pid_t pid = fork(); ASSERT(pid >= 0); bool isChildProcess = pid == 0; close(isChildProcess ? parentSock : childSock); if (isChildProcess) { /* The Nuwa process */ /* This provides the IPC service of loading Nuwa at the process. * The b2g process would send a IPC message of loading Nuwa * as the replacement of forking and executing plugin-container. */ return XRE_ProcLoaderServiceRun(getppid(), childSock, argc, argv, aReservedFds); } // Reap zombie child process. struct sigaction sa; sa.sa_handler = SIG_IGN; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sigaction(SIGCHLD, &sa, nullptr); // The b2g process int childPid = pid; XRE_ProcLoaderClientInit(childPid, parentSock, aReservedFds); return b2g_main(argc, argv); }
/** * Fork and run parent and child process. * * The parent is the b2g process and child for Nuwa. */ static int RunProcesses(int argc, const char *argv[]) { /* * The original main() of the b2g process. It is renamed to * b2g_main() for the b2g loader. */ int b2g_main(int argc, const char *argv[]); int ipcSockets[2] = {-1, -1}; int r = socketpair(AF_LOCAL, SOCK_STREAM, 0, ipcSockets); ASSERT(r == 0); int parentSock = ipcSockets[0]; int childSock = ipcSockets[1]; r = fcntl(parentSock, F_SETFL, O_NONBLOCK); ASSERT(r != -1); r = fcntl(childSock, F_SETFL, O_NONBLOCK); ASSERT(r != -1); pid_t pid = fork(); ASSERT(pid >= 0); bool isChildProcess = pid == 0; close(isChildProcess ? parentSock : childSock); if (isChildProcess) { /* The Nuwa process */ /* This provides the IPC service of loading Nuwa at the process. * The b2g process would send a IPC message of loading Nuwa * as the replacement of forking and executing plugin-container. */ return XRE_ProcLoaderServiceRun(getppid(), childSock, argc, argv); } // The b2g process int childPid = pid; XRE_ProcLoaderClientInit(childPid, parentSock); return b2g_main(argc, argv); }