void test_conf_get_path(void) { char* path; path = conf_get_path("", NULL); CU_ASSERT_PTR_NULL(path); unlink(CONF_TEST_PATH); FILE* fp = fopen(CONF_TEST_PATH, "w"); CU_ASSERT_PTR_NOT_NULL_FATAL(fp); fclose(fp); path = conf_get_path(CONF_TEST_PATH, NULL); CU_ASSERT_STRING_EQUAL(CONF_TEST_PATH, path); unsetenv(CONF_TEST_ENVVAR); path = conf_get_path(CONF_TEST_PATH, CONF_TEST_ENVVAR); CU_ASSERT_STRING_EQUAL(CONF_TEST_PATH, path); setenv(CONF_TEST_ENVVAR, CONF_TEST_PATH2, 1); unlink(CONF_TEST_PATH2); path = conf_get_path(CONF_TEST_PATH2, CONF_TEST_ENVVAR); CU_ASSERT_PTR_NULL(path); fp = fopen(CONF_TEST_PATH2, "w"); CU_ASSERT_PTR_NOT_NULL_FATAL(fp); fclose(fp); path = conf_get_path(CONF_TEST_PATH, CONF_TEST_ENVVAR); CU_ASSERT_STRING_EQUAL(CONF_TEST_PATH2, path); }
static void zipper_init_command_server(zipper_t *zipper, const char *config_path) { config_t *command_server_conf = NULL; int ret = conf_get_sub_config(zipper->config_, "command_server_config", &command_server_conf); ASSERT(ret == 0, "get configure for command server failed\n"); char ip[MAX_IP_STR_LEN]; int port; conf_get_string(command_server_conf, "ip", ip); conf_get_integer(command_server_conf, "port", &port); char command_spec_file_path[PATH_MAX]; if (0 != conf_get_path(command_server_conf, "command_spec_file", command_spec_file_path)) ASSERT(0, "command specific file doesn't found\n"); zipper->command_server_ = command_server_create(zipper->base_event_, ip, port, command_spec_file_path, config_path); conf_destroy(command_server_conf); command_server_init_command_runner(zipper->command_server_, zipper->rule_store_, zipper->ip_store_); }
static void zipper_run(zipper_t *zipper, bool run_foreground) { char ip_store_file_path[PATH_MAX]; if (0 != conf_get_path(zipper->config_, "ip_store_file_path", ip_store_file_path)) { ASSERT(0, "log file path isn't configured\n", ip_store_file_path); return; } if (0 != ipstore_load(zipper->ip_store_, ip_store_file_path)) { ASSERT(0, "load ip store file [%s] faild\n", ip_store_file_path); } if (!run_foreground) { int ret = fork(); ASSERT (ret >= 0, "fork failed"); if (ret > 0) { pid_file_write(zipper->pid_file_, ret); exit(0); } ret = setsid(); ASSERT( ret != -1, "setsid failed"); int fd = open("/dev/null", O_RDWR, 0); ASSERT(fd != -1, "open null dev failed"); (void)dup2(fd, STDIN_FILENO); (void)dup2(fd, STDOUT_FILENO); (void)dup2(fd, STDERR_FILENO); if (fd > 2) (void)close(fd); } dns_server_start(zipper->dns_server_, handle_dns_query, zipper); command_server_start(zipper->command_server_); event_base_dispatch(zipper->base_event_); }