int main(int argc, char *argv[]) { pid_t pid; //Initialize the controller if (!init()) parent_close(0); //Create a child process pid = fork(); switch(pid) { case -1: printf("%d: fork failed\n.",getpid()); parent_close(0); case 0: // The child process handles all connected devices device_Handler(); break; default: // The parent process handles signals from the child child_pid = pid; signal_Handler(); break; } return 1; }
END_TEST START_TEST(test_parent_socket) { struct rawfd *rfd; const char *errstr; options |= OPT_DEBUG; dfd = STDOUT_FILENO; mark_point(); parent_open(ifindex, ifname); rfd = rfd_byindex(&rawfds, ifindex); fail_unless (rfd != NULL, "rfd should be added to the queue"); mark_point(); // only run this as a regular user if (!geteuid()) return; options &= ~OPT_DEBUG; errstr = "pcap_"; WRAP_FATAL_START(); parent_socket(rfd); WRAP_FATAL_END(); fail_unless (strncmp(check_wrap_errstr, errstr, strlen(errstr)) == 0, "incorrect message logged: %s", check_wrap_errstr); rfd = rfd_byindex(&rawfds, ifindex); fail_unless (rfd != NULL, "rfd not found"); parent_close(rfd); fail_unless (TAILQ_EMPTY(&rawfds), "the queue should be empty"); }
END_TEST START_TEST(test_parent_open_close) { struct rawfd *rfd; options |= OPT_DEBUG; dfd = STDOUT_FILENO; mark_point(); parent_open(ifindex, ifname); rfd = rfd_byindex(&rawfds, ifindex); fail_unless (rfd != NULL, "rfd should be added to the queue"); parent_close(rfd); fail_unless (rfd_byindex(&rawfds, ifindex) == NULL, "rfd should be removed from the queue"); mark_point(); parent_open(ifindex, ifname); rfd = rfd_byindex(&rawfds, ifindex); fail_unless (rfd != NULL, "rfd should be added to the queue"); parent_open(2, "lo1"); rfd = rfd_byindex(&rawfds, 2); fail_unless (rfd != NULL, "rfd should be added to the queue"); rfd_closeall(&rawfds); fail_unless (TAILQ_EMPTY(&rawfds), "the queue should be empty"); }