void restart_logging (ice_config_t *config) { if (strcmp (config->error_log, "-")) { char fn_error[FILENAME_MAX]; snprintf (fn_error, FILENAME_MAX, "%s%s%s", config->log_dir, PATH_SEPARATOR, config->error_log); log_set_filename (errorlog, fn_error); log_set_level (errorlog, config->loglevel); log_set_trigger (errorlog, config->logsize); log_set_archive_timestamp(errorlog, config->logarchive); log_reopen (errorlog); } if (strcmp (config->access_log, "-")) { char fn_error[FILENAME_MAX]; snprintf (fn_error, FILENAME_MAX, "%s%s%s", config->log_dir, PATH_SEPARATOR, config->access_log); log_set_filename (accesslog, fn_error); log_set_trigger (accesslog, config->logsize); log_set_archive_timestamp (accesslog, config->logarchive); log_reopen (accesslog); } if (config->playlist_log) { char fn_error[FILENAME_MAX]; snprintf (fn_error, FILENAME_MAX, "%s%s%s", config->log_dir, PATH_SEPARATOR, config->playlist_log); log_set_filename (playlistlog, fn_error); log_set_trigger (playlistlog, config->logsize); log_set_archive_timestamp (playlistlog, config->logarchive); log_reopen (playlistlog); } }
static int recheck_log_file (ice_config_t *config, int *id, const char *file) { char fn [FILENAME_MAX]; if (file == NULL || strcmp (file, "-") == 0) { log_close (*id); *id = -1; return 0; } snprintf (fn, FILENAME_MAX, "%s%s%s", config->log_dir, PATH_SEPARATOR, file); if (*id < 0) { *id = log_open (fn); if (*id < 0) { char buf[1024]; snprintf (buf,1024, "could not open log %s: %s", fn, strerror(errno)); fatal_error (buf); return -1; } return 0; } log_set_filename (*id, fn); log_reopen (*id); return 0; }
int fdfs_mod_init() { IniContext iniContext; int result; char *pBasePath; char *pLogFilename; char *pReponseMode; char *pGroupName; char *pIfAliasPrefix; log_init(); if ((result = iniLoadFromFile(FDFS_MOD_CONF_FILENAME, &iniContext)) != 0) { logError("file: "__FILE__", line: %d, " "load conf file \"%s\" fail, ret code: %d", __LINE__, FDFS_MOD_CONF_FILENAME, result); return result; } do { pBasePath = iniGetStrValue(NULL, "base_path", &iniContext); if (pBasePath == NULL) { logError("file: "__FILE__", line: %d, " "conf file \"%s\" must have item " "\"base_path\"!", __LINE__, FDFS_MOD_CONF_FILENAME); result = ENOENT; break; } snprintf(g_fdfs_base_path, sizeof(g_fdfs_base_path), "%s", pBasePath); chopPath(g_fdfs_base_path); if (!fileExists(g_fdfs_base_path)) { logError("file: "__FILE__", line: %d, " "\"%s\" can't be accessed, error info: %s", __LINE__, g_fdfs_base_path, strerror(errno)); result = errno != 0 ? errno : ENOENT; break; } if (!isDir(g_fdfs_base_path)) { logError("file: "__FILE__", line: %d, " "\"%s\" is not a directory!", __LINE__, g_fdfs_base_path); result = ENOTDIR; break; } g_fdfs_connect_timeout = iniGetIntValue(NULL, "connect_timeout", &iniContext, DEFAULT_CONNECT_TIMEOUT); if (g_fdfs_connect_timeout <= 0) { g_fdfs_connect_timeout = DEFAULT_CONNECT_TIMEOUT; } g_fdfs_network_timeout = iniGetIntValue(NULL, "network_timeout", &iniContext, DEFAULT_NETWORK_TIMEOUT); if (g_fdfs_network_timeout <= 0) { g_fdfs_network_timeout = DEFAULT_NETWORK_TIMEOUT; } load_log_level(&iniContext); pLogFilename = iniGetStrValue(NULL, "log_filename", &iniContext); if (pLogFilename != NULL && *pLogFilename != '\0') { if ((result = log_set_filename(pLogFilename)) != 0) { break; } } result = fdfs_load_tracker_group_ex(&g_tracker_group, FDFS_MOD_CONF_FILENAME, &iniContext); if (result != 0) { break; } storage_server_port = iniGetIntValue(NULL, "storage_server_port", &iniContext, FDFS_STORAGE_SERVER_DEF_PORT); url_have_group_name = iniGetBoolValue(NULL, "url_have_group_name", &iniContext, false); pGroupName = iniGetStrValue(NULL, "group_name", &iniContext); if (pGroupName != NULL) { snprintf(group_name, sizeof(group_name), "%s", pGroupName); } group_name_len = strlen(group_name); if ((!url_have_group_name) && group_name_len == 0) { logError("file: "__FILE__", line: %d, " "you must set parameter: group_name!", __LINE__); result = ENOENT; break; } if ((result = fdfs_http_params_load(&iniContext, FDFS_MOD_CONF_FILENAME, &g_http_params)) != 0) { break; } pReponseMode = iniGetStrValue(NULL, "response_mode", &iniContext); //add client 模式 if (pReponseMode != NULL) { if (strcmp(pReponseMode, "redirect") == 0) { response_mode = FDFS_MOD_REPONSE_MODE_REDIRECT; } else if (strcmp(pReponseMode, "client") == 0) { response_mode = FDFS_MOD_REPONSE_MODE_CLIENT; } } pIfAliasPrefix = iniGetStrValue(NULL, "if_alias_prefix", &iniContext); if (pIfAliasPrefix == NULL) { *g_if_alias_prefix = '\0'; } else { snprintf(g_if_alias_prefix, sizeof(g_if_alias_prefix), "%s", pIfAliasPrefix); } } while (false); iniFreeContext(&iniContext); if (result != 0) { return result; } load_local_host_ip_addrs(); fdfs_get_params_from_tracker(); logInfo("fastdfs apache / nginx module v1.04, " "response_mode=%s, " "base_path=%s, " "connect_timeout=%d, " "network_timeout=%d, " "tracker_server_count=%d, " "storage_server_port=%d, " "group_name=%s, " "if_alias_prefix=%s, " "local_host_ip_count=%d, " "need_find_content_type=%d, " "default_content_type=%s, " "anti_steal_token=%d, " "token_ttl=%ds, " "anti_steal_secret_key length=%d, " "token_check_fail content_type=%s, " "token_check_fail buff length=%d, " "storage_sync_file_max_delay=%ds", response_mode == FDFS_MOD_REPONSE_MODE_PROXY ? "proxy" : "redirect", g_fdfs_base_path, g_fdfs_connect_timeout, g_fdfs_network_timeout, g_tracker_group.server_count, storage_server_port, group_name, g_if_alias_prefix, g_local_host_ip_count, g_http_params.need_find_content_type, g_http_params.default_content_type, g_http_params.anti_steal_token, g_http_params.token_ttl, g_http_params.anti_steal_secret_key.length, g_http_params.token_check_fail_content_type, g_http_params.token_check_fail_buff.length, storage_sync_file_max_delay); //print_local_host_ip_addrs(); return 0; }