/** * Main */ int main(int argc, char* argv[], char* envp[]) { parent_pid = getpid(); child_pid = fork(); switch(child_pid) { case -1: { PFLUSH("Fork failed!\n"); exit(-1); } case 0: { child_entry: child_loop(); break; } default: { child_pid2 = fork(); if (!child_pid2) { goto child_entry; } struct sigaction sig_action; sig_action.sa_sigaction = &handle_signals_info; sig_action.sa_flags = SA_SIGINFO; sigemptyset(&sig_action.sa_mask); sigaction(SIGUSR1, &sig_action, NULL); sigaction(SIGUSR2, &sig_action, NULL); sigaction(SIGINT, &sig_action, NULL); while(1) { PFLUSH("waiting... "); pause(); } break; } } return 0; }
void child_main() { // Ignore control-C in child setup_signal_handling(SIGINT, SIG_IGN); // Create the message queue msg_queue_id = msgget(MESSAGE_QUEUE_KEY, 0666 | IPC_CREAT); if (msg_queue_id == -1) { // Invalid message queue dump("Failed to open/create controller queue."); send_signal(SIGTERM, true); return; } while(running) { child_loop(); } // Delete the message queue dump("Removing message queue"); if (-1 == msgctl(msg_queue_id, IPC_RMID, 0)) { dump("Failed to delete message queue"); } dump("Finished"); }
int child_continue(int argc, char **argv) { wshd_t *w; int rv; w = child_load_from_shm(); /* Process MUST not leak file descriptors to children */ barrier_mix_cloexec(&w->barrier_child); fcntl_mix_cloexec(w->fd); if (strlen(w->title) > 0) { setproctitle(argv, w->title); } rv = mount_umount_pivoted_root("/mnt"); if (rv == -1) { exit(1); } /* Detach this process from its original group */ rv = setsid(); assert(rv > 0 && rv == getpid()); /* Signal parent */ rv = barrier_signal(&w->barrier_child); assert(rv == 0); return child_loop(w); }
void child_main() { // Ignore control-C in child setup_signal_handling(SIGINT, SIG_IGN); // Child setup srand(RAND_SEED); // Intializes random number generator // Get message queue msg_queue_id = msgget(MESSAGE_QUEUE_KEY, 0666); if (msg_queue_id == -1) { // Invalid message queue dump("Cannot open controller queue. Is controller running?"); send_signal(SIGTERM, true); // Tell parent to stop return; } // Start loop while(running) { child_loop(); } dump("Child finished"); }