int main(int argc, char *argv[]) { lstate *state; if(argc != 2) usage(); state = my_malloc(sizeof(lstate)); state->config_file = strdup(argv[1]); initialise(state); do_event_loop(state); GrClose(); return 0; }
void event_loop_prio(int timeout) { do_event_loop(timeout, true); }
void event_loop(int timeout) { do_event_loop(timeout, false); }
int main(int argc, char *argv[]) { static struct option long_options[] = { {"listen", required_argument, 0, 'l'}, {"port", required_argument, 0, 'p'}, {"help", no_argument, 0, 'h'}, {"verbose", no_argument, 0, 'v'}, {"ping-parent", no_argument, 0, 'x'}, {"gcc-command", required_argument, 0, 'g'}, {"vx32sdk", required_argument, 0, 's'}, {"tmpdir", required_argument, 0, 't'}, {"engine", required_argument, 0, 'e'}, {"no-vx32", no_argument, 0, 'n'}, {0, 0, 0, 0} }; struct server *server = (struct server*)st_calloc(1, sizeof(struct server)); server->info_handler = &info_handler; server->quit_handler = &quit_handler; server->process_multi= &process_multi; INIT_LIST_HEAD(&server->root); server->host = "127.0.0.1"; server->port = 22122; struct config *config = (struct config*)st_calloc(1, sizeof(struct config)); server->userdata = config; config->tmpdir = "/tmp"; config->vx32sdk_path = "./untrusted/"; config->vx32sdk_gcc_command = strdup(flatten_argv(NELEM(default_vx32sdk_gcc_command), default_vx32sdk_gcc_command, " ")); config->syscall_limit = 4; /* 4 syscalls per request allowed */ int option_index; int arg; char *engine_name = NULL; while((arg = getopt_long_only(argc, argv, "hxvnl:p:g:s:t:e:", long_options, &option_index)) != EOF) { switch(arg) { case 'h': print_help(server, config); exit(-1); break; case 'v': server->trace = 1; break; case 'x': server->ping_parent = 1; break; case 'l': server->host = optarg; break; case 'p': server->port = atoi(optarg); if(server->port < 0 || server->port > 65536) fatal("Port number broken: %i", server->port); break; case 'g': free(config->vx32sdk_gcc_command); config->vx32sdk_gcc_command = strdup(optarg); break; case 's': config->vx32sdk_path = optarg; break; case 't': config->tmpdir = optarg; break; case 'e': engine_name = optarg; break; case 'n': config->vx32_disabled = 1; break; case 0: default: fatal("\nUnknown option: \"%s\"\n", argv[optind-1]); } } int i; storage_engine_create *engine_create = NULL; storage_engine_destroy *engine_destroy = NULL; for(i=0; i<NELEM(engines); i++) { if(engine_name && 0 == strcmp(engine_name, engines[i].name)) { engine_create = engines[i].create; engine_destroy = engines[i].destroy; } } if(NULL == engine_create) fatal("\nYou must specify a storage engine:" " --engine=[%s]\n", flatten_engine_names() ); log_info("Process pid %i", getpid()); signal(SIGPIPE, SIG_IGN); commands_initialize(); process_initialize(config); char *params = flatten_argv(argc-optind, &argv[optind], ", "); log_info("Loading database engine \"%s\" with parameters \"%s\"", engine_name, params); config->api = engine_create(argc-optind, &argv[optind]); do_event_loop(server); log_info("Quit"); process_destroy(); commands_destroy(); pool_free(); engine_destroy(config->api); free(config->vx32sdk_gcc_command); free(config); free(server); exit(0); return(0); }