auto create base_path when it not exist
parent
45531cf0c8
commit
4f3cde053c
|
|
@ -229,17 +229,27 @@ int sf_get_base_path_from_conf_file(const char *config_filename)
|
|||
return 0;
|
||||
}
|
||||
|
||||
result = get_base_path_from_conf_file(config_filename,
|
||||
SF_G_BASE_PATH_STR, sizeof(SF_G_BASE_PATH_STR));
|
||||
if (result == 0) {
|
||||
SF_G_BASE_PATH_INITED = true;
|
||||
result = get_base_path_from_conf_file_ex(config_filename,
|
||||
SF_G_BASE_PATH_STR, sizeof(SF_G_BASE_PATH_STR), LOG_NOTHING);
|
||||
if (result != 0) {
|
||||
if (result == ENOENT) {
|
||||
if ((result=fc_check_mkdir_ex(SF_G_BASE_PATH_STR,
|
||||
0775, &SF_G_BASE_PATH_CREATED)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
SF_G_BASE_PATH_INITED = true;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sf_load_global_base_path(IniFullContext *ini_ctx)
|
||||
{
|
||||
int result;
|
||||
char *pBasePath;
|
||||
|
||||
if (!SF_G_BASE_PATH_INITED) {
|
||||
|
|
@ -255,10 +265,11 @@ int sf_load_global_base_path(IniFullContext *ini_ctx)
|
|||
|
||||
chopPath(SF_G_BASE_PATH_STR);
|
||||
if (!fileExists(SF_G_BASE_PATH_STR)) {
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"\"%s\" can't be accessed, error info: %s",
|
||||
__LINE__, SF_G_BASE_PATH_STR, strerror(errno));
|
||||
return errno != 0 ? errno : ENOENT;
|
||||
if ((result=fc_check_mkdir_ex(SF_G_BASE_PATH_STR, 0775,
|
||||
&SF_G_BASE_PATH_CREATED)) != 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (!isDir(SF_G_BASE_PATH_STR)) {
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
|
|
@ -352,6 +363,10 @@ int sf_load_global_config_ex(const char *server_name,
|
|||
g_sf_global_vars.run_by_uid = pUser->pw_uid;
|
||||
}
|
||||
|
||||
if (SF_G_BASE_PATH_CREATED) {
|
||||
SF_CHOWN_TO_RUNBY_RETURN_ON_ERROR(SF_G_BASE_PATH_STR);
|
||||
}
|
||||
|
||||
if (need_set_run_by) {
|
||||
if ((result=set_run_by(g_sf_global_vars.run_by_group,
|
||||
g_sf_global_vars.run_by_user)) != 0)
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ typedef struct sf_global_variables {
|
|||
struct {
|
||||
char str[MAX_PATH_SIZE];
|
||||
bool inited;
|
||||
bool created;
|
||||
} base_path;
|
||||
|
||||
volatile bool continue_flag;
|
||||
|
|
@ -75,6 +76,7 @@ extern SFContext g_sf_context;
|
|||
|
||||
#define SF_G_BASE_PATH_STR g_sf_global_vars.base_path.str
|
||||
#define SF_G_BASE_PATH_INITED g_sf_global_vars.base_path.inited
|
||||
#define SF_G_BASE_PATH_CREATED g_sf_global_vars.base_path.created
|
||||
#define SF_G_CONTINUE_FLAG g_sf_global_vars.continue_flag
|
||||
#define SF_G_CONNECT_TIMEOUT g_sf_global_vars.connect_timeout
|
||||
#define SF_G_NETWORK_TIMEOUT g_sf_global_vars.network_timeout
|
||||
|
|
|
|||
Loading…
Reference in New Issue