sf_load_global_config_ex add params: max_pkg_size_item_name and need_set_run_by
parent
cf4856e04b
commit
b7b346ea7f
|
|
@ -46,7 +46,7 @@ SFGlobalVariables g_sf_global_vars = {
|
||||||
SFContext g_sf_context = {
|
SFContext g_sf_context = {
|
||||||
{'\0'}, NULL, 0, -1, -1, 0, 0, 1, DEFAULT_WORK_THREADS,
|
{'\0'}, NULL, 0, -1, -1, 0, 0, 1, DEFAULT_WORK_THREADS,
|
||||||
{'\0'}, {'\0'}, 0, true, true, NULL, NULL, NULL, NULL,
|
{'\0'}, {'\0'}, 0, true, true, NULL, NULL, NULL, NULL,
|
||||||
sf_task_finish_clean_up, NULL
|
NULL, sf_task_finish_clean_up, NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline void set_config_str_value(const char *value,
|
static inline void set_config_str_value(const char *value,
|
||||||
|
|
@ -60,6 +60,7 @@ static inline void set_config_str_value(const char *value,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int load_network_parameters(IniFullContext *ini_ctx,
|
static int load_network_parameters(IniFullContext *ini_ctx,
|
||||||
|
const char *max_pkg_size_item_nm,
|
||||||
const int task_buffer_extra_size)
|
const int task_buffer_extra_size)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
|
|
@ -93,7 +94,7 @@ static int load_network_parameters(IniFullContext *ini_ctx,
|
||||||
}
|
}
|
||||||
|
|
||||||
g_sf_global_vars.max_pkg_size = iniGetByteCorrectValueEx(ini_ctx,
|
g_sf_global_vars.max_pkg_size = iniGetByteCorrectValueEx(ini_ctx,
|
||||||
"max_pkg_size", SF_DEF_MAX_PACKAGE_SIZE, 1, 8192,
|
max_pkg_size_item_nm, SF_DEF_MAX_PACKAGE_SIZE, 1, 8192,
|
||||||
SF_MAX_NETWORK_BUFF_SIZE, true);
|
SF_MAX_NETWORK_BUFF_SIZE, true);
|
||||||
pMinBuffSize = iniGetStrValueEx(ini_ctx->section_name,
|
pMinBuffSize = iniGetStrValueEx(ini_ctx->section_name,
|
||||||
"min_buff_size", ini_ctx->context, true);
|
"min_buff_size", ini_ctx->context, true);
|
||||||
|
|
@ -271,7 +272,8 @@ int sf_load_global_base_path(IniFullContext *ini_ctx)
|
||||||
|
|
||||||
int sf_load_global_config_ex(const char *server_name,
|
int sf_load_global_config_ex(const char *server_name,
|
||||||
IniFullContext *ini_ctx, const bool load_network_params,
|
IniFullContext *ini_ctx, const bool load_network_params,
|
||||||
const int task_buffer_extra_size)
|
const char *max_pkg_size_item_nm, const int task_buffer_extra_size,
|
||||||
|
const bool need_set_run_by)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
const char *old_section_name;
|
const char *old_section_name;
|
||||||
|
|
@ -287,7 +289,7 @@ int sf_load_global_config_ex(const char *server_name,
|
||||||
"tcp_quick_ack", ini_ctx->context, true);
|
"tcp_quick_ack", ini_ctx->context, true);
|
||||||
tcp_set_quick_ack(g_sf_global_vars.tcp_quick_ack);
|
tcp_set_quick_ack(g_sf_global_vars.tcp_quick_ack);
|
||||||
if (load_network_params) {
|
if (load_network_params) {
|
||||||
if ((result=load_network_parameters(ini_ctx,
|
if ((result=load_network_parameters(ini_ctx, max_pkg_size_item_nm,
|
||||||
task_buffer_extra_size)) != 0)
|
task_buffer_extra_size)) != 0)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -350,11 +352,13 @@ int sf_load_global_config_ex(const char *server_name,
|
||||||
g_sf_global_vars.run_by_uid = pUser->pw_uid;
|
g_sf_global_vars.run_by_uid = pUser->pw_uid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (need_set_run_by) {
|
||||||
if ((result=set_run_by(g_sf_global_vars.run_by_group,
|
if ((result=set_run_by(g_sf_global_vars.run_by_group,
|
||||||
g_sf_global_vars.run_by_user)) != 0)
|
g_sf_global_vars.run_by_user)) != 0)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
g_sf_global_vars.thread_stack_size = iniGetByteCorrectValueEx(ini_ctx,
|
g_sf_global_vars.thread_stack_size = iniGetByteCorrectValueEx(ini_ctx,
|
||||||
"thread_stack_size", SF_DEF_THREAD_STACK_SIZE, 1,
|
"thread_stack_size", SF_DEF_THREAD_STACK_SIZE, 1,
|
||||||
|
|
@ -379,12 +383,13 @@ int sf_load_global_config_ex(const char *server_name,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sf_load_config_ex(const char *server_name, SFContextIniConfig
|
int sf_load_config_ex(const char *server_name, SFContextIniConfig *config,
|
||||||
*config, const int task_buffer_extra_size)
|
const int task_buffer_extra_size, const bool need_set_run_by)
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
if ((result=sf_load_global_config_ex(server_name, &config->ini_ctx,
|
if ((result=sf_load_global_config_ex(server_name, &config->ini_ctx,
|
||||||
true, task_buffer_extra_size)) != 0)
|
true, config->max_pkg_size_item_name,
|
||||||
|
task_buffer_extra_size, need_set_run_by)) != 0)
|
||||||
{
|
{
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
@ -539,12 +544,14 @@ void sf_slow_log_config_to_string(SFSlowLogConfig *slow_log_cfg,
|
||||||
slow_log_buff, output, size);
|
slow_log_buff, output, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sf_global_config_to_string(char *output, const int size)
|
void sf_global_config_to_string_ex(const char *max_pkg_size_item_nm,
|
||||||
|
char *output, const int size)
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
int max_pkg_size;
|
int max_pkg_size;
|
||||||
int min_buff_size;
|
int min_buff_size;
|
||||||
int max_buff_size;
|
int max_buff_size;
|
||||||
|
char pkg_buff[256];
|
||||||
|
|
||||||
max_pkg_size = g_sf_global_vars.max_pkg_size -
|
max_pkg_size = g_sf_global_vars.max_pkg_size -
|
||||||
g_sf_global_vars.task_buffer_extra_size;
|
g_sf_global_vars.task_buffer_extra_size;
|
||||||
|
|
@ -552,19 +559,27 @@ void sf_global_config_to_string(char *output, const int size)
|
||||||
g_sf_global_vars.task_buffer_extra_size;
|
g_sf_global_vars.task_buffer_extra_size;
|
||||||
max_buff_size = g_sf_global_vars.max_buff_size -
|
max_buff_size = g_sf_global_vars.max_buff_size -
|
||||||
g_sf_global_vars.task_buffer_extra_size;
|
g_sf_global_vars.task_buffer_extra_size;
|
||||||
|
|
||||||
|
if (min_buff_size == max_buff_size && max_pkg_size == max_buff_size) {
|
||||||
|
snprintf(pkg_buff, sizeof(pkg_buff), "%s=%d KB",
|
||||||
|
max_pkg_size_item_nm, max_pkg_size / 1024);
|
||||||
|
} else {
|
||||||
|
snprintf(pkg_buff, sizeof(pkg_buff), "%s=%d KB, "
|
||||||
|
"min_buff_size=%d KB, max_buff_size=%d KB",
|
||||||
|
max_pkg_size_item_nm, max_pkg_size / 1024,
|
||||||
|
min_buff_size / 1024, max_buff_size / 1024);
|
||||||
|
}
|
||||||
|
|
||||||
len = snprintf(output, size,
|
len = snprintf(output, size,
|
||||||
"base_path=%s, max_connections=%d, connect_timeout=%d, "
|
"base_path=%s, max_connections=%d, connect_timeout=%d, "
|
||||||
"network_timeout=%d, thread_stack_size=%d KB, "
|
"network_timeout=%d, thread_stack_size=%d KB, "
|
||||||
"max_pkg_size=%d KB, min_buff_size=%d KB, "
|
"%s, tcp_quick_ack=%d, log_level=%s, "
|
||||||
"max_buff_size=%d KB, tcp_quick_ack=%d, log_level=%s, "
|
|
||||||
"run_by_group=%s, run_by_user=%s, ", SF_G_BASE_PATH_STR,
|
"run_by_group=%s, run_by_user=%s, ", SF_G_BASE_PATH_STR,
|
||||||
g_sf_global_vars.max_connections,
|
g_sf_global_vars.max_connections,
|
||||||
g_sf_global_vars.connect_timeout,
|
g_sf_global_vars.connect_timeout,
|
||||||
g_sf_global_vars.network_timeout,
|
g_sf_global_vars.network_timeout,
|
||||||
g_sf_global_vars.thread_stack_size / 1024,
|
g_sf_global_vars.thread_stack_size / 1024,
|
||||||
max_pkg_size / 1024, min_buff_size / 1024,
|
pkg_buff, g_sf_global_vars.tcp_quick_ack,
|
||||||
max_buff_size / 1024,
|
|
||||||
g_sf_global_vars.tcp_quick_ack,
|
|
||||||
log_get_level_caption(),
|
log_get_level_caption(),
|
||||||
g_sf_global_vars.run_by_group,
|
g_sf_global_vars.run_by_group,
|
||||||
g_sf_global_vars.run_by_user
|
g_sf_global_vars.run_by_user
|
||||||
|
|
|
||||||
|
|
@ -63,6 +63,7 @@ typedef struct sf_context_ini_config {
|
||||||
int default_inner_port;
|
int default_inner_port;
|
||||||
int default_outer_port;
|
int default_outer_port;
|
||||||
int default_work_threads;
|
int default_work_threads;
|
||||||
|
const char *max_pkg_size_item_name;
|
||||||
} SFContextIniConfig;
|
} SFContextIniConfig;
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
@ -80,6 +81,12 @@ extern SFContext g_sf_context;
|
||||||
#define SF_G_MAX_CONNECTIONS g_sf_global_vars.max_connections
|
#define SF_G_MAX_CONNECTIONS g_sf_global_vars.max_connections
|
||||||
#define SF_G_THREAD_STACK_SIZE g_sf_global_vars.thread_stack_size
|
#define SF_G_THREAD_STACK_SIZE g_sf_global_vars.thread_stack_size
|
||||||
|
|
||||||
|
#define SF_G_OUTER_PORT g_sf_context.outer_port
|
||||||
|
#define SF_G_INNER_PORT g_sf_context.inner_port
|
||||||
|
#define SF_G_OUTER_BIND_ADDR g_sf_context.outer_bind_addr
|
||||||
|
#define SF_G_INNER_BIND_ADDR g_sf_context.inner_bind_addr
|
||||||
|
|
||||||
|
#define SF_G_ACCEPT_THREADS g_sf_context.accept_threads
|
||||||
#define SF_G_WORK_THREADS g_sf_context.work_threads
|
#define SF_G_WORK_THREADS g_sf_context.work_threads
|
||||||
#define SF_G_ALIVE_THREAD_COUNT g_sf_context.thread_count
|
#define SF_G_ALIVE_THREAD_COUNT g_sf_context.thread_count
|
||||||
#define SF_G_THREAD_INDEX(tdata) (int)(tdata - g_sf_context.thread_data)
|
#define SF_G_THREAD_INDEX(tdata) (int)(tdata - g_sf_context.thread_data)
|
||||||
|
|
@ -113,44 +120,78 @@ extern SFContext g_sf_context;
|
||||||
#define SF_CHOWN_TO_RUNBY_RETURN_ON_ERROR(path) \
|
#define SF_CHOWN_TO_RUNBY_RETURN_ON_ERROR(path) \
|
||||||
SF_CHOWN_RETURN_ON_ERROR(path, geteuid(), getegid())
|
SF_CHOWN_RETURN_ON_ERROR(path, geteuid(), getegid())
|
||||||
|
|
||||||
#define SF_SET_CONTEXT_INI_CONFIG(config, filename, pIniContext, \
|
|
||||||
section_name, def_inner_port, def_outer_port, def_work_threads) \
|
#define SF_FCHOWN_RETURN_ON_ERROR(fd, path, current_uid, current_gid) \
|
||||||
|
do { \
|
||||||
|
if (!(g_sf_global_vars.run_by_gid == current_gid && \
|
||||||
|
g_sf_global_vars.run_by_uid == current_uid)) \
|
||||||
|
{ \
|
||||||
|
if (fchown(fd, g_sf_global_vars.run_by_uid, \
|
||||||
|
g_sf_global_vars.run_by_gid) != 0) \
|
||||||
|
{ \
|
||||||
|
logError("file: "__FILE__", line: %d, " \
|
||||||
|
"fchown \"%s\" fail, " \
|
||||||
|
"errno: %d, error info: %s", \
|
||||||
|
__LINE__, path, errno, STRERROR(errno)); \
|
||||||
|
return errno != 0 ? errno : EPERM; \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define SF_FCHOWN_TO_RUNBY_RETURN_ON_ERROR(fd, path) \
|
||||||
|
SF_FCHOWN_RETURN_ON_ERROR(fd, path, geteuid(), getegid())
|
||||||
|
|
||||||
|
#define SF_SET_CONTEXT_INI_CONFIG_EX(config, filename, pIniContext, \
|
||||||
|
section_name, def_inner_port, def_outer_port, def_work_threads, \
|
||||||
|
max_pkg_size_item_nm) \
|
||||||
do { \
|
do { \
|
||||||
FAST_INI_SET_FULL_CTX_EX(config.ini_ctx, filename, \
|
FAST_INI_SET_FULL_CTX_EX(config.ini_ctx, filename, \
|
||||||
section_name, pIniContext); \
|
section_name, pIniContext); \
|
||||||
config.default_inner_port = def_inner_port; \
|
config.default_inner_port = def_inner_port; \
|
||||||
config.default_outer_port = def_outer_port; \
|
config.default_outer_port = def_outer_port; \
|
||||||
config.default_work_threads = def_work_threads; \
|
config.default_work_threads = def_work_threads; \
|
||||||
|
config.max_pkg_size_item_name = max_pkg_size_item_nm; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define SF_SET_CONTEXT_INI_CONFIG(config, filename, pIniContext, \
|
||||||
|
section_name, def_inner_port, def_outer_port, def_work_threads) \
|
||||||
|
SF_SET_CONTEXT_INI_CONFIG_EX(config, filename, pIniContext, \
|
||||||
|
section_name, def_inner_port, def_outer_port, def_work_threads, \
|
||||||
|
"max_pkg_size")
|
||||||
|
|
||||||
int sf_load_global_config_ex(const char *server_name,
|
int sf_load_global_config_ex(const char *server_name,
|
||||||
IniFullContext *ini_ctx, const bool load_network_params,
|
IniFullContext *ini_ctx, const bool load_network_params,
|
||||||
const int task_buffer_extra_size);
|
const char *max_pkg_size_item_nm, const int task_buffer_extra_size,
|
||||||
|
const bool need_set_run_by);
|
||||||
|
|
||||||
static inline int sf_load_global_config(const char *server_name,
|
static inline int sf_load_global_config(const char *server_name,
|
||||||
IniFullContext *ini_ctx)
|
IniFullContext *ini_ctx)
|
||||||
{
|
{
|
||||||
const bool load_network_params = true;
|
const bool load_network_params = true;
|
||||||
|
const char *max_pkg_size_item_nm = "max_pkg_size";
|
||||||
const int task_buffer_extra_size = 0;
|
const int task_buffer_extra_size = 0;
|
||||||
|
const bool need_set_run_by = true;
|
||||||
|
|
||||||
return sf_load_global_config_ex(server_name, ini_ctx,
|
return sf_load_global_config_ex(server_name, ini_ctx, load_network_params,
|
||||||
load_network_params, task_buffer_extra_size);
|
max_pkg_size_item_nm, task_buffer_extra_size, need_set_run_by);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sf_load_config_ex(const char *server_name,
|
int sf_load_config_ex(const char *server_name, SFContextIniConfig *config,
|
||||||
SFContextIniConfig *config, const int task_buffer_extra_size);
|
const int task_buffer_extra_size, const bool need_set_run_by);
|
||||||
|
|
||||||
static inline int sf_load_config(const char *server_name,
|
static inline int sf_load_config(const char *server_name,
|
||||||
const char *filename, IniContext *pIniContext,
|
const char *filename, IniContext *pIniContext,
|
||||||
const char *section_name, const int default_inner_port,
|
const char *section_name, const int default_inner_port,
|
||||||
const int default_outer_port, const int task_buffer_extra_size)
|
const int default_outer_port, const int task_buffer_extra_size)
|
||||||
{
|
{
|
||||||
|
const bool need_set_run_by = true;
|
||||||
SFContextIniConfig config;
|
SFContextIniConfig config;
|
||||||
|
|
||||||
SF_SET_CONTEXT_INI_CONFIG(config, filename, pIniContext,
|
SF_SET_CONTEXT_INI_CONFIG(config, filename, pIniContext,
|
||||||
section_name, default_inner_port, default_outer_port,
|
section_name, default_inner_port, default_outer_port,
|
||||||
DEFAULT_WORK_THREADS);
|
DEFAULT_WORK_THREADS);
|
||||||
return sf_load_config_ex(server_name, &config, task_buffer_extra_size);
|
return sf_load_config_ex(server_name, &config,
|
||||||
|
task_buffer_extra_size, need_set_run_by);
|
||||||
}
|
}
|
||||||
|
|
||||||
int sf_load_context_from_config_ex(SFContext *sf_context,
|
int sf_load_context_from_config_ex(SFContext *sf_context,
|
||||||
|
|
@ -193,7 +234,14 @@ void sf_log_config_to_string_ex(SFLogConfig *log_cfg, const char *caption,
|
||||||
void sf_slow_log_config_to_string(SFSlowLogConfig *slow_log_cfg,
|
void sf_slow_log_config_to_string(SFSlowLogConfig *slow_log_cfg,
|
||||||
const char *caption, char *output, const int size);
|
const char *caption, char *output, const int size);
|
||||||
|
|
||||||
void sf_global_config_to_string(char *output, const int size);
|
void sf_global_config_to_string_ex(const char *max_pkg_size_item_nm,
|
||||||
|
char *output, const int size);
|
||||||
|
|
||||||
|
static inline void sf_global_config_to_string(char *output, const int size)
|
||||||
|
{
|
||||||
|
const char *max_pkg_size_item_nm = "max_pkg_size";
|
||||||
|
sf_global_config_to_string_ex(max_pkg_size_item_nm, output, size);
|
||||||
|
}
|
||||||
|
|
||||||
void sf_context_config_to_string(const SFContext *sf_context,
|
void sf_context_config_to_string(const SFContext *sf_context,
|
||||||
char *output, const int size);
|
char *output, const int size);
|
||||||
|
|
|
||||||
|
|
@ -199,8 +199,13 @@ const char *sf_parse_daemon_mode_and_action_ex(int argc, char *argv[],
|
||||||
} else {
|
} else {
|
||||||
proc_name = argv[0];
|
proc_name = argv[0];
|
||||||
}
|
}
|
||||||
|
if (version->patch > 0) {
|
||||||
printf("\n%s V%d.%d.%d\n\n", proc_name, version->major,
|
printf("\n%s V%d.%d.%d\n\n", proc_name, version->major,
|
||||||
version->minor, version->patch);
|
version->minor, version->patch);
|
||||||
|
} else {
|
||||||
|
printf("\n%s V%d.%02d\n\n", proc_name,
|
||||||
|
version->major, version->minor);
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (strcmp(argv[i], "-h") == 0 ||
|
if (strcmp(argv[i], "-h") == 0 ||
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue