int main (int argc, char ** argv) { if (argc < 2) { fprintf(stderr, "%s: expected argument\n", argv[0]); return 1; } printf("(This should fork and the child process (but not the parent) should segfault)\n"); size_t size = 27; volatile char * shm = (char *)syscall_shm_obtain(argv[1], &size); if (shm == NULL) { return 1; } int pid = getpid(); uint32_t f = fork(); if (getpid() != pid) { // Child: client return main_client(shm); } else { // Parent: server return main_server(shm); } return 0; }
int main(int argc, char * const *argv) { if (getpid() == 0) dummy(); if (argc > 1 && !strcmp(argv[1], "--poll-server")) return (main_poll_server(argc - 1, argv + 1)); if (argc > 1 && !strcmp(argv[1], "--sim-client")) return (main_sim_client(argc - 1, argv + 1)); if (argc > 1 && !strcmp(argv[1], "--run-tests")) return (main_run_tests(argc - 1, argv + 1)); return (main_client(argc, argv)); }
int main(int argc, char const *argv[]) { if (atoi(argv[1]) == 1) { main_server(); // Order orders[MAX_QUEUE_SIZE]; // int i; // elev_init(); // pthread_t buttons; // // for (i = 0; i < MAX_QUEUE_SIZE; i++) { // orders[i] = malloc(sizeof(Order)); // // } // // pthread_create(&buttons, NULL, thread_monitor_button_inputs, (void *) orders); // // // // while(1) { // // // for (i = 0; i < MAX_QUEUE_SIZE; i++) { // printf("Floor: %d, Direction: %d\n", orders[i].floor, orders[i].button_type); // } // printf("--------------------\n"); // sleep(5); // } // // pthread_join(buttons, NULL); } else if (atoi(argv[1]) == 2) { if(argc != 3) { printf("Not enough input arguments\n"); exit(1); } main_client(argv[2]); } return 0; }
int main(int argc, char **argv) { int ret = 0, c, udp = 0, ipv4 = -1, daemon = 1, log = 1; char *port = NULL, *stun = NULL, *dev = NULL, *home = NULL, *alias = NULL; enum working_mode wmode = MODE_UNKNOW; setfsuid(getuid()); setfsgid(getgid()); home = fetch_home_dir(); while ((c = getopt_long(argc, argv, short_options, long_options, NULL)) != EOF) { switch (c) { case 'h': help(); break; case 'v': version(); break; case 'D': daemon = 0; break; case 'N': log = 0; break; case 'C': wmode = MODE_DUMPC; break; case 'S': wmode = MODE_DUMPS; break; case 'c': wmode = MODE_CLIENT; if (optarg) { if (*optarg == '=') optarg++; alias = xstrdup(optarg); } break; case 'd': dev = xstrdup(optarg); break; case 'k': wmode = MODE_KEYGEN; break; case '4': ipv4 = 1; break; case '6': ipv4 = 0; break; case 'x': wmode = MODE_EXPORT; break; case 's': wmode = MODE_SERVER; break; case 'u': udp = 1; break; case 't': stun = xstrdup(optarg); break; case 'p': port = xstrdup(optarg); break; case '?': switch (optopt) { case 't': case 'd': case 'u': case 'p': panic("Option -%c requires an argument!\n", optopt); default: if (isprint(optopt)) printf("Unknown option character `0x%X\'!\n", optopt); die(); } default: break; } } if (argc < 2) help(); register_signal(SIGINT, signal_handler); register_signal(SIGHUP, signal_handler); register_signal(SIGTERM, signal_handler); register_signal(SIGPIPE, signal_handler); curve25519_selftest(); switch (wmode) { case MODE_KEYGEN: ret = main_keygen(home); break; case MODE_EXPORT: ret = main_export(home); break; case MODE_DUMPC: ret = main_dumpc(home); break; case MODE_DUMPS: ret = main_dumps(home); break; case MODE_CLIENT: ret = main_client(home, dev, alias, daemon); break; case MODE_SERVER: if (!port) panic("No port specified!\n"); if (stun) print_stun_probe(stun, 3478, strtoul(port, NULL, 10)); ret = main_server(home, dev, port, udp, ipv4, daemon, log); break; default: die(); } free(dev); free(stun); free(port); free(alias); return ret; }