summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/sapp_log.c33
-rw-r--r--src/common/sapp_mem.c6
-rw-r--r--src/config/cmd_args.c26
-rw-r--r--src/config/config_parse.cpp122
-rw-r--r--src/packet_io/cycle_pkt_dump_through_write_offset.c3
-rw-r--r--src/packet_io/packet_io_device.c6
-rw-r--r--src/packet_io/packet_io_lib_load.c4
-rw-r--r--src/packet_io/packet_io_pcap.c15
-rw-r--r--src/packet_io/packet_io_status.cpp1
-rw-r--r--src/packet_io/sendpacket.c4
-rw-r--r--src/plugin/src/plugin.c14
-rw-r--r--src/plugin/src/plugin_business.c2
-rw-r--r--src/plugin/src/plugin_platform.c3
-rw-r--r--src/plugin/src/plugin_protocol.c2
-rw-r--r--src/project/project_requirement.c5
-rw-r--r--src/sapp_dev/sapp_init.c10
-rw-r--r--src/sapp_dev/sapp_plug.c35
-rw-r--r--src/support/dictator2/src/dictator.cpp2
18 files changed, 174 insertions, 119 deletions
diff --git a/src/common/sapp_log.c b/src/common/sapp_log.c
index 215361d..4d4b26a 100644
--- a/src/common/sapp_log.c
+++ b/src/common/sapp_log.c
@@ -7,12 +7,29 @@ extern "C" {
#include "support/tomlc99_wrap.h"
+void sapp_printf(const char *fmt, ...)
+{
+ va_list ap;
+
+ if(sapp_global_val->cla.slient_mode != 0){
+ return;
+ }
+
+ va_start(ap, fmt);
+ vprintf(fmt, ap);
+ va_end(ap);
+
+ return;
+}
+
+
void sapp_printf_colorful(int level, const char *format, ...)
{
va_list ap;
char local_log_content_buff[XATTR_SIZE_MAX];
const char *log_color_start = "";
const char *log_color_end = "";
+ FILE *out_fp = stdout;
va_start(ap, format);
vsnprintf(local_log_content_buff, sizeof(local_log_content_buff), format, ap);
@@ -31,15 +48,16 @@ void sapp_printf_colorful(int level, const char *format, ...)
break;
case RLOG_LV_FATAL:
- log_color_start = "\033[1;31;40m";
+ log_color_start = "\033[1;31;40m[Error]";
log_color_end = "\033[0m";
+ out_fp = stderr;
break;
default:
break;
}
- fprintf(stdout, "%s%s%s", log_color_start, local_log_content_buff, log_color_end);
+ fprintf(out_fp, "%s%s%s", log_color_start, local_log_content_buff, log_color_end);
return;
}
@@ -57,12 +75,18 @@ void sapp_log(int level, int print_sw, int file_sw, const char *format, ...)
char local_log_content_buff[XATTR_SIZE_MAX];
const char *log_color_start = "";
const char *log_color_end = "";
+ FILE *out_fp = stdout;
+
+ if(sapp_global_val->cla.slient_mode != 0){
+ print_sw = 0;
+ }
if(level < ABBR_SAPP_LOG_LEVEL){
if((print_sw != ~0) && (file_sw != ~0)){
return;
}
}
+
if((0 == print_sw) && (0 == file_sw)){
return;
}
@@ -84,8 +108,9 @@ void sapp_log(int level, int print_sw, int file_sw, const char *format, ...)
break;
case RLOG_LV_FATAL:
- log_color_start = "\033[1;31;40m";
+ log_color_start = "\033[1;31;40m[Error]";
log_color_end = "\033[0m";
+ out_fp = stderr;
break;
default:
@@ -97,7 +122,7 @@ void sapp_log(int level, int print_sw, int file_sw, const char *format, ...)
}
if((~0 == print_sw) || (level >= ABBR_SAPP_LOG_LEVEL)){
- fprintf(stdout, "%s%s%s\n", log_color_start, local_log_content_buff, log_color_end);
+ fprintf(out_fp, "%s%s%s\n", log_color_start, local_log_content_buff, log_color_end);
}
return;
diff --git a/src/common/sapp_mem.c b/src/common/sapp_mem.c
index be7787b..0f93a74 100644
--- a/src/common/sapp_mem.c
+++ b/src/common/sapp_mem.c
@@ -227,20 +227,20 @@ void sapp_mem_stat_output(void)
int stat_name_tuple_num = sizeof(mem_stat_name_tuple)/sizeof(mem_stat_name_tuple_t);
assert(stat_name_tuple_num == __SAPP_MEM_TYPE_MAX);
if(stat_name_tuple_num != __SAPP_MEM_TYPE_MAX){
- printf("\033[1;31;40m[Error] sizeof(mem_stat_name_tuple) is not equal with __SAPP_MEM_TYPE_MAX \033[0m\n");
+ sapp_printf("\033[1;31;40m[Error] sizeof(mem_stat_name_tuple) is not equal with __SAPP_MEM_TYPE_MAX \033[0m\n");
exit(1);
}
for(stat_index = 0; stat_index < __SAPP_MEM_TYPE_MAX; stat_index++){
if((int)mem_stat_name_tuple[stat_index].mem_type != stat_index){
- printf("\033[1;31;40m[Error] mem_stat_name_tuple[] array index:%d is not equal with mem_stat_name_tuple_t\033[0m\n", stat_index);
+ sapp_printf("\033[1;31;40m[Error] mem_stat_name_tuple[] array index:%d is not equal with mem_stat_name_tuple_t\033[0m\n", stat_index);
exit(1);
}
}
fp = fopen(ABBR_MEMORY_STAT_LOG_DATA_FILE,"w+");
if(fp == NULL){
- printf("\033[1;31;40mopen %s error, %s\033[0m\n", ABBR_MEMORY_STAT_LOG_DATA_FILE, strerror(errno));
+ sapp_printf("\033[1;31;40mopen %s error, %s\033[0m\n", ABBR_MEMORY_STAT_LOG_DATA_FILE, strerror(errno));
return;
}
diff --git a/src/config/cmd_args.c b/src/config/cmd_args.c
index a98a7f5..a956469 100644
--- a/src/config/cmd_args.c
+++ b/src/config/cmd_args.c
@@ -122,15 +122,16 @@ static const sapp_cmd_args_usage_t cmd_args_usage[] =
{"-g", "coredump", "no",NULL, "generate coredump for test"},
{"-h", "help", "no",NULL, "show help message"},
{"-n", "not-exit", "no",NULL, "not exit in dumpfile mode after all packets have been processed"},
- {"-p", "dumpfile-speed", "required",dumpfile_speed_check, "\n \t\ttop-speed\tprocess packets as fast as possible, this is default behavior\n\t\ttimestamp\tprocess packets as pcap embedded timestamp interval"},
+ {"-p", "dumpfile-speed", "required",dumpfile_speed_check, "\n \t\ttop-speed\tprocess packets as fast as possible, this is default behavior\n\t\ttimestamp\tprocess packets as pcap embedded timestamp interval"},
{"-r", "dumpfile-file", "required",NULL, "read packets from which pcap file"},
+ {"-s", "silent", "no",NULL, "silent mode, don't print anything to stdout, default is verbose"},
{"-t", "test-config", "no",NULL, "check validity of the configuration file"},
{"-v", "version", "no",NULL, "show platform version"},
{NULL, NULL, NULL,NULL,NULL}
};
/* ��ֻ̬��ȫ�ֱ������Է����κδ����, ������sapp_global_val�� */
-static const char *sapp_cla_short_options = "dhgvnc:C:D:e:r:p:f:t";
+static const char *sapp_cla_short_options = "dhgvnsc:C:D:e:r:p:f:t";
/* ��ֻ̬��ȫ�ֱ������Է����κδ����, ������sapp_global_val�� */
static const struct option sapp_cla_long_options[] =
@@ -146,6 +147,7 @@ static const struct option sapp_cla_long_options[] =
{"dumpfile-speed", required_argument, NULL, 'p'},
{"example-config", required_argument, NULL, 'e'},
{"coredump", no_argument, NULL, 'g'},
+ {"silent", no_argument, NULL, 's'},
{"test-config", no_argument, NULL, 't'},
{"not-exit", no_argument, NULL, 'n'},
{NULL, 0, NULL, 0}
@@ -430,6 +432,21 @@ void sapp_update_data_root_dir(const char *data_root_dir)
}
+static void sapp_close_stdout(void)
+{
+#if 0
+ int null_fd = open("/dev/null", O_CREAT | O_RDWR); /* ����sappˢ����Ϣ */
+ if(null_fd > 0){
+ dup2(null_fd, STDOUT_FILENO);
+ }
+#else
+ if(stdout){
+ fclose(stdout);
+ stdout = fopen("/dev/null", "w");
+ }
+#endif
+}
+
int sapp_parse_cmd_args(int argc, char *argv[])
{
int ret = 0;
@@ -525,6 +542,11 @@ int sapp_parse_cmd_args(int argc, char *argv[])
continue;
break;
+ case 's':
+ sapp_global_val->cla.slient_mode = 1;
+ sapp_close_stdout();
+ break;
+
case 't':
test_config_flag = 1;
continue;
diff --git a/src/config/config_parse.cpp b/src/config/config_parse.cpp
index e90b7ff..d30fd30 100644
--- a/src/config/config_parse.cpp
+++ b/src/config/config_parse.cpp
@@ -159,7 +159,7 @@ static int cfg_value_check_bind_mask(const sapp_config_check_t *sapp_cfg_check_a
int cfg_send_only_threads_num = atoi(raw_cfg_send_only_threads_value);
if(bind_mask_array_num != cfg_worker_threads_num + cfg_send_only_threads_num){
- printf("\033[41m[Error]sapp.toml->CPU->bind_mask value is not match sapp.toml->CPU->worker_threads + CPU->send_only_threads_max!\033[0m\n");
+ sapp_log(RLOG_LV_FATAL,1,1, "sapp.toml->CPU->bind_mask value is not match sapp.toml->CPU->worker_threads + CPU->send_only_threads_max!\n");
return -1;
}
@@ -176,12 +176,12 @@ static int cfg_value_check_stream_id_base_time(const sapp_config_check_t *sapp_c
}
if(strptime(raw_cfg_value, "%Y-%m-%d %H:%M:%S", &local_tm) == NULL){
- printf("\033[41m[Error]sapp.toml->STREAM->stream_id_base_time error, the pattern must like '1970-01-01 01:01:01' !\033[0m\n");
+ sapp_log(RLOG_LV_FATAL,1,1,"sapp.toml->STREAM->stream_id_base_time error, the pattern must like '1970-01-01 01:01:01'!\n");
return -1;
}
if(mktime(&local_tm) > time(NULL)){
- printf("\033[41m[Error]sapp.toml->STREAM.stream_id_base_time value error, is after current system time!\033[0m\n");
+ sapp_log(RLOG_LV_FATAL,1,1,"sapp.toml->STREAM.stream_id_base_time value error, is after current system time!\n");
return -1;
}
@@ -442,7 +442,7 @@ static int cfg_value_check_inject_mode(const sapp_config_check_t *sapp_cfg_check
if(strncasecmp(depend_cfg_value, "vxlan_by_inline_device", strlen("vxlan_by_inline_device")) == 0){
expect_cfg_index = cfg_get_index_by_key_name("inject_mode_inline_device_sport");
if((NULL == sapp_cfg_check_attr[expect_cfg_index].cfg_value ) && (this_cfg_index == expect_cfg_index)){
- printf("\033[1;31;40m[Error]sapp.toml->inject_pkt_mode value is 'vxlan_by_inline_device', but not found '%s'!\033[0m\n", "inject_mode_inline_device_sport");
+ sapp_log(RLOG_LV_FATAL,1,1,"sapp.toml->inject_pkt_mode value is 'vxlan_by_inline_device', but not found '%s'!\n", "inject_mode_inline_device_sport");
return -1;
}
}
@@ -450,19 +450,19 @@ static int cfg_value_check_inject_mode(const sapp_config_check_t *sapp_cfg_check
if(strncasecmp(depend_cfg_value, "raw_ethernet_single_gateway", strlen("raw_ethernet_single_gateway")) == 0){
expect_cfg_index = cfg_get_index_by_key_name("inject_mode_single_gateway_device");
if((NULL == sapp_cfg_check_attr[expect_cfg_index].cfg_value ) && (this_cfg_index == expect_cfg_index)){
- printf("\033[1;31;40m[Error]sapp.toml->inject_pkt_mode value is 'raw_ethernet_single_gateway', but not found '%s'!\033[0m\n", "inject_mode_single_gateway_device");
+ sapp_log(RLOG_LV_FATAL,1,1,"sapp.toml->inject_pkt_mode value is 'raw_ethernet_single_gateway', but not found '%s'!\n", "inject_mode_single_gateway_device");
return -1;
}
expect_cfg_index = cfg_get_index_by_key_name("inject_mode_single_gateway_src_mac");
if((NULL == sapp_cfg_check_attr[expect_cfg_index].cfg_value ) && (this_cfg_index == expect_cfg_index)){
- printf("\033[1;31;40m[Error]sapp.toml->inject_pkt_mode value is 'raw_ethernet_single_gateway', but not found '%s'!\033[0m\n", "inject_mode_single_gateway_src_mac");
+ sapp_log(RLOG_LV_FATAL,1,1,"sapp.toml->inject_pkt_mode value is 'raw_ethernet_single_gateway', but not found '%s'!\n", "inject_mode_single_gateway_src_mac");
return -1;
}
expect_cfg_index = cfg_get_index_by_key_name("inject_mode_single_gateway_dst_mac");
if((NULL == sapp_cfg_check_attr[expect_cfg_index].cfg_value ) && (this_cfg_index == expect_cfg_index)){
- printf("\033[1;31;40m[Error]sapp.toml->inject_pkt_mode value is 'raw_ethernet_single_gateway', but not found '%s'!\033[0m\n", "inject_mode_single_gateway_dst_mac");
+ sapp_log(RLOG_LV_FATAL,1,1,"sapp.toml->inject_pkt_mode value is 'raw_ethernet_single_gateway', but not found '%s'!\n", "inject_mode_single_gateway_dst_mac");
return -1;
}
}
@@ -502,9 +502,9 @@ static const char *sapp_cfg_get_value_from_attr_by_section_key(const sapp_config
static void special_usage(void)
{
- printf("\033[1;31;40m[Error]open %s error!\033[0m\n", ABBR_CFG_FILE_MAIN_ENTRY);
- printf("\033[1;31;40m[Error]This is sapp version4.2, use sapp.toml instead of main.conf!\033[0m\n");
- printf("\033[1;31;40m[Error]You should run ./sapp -e to generate sapp.toml!\033[0m\n");
+ sapp_printf_colorful(RLOG_LV_FATAL,"open %s error!\n", ABBR_CFG_FILE_MAIN_ENTRY);
+ sapp_printf_colorful(RLOG_LV_FATAL,"This is sapp version4.2, use sapp.toml instead of main.conf!\n");
+ sapp_printf_colorful(RLOG_LV_FATAL,"You should run ./sapp -e to generate sapp.toml!\n");
}
static inline int is_file_exist(const char *filename)
@@ -559,13 +559,13 @@ void sapp_generate_example_config(const char *cfg_file_name, const char *sapp_ve
ret = stat(cfg_file_name, &file_stat);
if((ret >= 0) || (errno != ENOENT) || S_ISREG(file_stat.st_mode)){
- printf("\033[1;31;40m[Error]file '%s' already exist!\033[0m\n", cfg_file_name);
+ sapp_printf_colorful(RLOG_LV_FATAL,"file '%s' already exist!\n", cfg_file_name);
return;
}
fp = fopen(cfg_file_name, "w+");
if(NULL == fp){
- printf("\033[1;31;40m[Error]open %s error, %s!\033[0m\n", cfg_file_name, strerror(errno));
+ sapp_printf_colorful(RLOG_LV_FATAL,"open %s error, %s!\n", cfg_file_name, strerror(errno));
return;
}
@@ -596,7 +596,7 @@ static int pkt_dump_thread_id_convert(void)
for(i = 0; i < pdump->dump_thread_id_array_num; i++){
index = pdump->dump_thread_id_array[i];
if(index >= SAPP_MAX_THREADS){
- sapp_log(30, ~0, ~0, "[Error]sapp.toml->PKT_DUMP->dump_thread_id value more than max CPU core number!");
+ sapp_log(RLOG_LV_FATAL,1,1,"sapp.toml->PKT_DUMP->dump_thread_id value more than max CPU core number!\n");
return -1;
}else{
pdump->dump_thread_id_mask[index] = 1;
@@ -635,12 +635,12 @@ static int parse_vlan_flipping_map_config(void)
mac_flip_enable = 0;
ret = sscanf(line_cont, "%u %u %u", &c_router_vlan_id, &i_router_vlan_id, &mac_flip_enable);
if(ret != 3){
- sapp_log(RLOG_LV_FATAL, ~0, ~0, "[Error]parse vlan_flipping_cfg_file:%s, line:%s error!", ABBR_VLAN_FLIPPING_CONF_FILE, line_cont);
+ sapp_log(RLOG_LV_FATAL,1,1,"parse vlan_flipping_cfg_file:%s, line:%s error!", ABBR_VLAN_FLIPPING_CONF_FILE, line_cont);
fclose(fp);
return -1;
}
if(c_router_vlan_id>= 4096 || i_router_vlan_id >= 4096){
- sapp_log(RLOG_LV_FATAL, ~0, ~0, "[Error]parse vlan_flipping_cfg_file:%s line:%s error, vlan id must in range[1,4095]!", ABBR_VLAN_FLIPPING_CONF_FILE, line_cont);
+ sapp_log(RLOG_LV_FATAL,1,1, "parse vlan_flipping_cfg_file:%s line:%s error, vlan id must in range[1,4095]!", ABBR_VLAN_FLIPPING_CONF_FILE, line_cont);
fclose(fp);
return -1;
}
@@ -802,8 +802,7 @@ static int parse_asymmetric_addr_layer_config(void)
memset(&embed_layer, 0, sizeof(embed_layer));
ret = embed_layer_t_pton(line_cont, &embed_layer);
if(ret < 0){
- sapp_log(RLOG_LV_FATAL, ~0, ~0, "[Error]parse cfg_file:%s error, inlavid:%s",
- ABBR_ASYM_LAYER_ADDR_CONF_FILE, line_cont);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "parse cfg_file:%s error, inlavid:%s", ABBR_ASYM_LAYER_ADDR_CONF_FILE, line_cont);
fclose(fp);
return -1;
}
@@ -972,7 +971,7 @@ static int parse_stream_compare_layer_config(void)
memset(&embed_layer, 0, sizeof(embed_layer));
ret = embed_layer_t_pton(line_cont, &embed_layer);
if(ret < 0){
- sapp_log(RLOG_LV_FATAL, ~0, ~0, "[Error]parse stream compare layer cfg_file:%s error, inlavid:%s", ABBR_STREAM_CMP_LAYER_CONF_FILE, line_cont);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "parse stream compare layer cfg_file:%s error, inlavid:%s", ABBR_STREAM_CMP_LAYER_CONF_FILE, line_cont);
goto fun_exit;
}
@@ -1019,8 +1018,7 @@ static void update_well_known_port_array(int last_section_proto, unsigned short
sapp_global_val->config.stream.udp.well_known_ports_array = port_array;
sapp_global_val->config.stream.udp.well_known_ports_array_num = port_array_num;
}else{
- sapp_log(RLOG_LV_FATAL, ~0, ~0, "[Error]parse cfg_file:%s error, onlye support TCP or UDP", ABBR_WELL_KNOWN_PORT_CONF_FILE);
- assert(0);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "parse cfg_file:%s error, onlye support TCP or UDP", ABBR_WELL_KNOWN_PORT_CONF_FILE);
}
}
@@ -1066,7 +1064,7 @@ static int parse_well_known_port_config(void)
}else if(strncasecmp("[UDP]", line_buf, strlen("UDP")) == 0){
last_section_proto = IPPROTO_UDP;
}else{
- sapp_log(RLOG_LV_FATAL, ~0, ~0, "[Error]parse cfg_file:%s error, onlye support TCP or UDP", ABBR_WELL_KNOWN_PORT_CONF_FILE);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "parse cfg_file:%s error, onlye support TCP or UDP", ABBR_WELL_KNOWN_PORT_CONF_FILE);
return -1;
}
continue;
@@ -1074,7 +1072,7 @@ static int parse_well_known_port_config(void)
tmpnum = atoi(line_buf);
if(tmpnum <=0 || tmpnum > 65535){
- sapp_log(RLOG_LV_FATAL, ~0, ~0, "[Error]parse cfg_file:%s error, port value invalid:%s", ABBR_WELL_KNOWN_PORT_CONF_FILE, line_buf);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "parse cfg_file:%s error, port value invalid:%s", ABBR_WELL_KNOWN_PORT_CONF_FILE, line_buf);
return -1;
}
@@ -1189,7 +1187,7 @@ static int config_expression_convert(void)
pconfig->packet_io.depolyment_mode_bin = DEPOLYMENT_MODE_TRANSPARENT;
sapp_global_val->individual_fixed.depolyment_mode_private = NET_CONN_SERIAL_2CARD;
}else{
- sapp_log(RLOG_LV_FATAL, ~0, ~0, "[Error]sapp.toml->PACKET_IO.depolyment.mode error, only support:%s!", "[mirror, inline, transparent]");
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "sapp.toml->PACKET_IO.depolyment.mode error, only support:%s!", "[mirror, inline, transparent]");
return -1;
}
@@ -1199,7 +1197,7 @@ static int config_expression_convert(void)
}else if(strncasecmp(tmp_str, "vxlan", strlen("vxlan")) == 0){
pconfig->packet_io.packet_io_tunnel.overlay_mode_bin = OVERLAY_MODE_VXLAN;
}else{
- sapp_log(RLOG_LV_FATAL, ~0, ~0, "[Error]sapp.toml->overlay_mode error, unsupport : %s", tmp_str);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "sapp.toml->overlay_mode error, unsupport : %s", tmp_str);
return -1;
}
@@ -1210,33 +1208,33 @@ static int config_expression_convert(void)
ret = parse_vlan_flipping_map_config();
if(ret < 0){
- sapp_log(RLOG_LV_FATAL, ~0, ~0, "[Error]%s parse error", ABBR_VLAN_FLIPPING_CONF_FILE);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "%s parse error", ABBR_VLAN_FLIPPING_CONF_FILE);
return- 1;
}
ret = parse_asymmetric_addr_layer_config();
if(ret < 0){
- sapp_log(RLOG_LV_FATAL, ~0, ~0, "[Error]%s parse error", ABBR_ASYM_LAYER_ADDR_CONF_FILE);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "%s parse error", ABBR_ASYM_LAYER_ADDR_CONF_FILE);
return- 1;
}
#if 0 /* 2021-05-06 lijia close, �ǶԳ�mpls�ijɶ�̬����streaminfo�ķ�ʽ���, ������Ҫ�����ղ�. */
ret = parse_asymmetric_presence_layer_config();
if(ret < 0){
- sapp_log(30, ~0, ~0, "[Error]%s parse error", sapp_global_val->config.packet_io.packet_io_tunnel.asymmetric_presence_layer_cfg_file);
+ sapp_log(30, ~0, ~0, "%s parse error", sapp_global_val->config.packet_io.packet_io_tunnel.asymmetric_presence_layer_cfg_file);
return- 1;
}
#endif
ret = parse_stream_compare_layer_config();
if(ret < 0){
- sapp_log(30, ~0, ~0, "[Error]%s parse error", ABBR_STREAM_CMP_LAYER_CONF_FILE);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "%s parse error", ABBR_STREAM_CMP_LAYER_CONF_FILE);
return- 1;
}
ret = parse_well_known_port_config();
if(ret < 0){
- sapp_log(30, ~0, ~0, "[Error]%s parse error", ABBR_WELL_KNOWN_PORT_CONF_FILE);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "%s parse error", ABBR_WELL_KNOWN_PORT_CONF_FILE);
return- 1;
}
@@ -1253,7 +1251,7 @@ static int config_expression_convert(void)
}else if(strncasecmp(tmp_str, "tun", strlen("tun")) == 0){
pconfig->packet_io.internal.interface.type_bin = CAP_MODEL_TUN;
}else{
- sapp_log(30, ~0, ~0, "[Error]sapp.toml->type error, unsupport : %s", tmp_str);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "sapp.toml->type error, unsupport : %s", tmp_str);
return -1;
}
@@ -1266,26 +1264,26 @@ static int config_expression_convert(void)
}else if(strncasecmp("raw_ethernet_multi_gateway", pconfig->packet_io.inject_pkt_mode_string, strlen("raw_ethernet_multi_gateway")) == 0){
pconfig->packet_io.inject_pkt_mode = SEND_PKT_MODE_STACK_2_LAYER_MUTI_ROUTE;
}else{
- sapp_log(30, ~0, ~0, "[Error]sapp.toml->PACKET_IO.inject_pkt_mode error, only support:%s!", "[sys_route, vxlan_by_inline_device, raw_ethernet_single_gateway, raw_ethernet_multi_gateway]");
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "sapp.toml->PACKET_IO.inject_pkt_mode error, only support:%s!", "[sys_route, vxlan_by_inline_device, raw_ethernet_single_gateway, raw_ethernet_multi_gateway]");
return -1;
}
if(strncasecmp(pconfig->packet_io.inject_pkt_mode_string, "raw_ethernet_single_gateway", strlen("raw_ethernet_single_gateway")) == 0){
if(MESA_mac_pton(pconfig->packet_io.inject_mode_single_gateway_dst_mac_string, ':', pconfig->packet_io.inject_mode_single_gateway_dst_mac) < 0){
- sapp_log(30, ~0, ~0, "[Error]sapp.toml->[packet_io.feature]->inject_mode_single_gateway_dst_mac error: %s", pconfig->packet_io.inject_mode_single_gateway_dst_mac_string);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "sapp.toml->[packet_io.feature]->inject_mode_single_gateway_dst_mac error: %s", pconfig->packet_io.inject_mode_single_gateway_dst_mac_string);
return -1;
}
if(MESA_get_dev_mac(pconfig->packet_io.inject_mode_single_gateway_device, (unsigned char *)pconfig->packet_io.inject_mode_single_gateway_src_mac) < 0){
- sapp_log(20, ~0, ~0, "[Warning]can't get sapp.toml->[packet_io.feature]->inject_mode_single_gateway_device: '%s' mac address", pconfig->packet_io.inject_mode_single_gateway_device);
+ sapp_runtime_log(RLOG_LV_INFO, "[Warning]can't get sapp.toml->[packet_io.feature]->inject_mode_single_gateway_device: '%s' mac address", pconfig->packet_io.inject_mode_single_gateway_device);
tomlc99_wrap_load_string_def(ABBR_CFG_FILE_MAIN_ENTRY, (char *)"packet_io.feature", (char *)"inject_mode_single_gateway_src_mac", pconfig->packet_io.inject_mode_single_gateway_src_mac_string, sizeof(pconfig->packet_io.inject_mode_single_gateway_src_mac_string), "$");
if('$' == pconfig->packet_io.inject_mode_single_gateway_src_mac_string[0]){
- sapp_log(30, ~0, ~0, "[Error]can't get local device '%s' mac address, and no valid inject_mode_single_gateway_src_mac", pconfig->packet_io.inject_mode_single_gateway_device);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "can't get local device '%s' mac address, and no valid inject_mode_single_gateway_src_mac", pconfig->packet_io.inject_mode_single_gateway_device);
return -1;
}
if(MESA_mac_pton(pconfig->packet_io.inject_mode_single_gateway_src_mac_string, ':', pconfig->packet_io.inject_mode_single_gateway_src_mac) < 0){
- sapp_log(30, ~0, ~0, "[Error]sapp.toml->[packet_io.feature]->inject_mode_single_gateway_src_mac error: %s", pconfig->packet_io.inject_mode_single_gateway_src_mac_string);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "sapp.toml->[packet_io.feature]->inject_mode_single_gateway_src_mac error: %s", pconfig->packet_io.inject_mode_single_gateway_src_mac_string);
return -1;
}
}
@@ -1303,7 +1301,7 @@ static int config_expression_convert(void)
}
if(parse_extract_linkdir_from_mac_cfg() < 0){
- sapp_log(30, ~0, ~0, "[Error]sapp.toml->extract_linkdir_from_mac_in_mirror_mode format error, must like 'ether[4]:0'");
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "sapp.toml->extract_linkdir_from_mac_in_mirror_mode format error, must like 'ether[4]:0'");
return -1;
}
@@ -1314,15 +1312,15 @@ static int config_expression_convert(void)
sapp_global_val->config.stream.stream_id_base_time_t = 0;
}else{
if(strptime(sapp_global_val->config.stream.stream_id_base_time_str, "%Y-%m-%d %H:%M:%S", &ttm) == NULL){
- sapp_log(30, ~0, ~0, "[Error]sapp.toml->STREAM.stream_id_base_time format error, must like '1970-01-01 01:02:03'");
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "sapp.toml->STREAM.stream_id_base_time format error, must like '1970-01-01 01:02:03'");
return -1;
}
if(mktime(&ttm) > time(NULL)){
- sapp_log(30, ~0, ~0, "[Error]sapp.toml->STREAM.stream_id_base_time value error, is after current system time!");
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "sapp.toml->STREAM.stream_id_base_time value error, is after current system time!");
return -1;
}
if(time(NULL) - mktime(&ttm) > 268435456L){
- sapp_log(30, ~0, ~0, "[Error]sapp.toml->STREAM.stream_id_base_time value error, sapp stream id support max time range is 8.5 year!");
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "sapp.toml->STREAM.stream_id_base_time value error, sapp stream id support max time range is 8.5 year!");
return -1;
}
sapp_global_val->config.stream.stream_id_base_time_t = mktime(&ttm);
@@ -1335,7 +1333,7 @@ static int config_expression_convert(void)
}else if(strncasecmp(pconfig->tools.pkt_dump.mode_str, "udp_socket" ,strlen("udp_socket")) == 0){
pconfig->tools.pkt_dump.mode_bin = PKT_DUMP_UDP_SOCKET;
}else{
- sapp_log(30, ~0, ~0, "[Error]TOOLS.PKT_DUMP.mode only support [storage, udp_socket]!");
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "TOOLS.PKT_DUMP.mode only support [storage, udp_socket]!");
return -1;
}
}
@@ -1373,9 +1371,9 @@ static int get_user_intention(void)
static inline void old_config_file_detect(const char *old_filename, const char *new_filename)
{
if(is_file_exist(old_filename)){
- sapp_log(30, ~0, ~0, "[Error]This is sapp v4.0, detect obsolete config file:\"%s\"! please use \"%s\" instead!", old_filename, new_filename);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "This is sapp v4.0, detect obsolete config file:\"%s\"! please use \"%s\" instead!", old_filename, new_filename);
if(is_file_exist(new_filename)){
- sapp_log(30, ~0, ~0, "You already have new config file:\"%s\", you must rename or delete obsolete file:\"%s\"!", new_filename, old_filename);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "You already have new config file:\"%s\", you must rename or delete obsolete file:\"%s\"!", new_filename, old_filename);
//sapp_log(30, ~0, ~0, "Are you sure you are using new config file? 'y' or 'n':");
//if(0 == get_user_intention()){
exit(1);
@@ -1411,25 +1409,24 @@ static int config_sanity_check(void)
phony_stream_pr.layer_index = 0xF;
assert(SAPP_SUPPORT_LAYER_NUM_MAX == phony_stream_pr.layer_index); /* �����ж��������޸���layer_index��SAPP_SUPPORT_LAYER_NUM_MAX, ����������һ�µ���� */
if(SAPP_SUPPORT_LAYER_NUM_MAX != phony_stream_pr.layer_index){
- sapp_log(30, ~0, ~0, "[Error]SAPP_SUPPORT_LAYER_NUM_MAX is:%d, but streaminfo_private->layer_index max is:%d", SAPP_SUPPORT_LAYER_NUM_MAX, phony_stream_pr.layer_index);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "SAPP_SUPPORT_LAYER_NUM_MAX is:%d, but streaminfo_private->layer_index max is:%d", SAPP_SUPPORT_LAYER_NUM_MAX, phony_stream_pr.layer_index);
return -1;
}
/******************************* CPU ********************************/
cur_cpu_num = get_nprocs();
- if(cur_cpu_num < pconfig->cpu.worker_threads){
- printf("\033[33m[Warning]sapp.toml->CPU.worker_threads=%d more than current available processors:%d\033[0m\n", sapp_global_val->config.cpu.worker_threads, cur_cpu_num);
+ if(cur_cpu_num < pconfig->cpu.worker_threads){
sapp_log(20, 0, ~0, "[Warning]sapp.toml->CPU.worker_threads=%d more than current available processors:%d", sapp_global_val->config.cpu.worker_threads, cur_cpu_num);
sleep(1);
}
if(sapp_global_val->config.cpu.send_only_threads_max_num > INDEPENDENT_SEND_QUEUE_MAX_NUM){
- sapp_log(30, ~0, ~0, "[Error]send_only_threads_max is:%d, but max support value is:%d", sapp_global_val->config.cpu.send_only_threads_max_num, INDEPENDENT_SEND_QUEUE_MAX_NUM);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "send_only_threads_max is:%d, but max support value is:%d", sapp_global_val->config.cpu.send_only_threads_max_num, INDEPENDENT_SEND_QUEUE_MAX_NUM);
return -1;
}
if(sapp_global_val->config.cpu.worker_threads + sapp_global_val->config.cpu.send_only_threads_max_num > INDEPENDENT_SEND_QUEUE_MAX_NUM){
- sapp_log(30, ~0, ~0, "[Error]send_only_threads_max + worker_threads is:%d, but max support send queue is:%d",
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "RLOG_LV_FATALsend_only_threads_max + worker_threads is:%d, but max support send queue is:%d",
sapp_global_val->config.cpu.send_only_threads_max_num + sapp_global_val->config.cpu.worker_threads,
INDEPENDENT_SEND_QUEUE_MAX_NUM);
return -1;
@@ -1437,8 +1434,8 @@ static int config_sanity_check(void)
if(pconfig->cpu.bind_mask_array_num > 0){
if(pconfig->cpu.worker_threads + pconfig->cpu.send_only_threads_max_num != pconfig->cpu.bind_mask_array_num){
- printf("\033[41m[Error]etc/sapp.toml->CPU->bind_mask value is not match etc/sapp.toml->CPU->worker_threads + CPU->send_only_threads_max!\033[0m\n");
- printf("\033[41m for example, worker_threads=4, send_only_threads_max=4, bind_mask should be [1,2,3,4,5,6,7,8].\033[0m\n");
+ sapp_log(RLOG_LV_FATAL, ~0, ~0,"sapp.toml->CPU->bind_mask value is not match etc/sapp.toml->CPU->worker_threads + CPU->send_only_threads_max!\n");
+ sapp_log(RLOG_LV_FATAL, ~0, ~0,"for example, worker_threads=4, send_only_threads_max=4, bind_mask should be [1,2,3,4,5,6,7,8]\n");
return -1;
}
@@ -1455,7 +1452,7 @@ static int config_sanity_check(void)
/******************************* STREAM ******************************/
if(pconfig->stream.tcp.inject.auto_remedy != 0){
if(pconfig->stream.tcp.inject.rst_num <= 0 || pconfig->stream.tcp.inject.rst_num >= 10){
- sapp_log(30, ~0, ~0, "[Error]sapp.toml->stream.tcp.inject.rst.number=%d, is Illegal!", pconfig->stream.tcp.inject.rst_num);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "sapp.toml->stream.tcp.inject.rst.number=%d, is Illegal!", pconfig->stream.tcp.inject.rst_num);
return -1;
}
}
@@ -1472,7 +1469,7 @@ static int config_sanity_check(void)
&&(strncasecmp(tmp_str, "inline", strlen("inline")) != 0)
&&(strncasecmp(tmp_str, "transparent", strlen("transparent")) != 0)
&&(strncasecmp(tmp_str, "dumpfile", strlen("dumpfile")) != 0)){
- printf("\033[1;31;40m[Error]sapp.toml->PACKET_IO.depolyment.mode error, only support:%s!\033[0m\n", "[mirror, inline, transparent, dumpfile]");
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "sapp.toml->PACKET_IO.depolyment.mode error, only support:%s!\n", "[mirror, inline, transparent, dumpfile]");
return -1;
}
@@ -1481,21 +1478,21 @@ static int config_sanity_check(void)
|| (strlen(pconfig->packet_io.internal.interface.name) <= 0)
||(pconfig->packet_io.internal.interface.type_str[0] == '\0')
|| (strlen(pconfig->packet_io.internal.interface.type_str) <= 0)){
- sapp_log(30, ~0, ~0, "depolyment_mode is transparent, must set internal interface parameters!");
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "depolyment_mode is transparent, must set internal interface parameters!");
return -1;
}
if((pconfig->packet_io.external.interface.name[0] == '\0')
|| (strlen(pconfig->packet_io.external.interface.name) <= 0)
||(pconfig->packet_io.external.interface.type_str[0] == '\0')
|| (strlen(pconfig->packet_io.external.interface.type_str) <= 0)){
- sapp_log(30, ~0, ~0, "depolyment_mode is transparent, must set external interface parameters!");
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "depolyment_mode is transparent, must set external interface parameters!");
return -1;
}
if(strncasecmp(pconfig->packet_io.internal.interface.type_str,
pconfig->packet_io.external.interface.type_str,
strlen(pconfig->packet_io.internal.interface.type_str)) != 0){
- sapp_log(30, ~0, ~0, "int transparent, internal and external interface type must be the same!");
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "int transparent, internal and external interface type must be the same!");
return -1;
}
}
@@ -1503,16 +1500,16 @@ static int config_sanity_check(void)
if(pconfig->packet_io.under_ddos_config.enabled){
if(pconfig->packet_io.under_ddos_config.bypass_trigger_cpu_usage < 1.0
|| pconfig->packet_io.under_ddos_config.bypass_trigger_cpu_usage >= 100.0){
- sapp_log(30, ~0, ~0, "[Error] [packet_io.under_ddos]->bypass_trigger_cpu_usage invalid!");
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "[packet_io.under_ddos]->bypass_trigger_cpu_usage invalid!");
return -1;
}
if(pconfig->packet_io.under_ddos_config.factor_decrease_ratio >= 1.0000){
- sapp_log(30, ~0, ~0, "[Error] [packet_io.under_ddos]->factor_decrease_ratio invalid, must smaller than 1.0!");
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "[packet_io.under_ddos]->factor_decrease_ratio invalid, must smaller than 1.0!");
return -1;
}
if(pconfig->packet_io.under_ddos_config.factor_increase_ratio <= 1.0000){
- sapp_log(30, ~0, ~0, "[Error] [packet_io.under_ddos]->factor_increase_ratio invalid, must bigger than 1.0!");
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "[packet_io.under_ddos]->factor_increase_ratio invalid, must bigger than 1.0!");
return -1;
}
}
@@ -1520,19 +1517,19 @@ static int config_sanity_check(void)
/******************************* PKT_DUMP ******************************/
if(pconfig->tools.pkt_dump.enabled != 0){
if(pconfig->tools.pkt_dump.dump_thread_id_array_num > pconfig->cpu.worker_threads){
- sapp_log(30, ~0, ~0, "[Error] TOOLS.PKT_DUMP.dump_thread_id_array items more than CPU.worker_threads!");
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "TOOLS.PKT_DUMP.dump_thread_id_array items more than CPU.worker_threads!");
return -1;
}
if((strncasecmp(pconfig->tools.pkt_dump.mode_str, "storage" ,strlen("storage")) != 0)
&& (strncasecmp(pconfig->tools.pkt_dump.mode_str, "udp_socket" ,strlen("udp_socket")) != 0)){
- sapp_log(30, ~0, ~0, "[Error]TOOLS.PKT_DUMP.mode only support [storage, udp_socket]!");
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "TOOLS.PKT_DUMP.mode only support [storage, udp_socket]!");
return -1;
}
if(strncasecmp(pconfig->tools.pkt_dump.mode_str, "udp_socket" ,strlen("udp_socket")) == 0){
if(pconfig->tools.pkt_dump.command_port <=0 || pconfig->tools.pkt_dump.command_port > 65535){
- sapp_log(30, ~0, ~0, "[Error] TOOLS.PKT_DUMP.command_port: %u invalid!", pconfig->tools.pkt_dump.command_port);
+ sapp_log(RLOG_LV_FATAL, ~0, ~0, "TOOLS.PKT_DUMP.command_port: %u invalid!", pconfig->tools.pkt_dump.command_port);
return -1;
}
}
@@ -1719,7 +1716,8 @@ int sapp_parse_config(void)
exit(1);
}
- sapp_log(RLOG_LV_INFO, ~0, ~0, "sapp use main config file: %s", ABBR_CFG_FILE_MAIN_ENTRY);
+ sapp_printf("sapp use main config file: %s\n", ABBR_CFG_FILE_MAIN_ENTRY);
+ sapp_runtime_log(RLOG_LV_INFO, "sapp use main config file: %s", ABBR_CFG_FILE_MAIN_ENTRY);
pconfig = &sapp_global_val->config;
@@ -1967,7 +1965,7 @@ int sapp_parse_config(void)
exit(1);
}
- sapp_log(10, 10, 10, "config parse success!");
+ sapp_runtime_log(RLOG_LV_INFO, "config parse success!");
return 0;
}
diff --git a/src/packet_io/cycle_pkt_dump_through_write_offset.c b/src/packet_io/cycle_pkt_dump_through_write_offset.c
index b72bed4..8bc7804 100644
--- a/src/packet_io/cycle_pkt_dump_through_write_offset.c
+++ b/src/packet_io/cycle_pkt_dump_through_write_offset.c
@@ -1445,7 +1445,8 @@ int cycle_pkt_dump_init(int argc, char *argv[])
printf("Catch SIGSEGV error!\n");
}
- sapp_log(20, 1, 1, "tools.pkt_dump enable, this maybe slow down performance!\n");
+ sapp_runtime_log(RLOG_LV_INFO, "tools.pkt_dump enable, this maybe slow down performance!\n");
+ sapp_printf("tools.pkt_dump enable, this maybe slow down performance!\n");
}else{
ret = cycle_pkt_dump_socket_init();
}
diff --git a/src/packet_io/packet_io_device.c b/src/packet_io/packet_io_device.c
index e235e7b..f4eb035 100644
--- a/src/packet_io/packet_io_device.c
+++ b/src/packet_io/packet_io_device.c
@@ -62,7 +62,7 @@ static int parse_send_raw_pkt_conf(void)
fp = fopen(ABBR_SEND_RAW_PKT_CONF_FILE, "r");
if(NULL == fp){
- printf("\033[41m[Error]open send raw pkt config file '%s' error!\033[0m\n", ABBR_SEND_RAW_PKT_CONF_FILE);
+ sapp_log(RLOG_LV_FATAL, 1, 1, "open send raw pkt config file '%s' error!\n", ABBR_SEND_RAW_PKT_CONF_FILE);
return -1;
}
@@ -81,7 +81,7 @@ static int parse_send_raw_pkt_conf(void)
tid = strtoul(section, NULL, 0);
if(tid > 1000){
- printf("\033[33mWarning! in '%s', target_id is too large!\033[0m\n", ABBR_SEND_RAW_PKT_CONF_FILE);
+ sapp_log(RLOG_LV_INFO, 1, 1,"[Warning] in '%s', target_id is too large!\n", ABBR_SEND_RAW_PKT_CONF_FILE);
sleep(1);
}
@@ -90,7 +90,7 @@ static int parse_send_raw_pkt_conf(void)
while(g_packet_io_cap_mode != column_index){ /* �ҵ���ǰ����ģʽ��Ӧ���� */
section = strtok_r(NULL, delim, &saveptr);
if(NULL == section){
- printf("\033[41m[Error]packet_io_mode is %d, but in %s not found related args!\033[0m\n", g_packet_io_cap_mode, ABBR_SEND_RAW_PKT_CONF_FILE);
+ sapp_log(RLOG_LV_FATAL, 1, 1,"packet_io_mode is %d, but in %s not found related args!\n", g_packet_io_cap_mode, ABBR_SEND_RAW_PKT_CONF_FILE);
return -1;
}
column_index++;
diff --git a/src/packet_io/packet_io_lib_load.c b/src/packet_io/packet_io_lib_load.c
index 145b96c..ff4a2f4 100644
--- a/src/packet_io/packet_io_lib_load.c
+++ b/src/packet_io/packet_io_lib_load.c
@@ -67,7 +67,7 @@ static int packet_io_lib_load_by_mode(int cap_mode, const char *full_lib_path)
io_lib_handle = dlopen(full_lib_path, RTLD_LAZY | RTLD_GLOBAL);
if(NULL == io_lib_handle){
- printf("\033[1;31;40m[Error]dlopen %s error, %s!\033[0m\n", full_lib_path, dlerror());
+ sapp_log(RLOG_LV_FATAL, 1, 1,"dlopen %s error, %s!\n", full_lib_path, dlerror());
return -1;
}
@@ -272,7 +272,7 @@ int packet_io_lib_load(int cap_mode)
char full_lib_path[PATH_MAX];
if(cap_mode < 0 || cap_mode > __CAP_MODEL_MAX){
- printf("\033[1;31;40m[Error]Unknown capture_mode:%d\033[0m\n", cap_mode);
+ sapp_log(RLOG_LV_FATAL, 1, 1,"Unknown capture_mode:%d\n", cap_mode);
return -1;
}
diff --git a/src/packet_io/packet_io_pcap.c b/src/packet_io/packet_io_pcap.c
index 9902487..f142bca 100644
--- a/src/packet_io/packet_io_pcap.c
+++ b/src/packet_io/packet_io_pcap.c
@@ -1439,10 +1439,8 @@ static void *pcap_io_thread(void *arg)
thread_exit:
*stop_flag = 1;
- sapp_usleep(10000);
- if(g_pcap_exit_cb_fun){
- (*g_pcap_exit_cb_fun)();
- }
+ sapp_usleep(1000);
+ sapp_set_current_state(SAPP_STATE_READY_TO_EXIT);
if(exit_prog_flag){
exit(0);
}
@@ -1498,7 +1496,7 @@ int pcap_dl_io_init(int argc, char *argv[])
pcap_up_handle = pcap_open_live(g_pcap_up_dev_name, PCAP_SNAPLEN_MAX,1,1,pcap_errbuf);
if(NULL == pcap_up_handle)
{
- printf("\033[1;31;40m[Error]Can't open device:'%s', %s\033[0m\n", g_pcap_up_dev_name, pcap_errbuf);
+ sapp_printf_colorful(RLOG_LV_FATAL, "[Error]Can't open device:'%s', %s\n", g_pcap_up_dev_name, pcap_errbuf);
return -1;
}
@@ -1580,26 +1578,27 @@ void pcap_dl_io_run(void)
long dir_down = DIR_ROUTE_DOWN;
pthread_create(&g_pcap_io_pid_up, NULL, pcap_io_thread, (void *)dir_up);
-
+ pthread_detach(g_pcap_io_pid_up);
+
if(NET_CONN_SERIAL_2CARD == g_pcap_topology_mode){ /* ˫��������ģʽ */
pthread_create(&g_pcap_io_pid_down, NULL, pcap_io_thread, (void *)dir_down);
+ pthread_detach(g_pcap_io_pid_down);
}
return;
}
+/* pcap ģʽ���ܱ�pcap_loop()����, ��Ҫ��������pcap_breakloop()�˳���ѭ��״̬ */
void pcap_dl_io_stop(void)
{
char *no_use;
if(sapp_get_cla_raw("dumpfile-list", &no_use) < 0){
if(pcap_up_handle){
pcap_breakloop(pcap_up_handle);
- pthread_join(g_pcap_io_pid_up, NULL);
}
if(pcap_down_handle){
pcap_breakloop(pcap_down_handle);
- pthread_join(g_pcap_io_pid_down, NULL);
}
}
}
diff --git a/src/packet_io/packet_io_status.cpp b/src/packet_io/packet_io_status.cpp
index 79e8400..8d89451 100644
--- a/src/packet_io/packet_io_status.cpp
+++ b/src/packet_io/packet_io_status.cpp
@@ -6,6 +6,7 @@ extern "C" {
#include "sapp_api.h"
#include "sapp_private_api.h"
+#include <stdarg.h>
volatile int update_packet_io_status_sw = 1;
diff --git a/src/packet_io/sendpacket.c b/src/packet_io/sendpacket.c
index 1bf39cc..5508185 100644
--- a/src/packet_io/sendpacket.c
+++ b/src/packet_io/sendpacket.c
@@ -282,13 +282,13 @@ int MESA_get_dev_mac(const char *device, unsigned char mac[6])
strncpy(ifr.ifr_ifrn.ifrn_name, device, sizeof(ifr.ifr_ifrn.ifrn_name));
if(ioctl(fd, SIOCGIFHWADDR, &ifr) == -1)
{
- printf("Cann't get hwaddr of %s:%s\n", device, strerror(errno));
+ //printf("Cann't get hwaddr of %s:%s\n", device, strerror(errno));
goto err_exit;
}
if(ifr.ifr_hwaddr.sa_family != ARPHRD_ETHER)
{
- printf("'%s' is not ethernet interface!\n", device);
+ //printf("'%s' is not ethernet interface!\n", device);
goto err_exit;
}
diff --git a/src/plugin/src/plugin.c b/src/plugin/src/plugin.c
index 24e83ea..f9840c0 100644
--- a/src/plugin/src/plugin.c
+++ b/src/plugin/src/plugin.c
@@ -916,7 +916,7 @@ int process_confelem_platentry(char* filename,void* fp_dlopen,char* plugname)
MESA_load_profile_string_nodef(filename,g_plugin_entryname[i],KEYWORD_FUNNAME,buf_funname,PLUGIN_MAX_CONFLEN);
if(buf_funname[0] == '\0')
{
- printf("\033[1;31;40m[Error]%s has [%s] and %s,but no %s\033[0m\n", filename,g_plugin_entryname[i],KEYWORD_FUNFLAG,KEYWORD_FUNNAME);
+ sapp_printf("\033[1;31;40m[Error]%s has [%s] and %s,but no %s\033[0m\n", filename,g_plugin_entryname[i],KEYWORD_FUNFLAG,KEYWORD_FUNNAME);
MESA_handle_runtime_log(g_plugin_runtime_handle,RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has [%s] and %s,but no %s",filename,g_plugin_entryname[i],KEYWORD_FUNFLAG,KEYWORD_FUNNAME);
return -1;
}
@@ -924,7 +924,7 @@ int process_confelem_platentry(char* filename,void* fp_dlopen,char* plugname)
fun_pointer = (char(*)())(dlsym(fp_dlopen,buf_funname));
if(fun_pointer == NULL)
{
- printf("\033[1;31;40m[Error]%s has [%s],but not load %s from %s sofile\033[0m\n", filename,g_plugin_entryname[i],buf_funname,plugname);
+ sapp_printf("\033[1;31;40m[Error]%s has [%s],but not load %s from %s sofile\033[0m\n", filename,g_plugin_entryname[i],buf_funname,plugname);
MESA_handle_runtime_log(g_plugin_runtime_handle,RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has [%s],but not load %s from %s sofile",filename,g_plugin_entryname[i],buf_funname,plugname);
return -1;
}
@@ -933,7 +933,7 @@ int process_confelem_platentry(char* filename,void* fp_dlopen,char* plugname)
ret=stream_register_fun(i,fun_pointer, plug_entry_id);
if(ret==-1)
{
- printf("\033[1;31;40m[Error]%s stream_register %s entry error\033[0m\n",filename,g_plugin_entryname[i]);
+ sapp_printf("\033[1;31;40m[Error]%s stream_register %s entry error\033[0m\n",filename,g_plugin_entryname[i]);
MESA_handle_runtime_log(g_plugin_runtime_handle,RLOG_LV_INFO, PLUGIN_LOGNAME,"%s stream_register %s entry error!",filename,g_plugin_entryname[i]);
}
else
@@ -1242,7 +1242,7 @@ int process_confelem_appentry(char* filename,stBusinessPlugInfo* pluginfo_bus)
pluginfo_pro = get_propluginfo_name(entryname);
if(pluginfo_pro == NULL)
{
- printf("\033[1;31;40m[Error]%s has %s entry,but ther is no protocol plug %s\033[0m\n", filename,entryname,entryname);
+ sapp_printf("\033[1;31;40m[Error]%s has %s entry,but ther is no protocol plug %s\033[0m\n", filename,entryname,entryname);
MESA_handle_runtime_log(g_plugin_runtime_handle,RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has %s entry,but ther is no protocol plug %s",filename,entryname,entryname);
return -1;
}
@@ -1257,7 +1257,7 @@ int process_confelem_appentry(char* filename,stBusinessPlugInfo* pluginfo_bus)
MESA_load_profile_string_nodef(filename,entryname,KEYWORD_FUNNAME,buf_funname,PLUGIN_MAX_CONFLEN);
if(buf_funname[0] =='\0')
{
- printf("\033[1;31;40m[Error]%s has [%s] and %s,but no %s\033[0m\n", filename,entryname,KEYWORD_FUNFLAG,KEYWORD_FUNNAME);
+ sapp_printf("\033[1;31;40m[Error]%s has [%s] and %s,but no %s\033[0m\n", filename,entryname,KEYWORD_FUNFLAG,KEYWORD_FUNNAME);
MESA_handle_runtime_log(g_plugin_runtime_handle,RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has [%s] and %s,but no %s",filename,entryname,KEYWORD_FUNFLAG,KEYWORD_FUNNAME);
return -1;
}
@@ -1265,7 +1265,7 @@ int process_confelem_appentry(char* filename,stBusinessPlugInfo* pluginfo_bus)
appentry = (char(*)(stSessionInfo* session_info, void **pme, int thread_seq,struct streaminfo *a_stream,const void *a_packet))(dlsym(file_point,buf_funname));
if(appentry == NULL)
{
- printf("\033[1;31;40m[Error]%s has %s in [%s],not load from %s sofile\033[0m\n", filename,buf_funname,entryname,pluginfo_bus->plugname);
+ sapp_printf("\033[1;31;40m[Error]%s has %s in [%s],not load from %s sofile\033[0m\n", filename,buf_funname,entryname,pluginfo_bus->plugname);
MESA_handle_runtime_log(g_plugin_runtime_handle,RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s has %s in [%s],not load from %s sofile",filename,buf_funname,entryname,pluginfo_bus->plugname);
return -1;
}
@@ -1274,7 +1274,7 @@ int process_confelem_appentry(char* filename,stBusinessPlugInfo* pluginfo_bus)
rec = stream_register_app(&(pluginfo_pro->fun_list),pluginfo_bus->plugid,appentry,flag, plug_entry_id);
if(rec < 0)
{
- printf("\033[1;31;40m[Error]%s's %s stream_register_app() error\033[0m\n", pluginfo_bus->plugname,buf_funname);
+ sapp_printf("\033[1;31;40m[Error]%s's %s stream_register_app() error\033[0m\n", pluginfo_bus->plugname,buf_funname);
MESA_handle_runtime_log(g_plugin_runtime_handle,RLOG_LV_FATAL, PLUGIN_LOGNAME,"%s's %s stream_register_app() error!",pluginfo_bus->plugname,buf_funname);
continue;
}
diff --git a/src/plugin/src/plugin_business.c b/src/plugin/src/plugin_business.c
index 325b09d..1fe2214 100644
--- a/src/plugin/src/plugin_business.c
+++ b/src/plugin/src/plugin_business.c
@@ -118,11 +118,9 @@ int process_confelem_business(char* confelem_filename)
g_business_plug_info = plug_info;
}
- //printf("\033[32m[Notice]%s, load %s success!\033[0m\n", PLUGIN_LOGNAME, plug_info->plugname);
MESA_handle_runtime_log(g_plugin_runtime_handle,RLOG_LV_FATAL, PLUGIN_LOGNAME,"load \033[32m%s\033[0m success!",plug_info->plugname);
return 0;
-
}
diff --git a/src/plugin/src/plugin_platform.c b/src/plugin/src/plugin_platform.c
index c6604e6..d2ff70f 100644
--- a/src/plugin/src/plugin_platform.c
+++ b/src/plugin/src/plugin_platform.c
@@ -92,12 +92,9 @@ int process_confelem_platform(char* confelem_filename)
g_platform_plug_info = plug_info;
}
- //printf("\033[32m[Notice]%s, load %s success!\033[0m\n", PLUGIN_LOGNAME, plug_info->plugname);
MESA_handle_runtime_log(g_plugin_runtime_handle,RLOG_LV_FATAL, PLUGIN_LOGNAME,"load \033[32m%s\033[0m success!",plug_info->plugname);
-
return 0;
-
}
diff --git a/src/plugin/src/plugin_protocol.c b/src/plugin/src/plugin_protocol.c
index 85ee122..746be3d 100644
--- a/src/plugin/src/plugin_protocol.c
+++ b/src/plugin/src/plugin_protocol.c
@@ -160,10 +160,8 @@ int process_confelem_protocol(char* confelem_filename)
g_protocol_plug_info = plug_info;
}
- //printf("\033[32m[Notice]%s, load %s success!\033[0m\n", PLUGIN_LOGNAME, plug_info->plugname);
MESA_handle_runtime_log(g_plugin_runtime_handle,RLOG_LV_FATAL, PLUGIN_LOGNAME,"load \033[32m%s\033[0m success!",plug_info->plugname);
return 0;
-
}
diff --git a/src/project/project_requirement.c b/src/project/project_requirement.c
index 20c3a96..4cc3303 100644
--- a/src/project/project_requirement.c
+++ b/src/project/project_requirement.c
@@ -99,7 +99,7 @@ static int __project_find_id_by_name(const char *project_req_name, const char *p
}
}
if(NULL == preq_man || -1 == pro_req_id){
- //printf("can't found project name:'%s' in %s\n", project_req_name, ABBR_PROJECT_LIST_CONF_FILE);
+ sapp_runtime_log(RLOG_LV_FATAL, "can't found project name:'%s' in %s\n", project_req_name, ABBR_PROJECT_LIST_CONF_FILE);
return -1;
}
@@ -264,7 +264,8 @@ static int project_req_conf_is_exist(const char *check_name)
preq_name = strtok_r(line_buf, delim, &save_ptr);
if(NULL == preq_name){
- printf("invalid conf in %s, line %d\n", ABBR_PROJECT_LIST_CONF_FILE, line_num);
+ sapp_printf("invalid conf in %s, line %d\n", ABBR_PROJECT_LIST_CONF_FILE, line_num);
+ sapp_runtime_log(RLOG_LV_INFO, "invalid conf in %s, line %d\n", ABBR_PROJECT_LIST_CONF_FILE, line_num);
goto fun_exit;
}
diff --git a/src/sapp_dev/sapp_init.c b/src/sapp_dev/sapp_init.c
index 554843f..1bdaaae 100644
--- a/src/sapp_dev/sapp_init.c
+++ b/src/sapp_dev/sapp_init.c
@@ -88,10 +88,10 @@ static void sapp_dictator_init(void)
assert(tmp != NULL);
free(tmp);
}else{
- printf("\033[33m[Warning]dictator is not enable, maybe slow down performance, please check 'sapp.toml -> dictator_enable'.\033[0m\n");
+ sapp_printf("\033[33m[Warning]dictator is not enable, maybe slow down performance, please check 'sapp.toml -> dictator_enable'.\033[0m\n");
}
#else
- printf("\033[33m[Warning]sapp is compiled without dictator.\033[0m\n");
+ sapp_printf("\033[33m[Warning]sapp is compiled without dictator.\033[0m\n");
#endif
}
@@ -156,18 +156,18 @@ int MESA_platform_init(int argc, char *argv[])
MESA_load_profile_int_def("conf/main.conf","Module", "encapsulate_with_ddp", &g_encapsulate_with_ddp, 0);
if(g_encapsulate_with_ddp != 0){
- printf("\033[32m[Notice] '%s' is enable!\033[0m\n", "encapsulate_with_ddp");
+ sapp_printf("\033[32m[Notice] '%s' is enable!\033[0m\n", "encapsulate_with_ddp");
sleep(1);
}
MESA_load_profile_int_def("conf/main.conf","Module", "encapsulate_with_L2E", &g_encapsulate_with_L2E, 0);
if(g_encapsulate_with_L2E != 0){
- printf("\033[32m[Notice] '%s' is enable!\033[0m\n", "encapsulate_with_L2E");
+ sapp_printf("\033[32m[Notice] '%s' is enable!\033[0m\n", "encapsulate_with_L2E");
sleep(1);
}
if((g_encapsulate_with_ddp != 0) && (g_encapsulate_with_L2E != 0)){
- printf("\033[1;31;40m[Error]g_encapsulate_with_ddp is conflict with g_encapsulate_with_L2E, can't enable simultaneously at all!\033[0m\n");
+ sapp_printf("\033[1;31;40m[Error]g_encapsulate_with_ddp is conflict with g_encapsulate_with_L2E, can't enable simultaneously at all!\033[0m\n");
return -1;
}
diff --git a/src/sapp_dev/sapp_plug.c b/src/sapp_dev/sapp_plug.c
index 78b3f11..cedac25 100644
--- a/src/sapp_dev/sapp_plug.c
+++ b/src/sapp_dev/sapp_plug.c
@@ -71,12 +71,13 @@ static void show_mesa_log(void)
for(i = 0; (i < sizeof(MESA_art_log)) && (MESA_art_log[i] != 0); i ++){
//putchar(MESA_log[i]);
- printf("%c", MESA_art_log[i]);
+ sapp_printf("%c", MESA_art_log[i]);
}
- printf("\n");
+ sapp_printf("\n");
sapp_runtime_log(30, "\n\n%s", MESA_art_log);
}
+/* �����ȴ���Ҫ���߳�������� */
static void sapp_wait_for_required_thread_starting(void)
{
int tseq;
@@ -92,6 +93,17 @@ static void sapp_wait_for_required_thread_starting(void)
}
}
+static void *sapp_monitor_thread(void *args)
+{
+ while(sapp_get_current_state() == SAPP_STATE_PROCESSING){
+ usleep(1000);
+ }
+
+ libsapp_destroy_env();
+
+ return NULL;
+}
+
int libsapp_setup_env(int argc, char *argv[])
{
@@ -148,14 +160,17 @@ int libsapp_setup_env(int argc, char *argv[])
sapp_wait_for_required_thread_starting();
- //TODO: dumpfileģʽ���������Զ��˳�, ����һֱ����
- //�������ź�, �����������߳�ǿ�е���sapp_destroy_env()
-#if 0
- while((SAPP_STATE_PROCESSING == sapp_global_val->individual_volatile->current_state)
- && (sapp_global_val->config.packet_io.depolyment_mode_bin)){
- usleep(1);
- }
-#endif
+ /*
+ ���г�ʼ���͹����̶߳���������,
+ �ó�cpu, ����ģ�����libsapp_setup_env()֮����Լ���ִ��, �����DZ�����, ��������߼��ͺ��Ѵ���.
+ dumpfileģʽ���������Զ��˳�, ����һֱ����,
+ �����������߳�ǿ�е���libsapp_destroy_env()
+ */
+
+ pthread_t pid;
+ pthread_create(&pid, NULL, sapp_monitor_thread, NULL);
+ pthread_detach(pid);
+
return 0;
}
diff --git a/src/support/dictator2/src/dictator.cpp b/src/support/dictator2/src/dictator.cpp
index 3786383..2de2deb 100644
--- a/src/support/dictator2/src/dictator.cpp
+++ b/src/support/dictator2/src/dictator.cpp
@@ -231,7 +231,7 @@ thread_mem_pool_t* init_dictator(pthread_t tid)
pthread_attr_destroy(&(attr));
memset(boundary_marker,'d',D_MARKER_SIZE);
#else
- fprintf(stderr,"Using DICTATOR2 memory manager\n");
+ ;//fprintf(stderr,"Using DICTATOR2 memory manager\n");
#endif
return p_mempool;
}