qd_dispatch_t *qd_dispatch(const char *python_pkgdir) { qd_dispatch_t *qd = NEW(qd_dispatch_t); memset(qd, 0, sizeof(qd_dispatch_t)); qd_entity_cache_initialize(); /* Must be first */ qd_alloc_initialize(); qd_log_initialize(); qd_error_initialize(); if (qd_error_code()) { qd_dispatch_free(qd); return 0; } qd_dispatch_set_router_area(qd, strdup("0")); qd_dispatch_set_router_id(qd, strdup("0")); qd->router_mode = QD_ROUTER_MODE_ENDPOINT; qd_python_initialize(qd, python_pkgdir); if (qd_error_code()) { qd_dispatch_free(qd); return 0; } qd_message_initialize(); if (qd_error_code()) { qd_dispatch_free(qd); return 0; } qd->dl_handle = 0; return qd; }
int main(int argc, char** argv) { if (argc != 2) { fprintf(stderr, "usage: %s <config-file>\n", argv[0]); exit(1); } int result = 0; // Call qd_dispatch() first initialize allocator used by other tests. qd_dispatch_t *qd = qd_dispatch(0); qd_dispatch_load_config(qd, argv[1]); if (qd_error_code()) { printf("Config failed: %s\n", qd_error_message()); return 1; } result += timer_tests(); result += server_tests(qd); result += tool_tests(); result += parse_tests(); result += compose_tests(); #if USE_MEMORY_POOL result += alloc_tests(); #endif result += policy_tests(); qd_dispatch_free(qd); // dispatch_free last. return result; }
static void main_process(const char *config_path, const char *python_pkgdir, int fd) { dispatch = qd_dispatch(python_pkgdir); check(fd); log_source = qd_log_source("MAIN"); /* Logging is initialized by qd_dispatch. */ qd_dispatch_validate_config(config_path); check(fd); qd_dispatch_load_config(dispatch, config_path); check(fd); signal(SIGHUP, signal_handler); signal(SIGQUIT, signal_handler); signal(SIGTERM, signal_handler); signal(SIGINT, signal_handler); if (fd > 2) { /* Daemon mode, fd is one end of a pipe not stdout or stderr */ #ifdef __sun const char * okResult = "ok"; write(fd, okResult, (strlen(okResult)+1)); #else dprintf(fd, "ok"); // Success signal #endif close(fd); } qd_server_run(dispatch); qd_dispatch_t *d = dispatch; dispatch = NULL; qd_dispatch_free(d); fflush(stdout); if (exit_with_sigint) { signal(SIGINT, SIG_DFL); kill(getpid(), SIGINT); } }