name changes

This commit is contained in:
Sukchan Lee 2017-11-27 15:45:33 +09:00
parent f9fe704ccb
commit aaa57d3008
16 changed files with 152 additions and 149 deletions

View File

@ -25,10 +25,10 @@ extern int g_trace_mask;
#define D_MSG_TO_CONSOLE 0x00000001
#define D_MSG_TO_STDOUT 0x00000002
#define D_MSG_TO_SYSLOG 0x00000004
#define D_MSG_TO_SOCKET 0x00000008
#define D_MSG_TO_NETWORK 0x00000008
#define D_MSG_TO_FILE 0x00000010
#define D_MSG_TO_ALL (D_MSG_TO_CONSOLE | D_MSG_TO_STDOUT | \
D_MSG_TO_SYSLOG | D_MSG_TO_SOCKET | \
D_MSG_TO_SYSLOG | D_MSG_TO_NETWORK | \
D_MSG_TO_FILE )
#define D_LOG_LEVEL_NONE 0
@ -144,11 +144,11 @@ status_t d_msg_console_init(int console_fd);
void d_msg_console_final();
void d_msg_syslog_init(const char *name);
void d_msg_syslog_final();
status_t d_msg_socket_init(const char *name);
void d_msg_socket_final();
status_t d_msg_socket_start(const char *file);
void d_msg_socket_stop();
void d_msg_socket_final();
status_t d_msg_network_init(const char *name);
void d_msg_network_final();
status_t d_msg_network_start(const char *file);
void d_msg_network_stop();
void d_msg_network_final();
status_t d_msg_file_init(const char *file);
void d_msg_file_final();

View File

@ -14,22 +14,22 @@ int g_msg_to = D_MSG_TO_STDOUT;
int g_console_connected = 0;
int g_syslog_connected = 0;
int g_socket_connected = 0;
int g_network_connected = 0;
int g_file_connected = 0;
int g_log_level_console = D_LOG_LEVEL_FULL;
int g_log_level_stdout = D_LOG_LEVEL_FULL;
int g_log_level_syslog = D_LOG_LEVEL_FULL;
int g_log_level_socket = D_LOG_LEVEL_FULL;
int g_log_level_network = D_LOG_LEVEL_FULL;
int g_log_level_file = D_LOG_LEVEL_FULL;
static int g_console_fd = -1;
static int g_socket_fd = -1;
static struct sockaddr_un g_socket_addr;
static int g_network_fd = -1;
static struct sockaddr_un g_network_addr;
static thread_id socket_thread = 0;
static void *THREAD_FUNC socket_main(thread_id id, void *data);
static int socket_handler(const char *path);
static thread_id network_thread = 0;
static void *THREAD_FUNC network_main(thread_id id, void *data);
static int network_handler(const char *path);
static file_t *g_file = NULL;
@ -64,57 +64,57 @@ void d_msg_syslog_final()
closelog();
}
status_t d_msg_socket_init(const char *name)
status_t d_msg_network_init(const char *name)
{
d_assert(name, return CORE_ERROR, );
g_socket_fd = socket(AF_UNIX, SOCK_DGRAM, 0);
d_assert(g_socket_fd >= 0, return CORE_ERROR,
g_network_fd = socket(AF_UNIX, SOCK_DGRAM, 0);
d_assert(g_network_fd >= 0, return CORE_ERROR,
"socket() failed. (%d:%s)\n", errno, strerror(errno));
g_socket_addr.sun_family = AF_UNIX;
strcpy(g_socket_addr.sun_path, name);
g_network_addr.sun_family = AF_UNIX;
strcpy(g_network_addr.sun_path, name);
return CORE_OK;
}
status_t d_msg_socket_start(const char *file)
status_t d_msg_network_start(const char *file)
{
status_t rv;
d_assert(file, return CORE_ERROR, );
rv = thread_create(&socket_thread, NULL, socket_main, (void*)file);
rv = thread_create(&network_thread, NULL, network_main, (void*)file);
d_assert(rv == CORE_OK, return CORE_ERROR,
"socket thread creation failed");
"network thread creation failed");
g_socket_connected = 1;
d_msg_to(D_MSG_TO_SOCKET, 1);
g_network_connected = 1;
d_msg_to(D_MSG_TO_NETWORK, 1);
return CORE_OK;
}
void d_msg_socket_stop()
void d_msg_network_stop()
{
d_msg_to(D_MSG_TO_SOCKET, 0);
g_socket_connected = 0;
d_msg_to(D_MSG_TO_NETWORK, 0);
g_network_connected = 0;
if (socket_thread)
thread_delete(socket_thread);
if (network_thread)
thread_delete(network_thread);
}
void d_msg_socket_final()
void d_msg_network_final()
{
close(g_socket_fd);
g_socket_fd = -1;
close(g_network_fd);
g_network_fd = -1;
}
static void *THREAD_FUNC socket_main(thread_id id, void *data)
static void *THREAD_FUNC network_main(thread_id id, void *data)
{
int ret;
char *path = data;
ret = socket_handler(path);
ret = network_handler(path);
if (ret != 0)
{
d_error("Failed to initialize logger.");
@ -124,7 +124,7 @@ static void *THREAD_FUNC socket_main(thread_id id, void *data)
return NULL;
}
static int socket_handler(const char *path)
static int network_handler(const char *path)
{
status_t rv;
int ret;
@ -143,7 +143,7 @@ static int socket_handler(const char *path)
d_error("socket() failed. (%d:%s)", errno, strerror(errno));
return -1;
}
memcpy(&svaddr, &g_socket_addr, sizeof(struct sockaddr_un));
memcpy(&svaddr, &g_network_addr, sizeof(struct sockaddr_un));
ret = bind(us, (struct sockaddr *)&svaddr, sizeof(svaddr));
if (ret != 0)
@ -281,10 +281,10 @@ void d_msg_to(int to, int on_off)
g_msg_to | D_MSG_TO_SYSLOG :
g_msg_to & ~D_MSG_TO_SYSLOG;
break;
case D_MSG_TO_SOCKET:
case D_MSG_TO_NETWORK:
g_msg_to = on_off ?
g_msg_to | D_MSG_TO_SOCKET :
g_msg_to & ~D_MSG_TO_SOCKET;
g_msg_to | D_MSG_TO_NETWORK :
g_msg_to & ~D_MSG_TO_NETWORK;
break;
case D_MSG_TO_FILE:
g_msg_to = on_off ?
@ -317,17 +317,18 @@ void d_log_set_level(int to, int level)
case D_MSG_TO_SYSLOG:
g_log_level_syslog = level;
break;
case D_MSG_TO_SOCKET:
g_log_level_socket = level;
case D_MSG_TO_NETWORK:
g_log_level_network = level;
break;
case D_MSG_TO_FILE:
g_log_level_socket = level;
g_log_level_file = level;
break;
case D_MSG_TO_ALL:
g_log_level_console = level;
g_log_level_stdout = level;
g_log_level_syslog = level;
g_log_level_socket = level;
g_log_level_network = level;
g_log_level_file = level;
break;
default:
break;
@ -344,10 +345,10 @@ int d_log_get_level(int to)
return g_log_level_stdout;
case D_MSG_TO_SYSLOG:
return g_log_level_syslog;
case D_MSG_TO_SOCKET:
return g_log_level_socket;
case D_MSG_TO_NETWORK:
return g_log_level_network;
case D_MSG_TO_FILE:
return g_log_level_socket;
return g_log_level_file;
default:
break;
}
@ -368,17 +369,18 @@ void d_log_full(int to)
case D_MSG_TO_SYSLOG:
g_log_level_syslog = D_LOG_LEVEL_FULL;
break;
case D_MSG_TO_SOCKET:
g_log_level_socket = D_LOG_LEVEL_FULL;
case D_MSG_TO_NETWORK:
g_log_level_network = D_LOG_LEVEL_FULL;
break;
case D_MSG_TO_FILE:
g_log_level_socket = D_LOG_LEVEL_FULL;
g_log_level_file = D_LOG_LEVEL_FULL;
break;
case D_MSG_TO_ALL:
g_log_level_console = D_LOG_LEVEL_FULL;
g_log_level_stdout = D_LOG_LEVEL_FULL;
g_log_level_syslog = D_LOG_LEVEL_FULL;
g_log_level_socket = D_LOG_LEVEL_FULL;
g_log_level_network = D_LOG_LEVEL_FULL;
g_log_level_file = D_LOG_LEVEL_FULL;
break;
default:
break;
@ -398,17 +400,18 @@ void d_log_off(int to)
case D_MSG_TO_SYSLOG:
g_log_level_syslog = D_LOG_LEVEL_NONE;
break;
case D_MSG_TO_SOCKET:
g_log_level_socket = D_LOG_LEVEL_NONE;
case D_MSG_TO_NETWORK:
g_log_level_network = D_LOG_LEVEL_NONE;
break;
case D_MSG_TO_FILE:
g_log_level_socket = D_LOG_LEVEL_NONE;
g_log_level_file = D_LOG_LEVEL_NONE;
break;
case D_MSG_TO_ALL:
g_log_level_console = D_LOG_LEVEL_NONE;
g_log_level_stdout = D_LOG_LEVEL_NONE;
g_log_level_syslog = D_LOG_LEVEL_NONE;
g_log_level_socket = D_LOG_LEVEL_NONE;
g_log_level_network = D_LOG_LEVEL_NONE;
g_log_level_file = D_LOG_LEVEL_NONE;
break;
default:
break;
@ -497,10 +500,10 @@ int d_msg(int tp, int lv, c_time_t t, char *fn, int ln, char *fmt, ...)
{
syslog(LOG_DEBUG, "%s", fstr);
}
if (g_socket_connected && (g_msg_to & D_MSG_TO_SOCKET))
if (g_network_connected && (g_msg_to & D_MSG_TO_NETWORK))
{
sendto(g_socket_fd, fstr, n, 0,
(struct sockaddr *)&g_socket_addr, sizeof(g_socket_addr));
sendto(g_network_fd, fstr, n, 0,
(struct sockaddr *)&g_network_addr, sizeof(g_network_addr));
}
if (g_file_connected && (g_msg_to & D_MSG_TO_FILE))
{
@ -529,10 +532,10 @@ int d_msg(int tp, int lv, c_time_t t, char *fn, int ln, char *fmt, ...)
{
syslog(LOG_DEBUG, "%s", fstr);
}
if (g_socket_connected && (g_msg_to & D_MSG_TO_SOCKET))
if (g_network_connected && (g_msg_to & D_MSG_TO_NETWORK))
{
sendto(g_socket_fd, fstr, n, 0,
(struct sockaddr *)&g_socket_addr, sizeof(g_socket_addr));
sendto(g_network_fd, fstr, n, 0,
(struct sockaddr *)&g_network_addr, sizeof(g_network_addr));
}
if (g_file_connected && (g_msg_to & D_MSG_TO_FILE))
{
@ -577,12 +580,12 @@ int d_msg(int tp, int lv, c_time_t t, char *fn, int ln, char *fmt, ...)
{
syslog(LOG_INFO, "[%s\n", fstr + 13);
}
if (g_socket_connected && (g_msg_to & D_MSG_TO_SOCKET) &&
lv <= g_log_level_socket)
if (g_network_connected && (g_msg_to & D_MSG_TO_NETWORK) &&
lv <= g_log_level_network)
{
fstr[n++] = '\n';
sendto(g_socket_fd, fstr, n, 0,
(struct sockaddr *)&g_socket_addr, sizeof(g_socket_addr));
sendto(g_network_fd, fstr, n, 0,
(struct sockaddr *)&g_network_addr, sizeof(g_network_addr));
}
if (g_file_connected && (g_msg_to & D_MSG_TO_FILE))
{
@ -616,11 +619,11 @@ int d_msg(int tp, int lv, c_time_t t, char *fn, int ln, char *fmt, ...)
{
syslog(LOG_CRIT, "[%s\n", fstr + 13);
}
if (g_socket_connected && (g_msg_to & D_MSG_TO_SOCKET))
if (g_network_connected && (g_msg_to & D_MSG_TO_NETWORK))
{
fstr[n++] = '\n';
sendto(g_socket_fd, fstr, n, 0,
(struct sockaddr *)&g_socket_addr, sizeof(g_socket_addr));
sendto(g_network_fd, fstr, n, 0,
(struct sockaddr *)&g_network_addr, sizeof(g_network_addr));
}
if (g_file_connected && (g_msg_to & D_MSG_TO_FILE))
{

View File

@ -125,7 +125,7 @@ status_t context_read_old_file()
static status_t context_prepare()
{
self.log.console = -1;
self.logger.console = -1;
return CORE_OK;
}
@ -179,16 +179,16 @@ status_t context_parse_config()
d_assert(logger_key, return CORE_ERROR,);
if (!strcmp(logger_key, "file"))
{
self.log.file = YAML_MAPPING_VALUE(document, logger_pair);
self.logger.file = YAML_MAPPING_VALUE(document, logger_pair);
}
else if (!strcmp(logger_key, "console"))
{
const char *v = YAML_MAPPING_VALUE(document, logger_pair);
if (v) self.log.console = atoi(v);
if (v) self.logger.console = atoi(v);
}
else if (!strcmp(logger_key, "syslog"))
{
self.log.syslog = YAML_MAPPING_VALUE(document, logger_pair);
self.logger.syslog = YAML_MAPPING_VALUE(document, logger_pair);
}
else if (!strcmp(logger_key, "network"))
{
@ -206,14 +206,14 @@ status_t context_parse_config()
const char *network_key =
YAML_MAPPING_KEY(document, network_pair);
d_assert(network_key, return CORE_ERROR,);
if (!strcmp(network_key, "path"))
if (!strcmp(network_key, "file"))
{
self.log.socket.file =
self.logger.network.file =
YAML_MAPPING_VALUE(document, network_pair);
}
else if (!strcmp(network_key, "unixDomain"))
{
self.log.socket.unix_domain =
self.logger.network.unix_domain =
YAML_MAPPING_VALUE(document, network_pair);
}
}
@ -238,31 +238,31 @@ status_t context_parse_config()
{
const char *v =
YAML_MAPPING_VALUE(document, trace_pair);
if (v) self.trace_level.s1ap = atoi(v);
if (v) self.logger.trace.s1ap = atoi(v);
}
else if (!strcmp(trace_key, "nas"))
{
const char *v =
YAML_MAPPING_VALUE(document, trace_pair);
if (v) self.trace_level.nas = atoi(v);
if (v) self.logger.trace.nas = atoi(v);
}
else if (!strcmp(trace_key, "diameter"))
{
const char *v =
YAML_MAPPING_VALUE(document, trace_pair);
if (v) self.trace_level.fd = atoi(v);
if (v) self.logger.trace.fd = atoi(v);
}
else if (!strcmp(trace_key, "gtp"))
{
const char *v =
YAML_MAPPING_VALUE(document, trace_pair);
if (v) self.trace_level.gtp = atoi(v);
if (v) self.logger.trace.gtp = atoi(v);
}
else if (!strcmp(trace_key, "others"))
{
const char *v =
YAML_MAPPING_VALUE(document, trace_pair);
if (v) self.trace_level.others = atoi(v);
if (v) self.logger.trace.others = atoi(v);
}
}
}

View File

@ -36,17 +36,17 @@ typedef struct _context_t {
struct {
const char *unix_domain;
const char *file;
} socket;
} network;
const char *file;
} log;
struct {
int s1ap;
int nas;
int gtp;
int fd;
int others;
} trace_level;
struct {
int s1ap;
int nas;
int gtp;
int fd;
int others;
} trace;
} logger;
struct {
/* Element */

View File

@ -45,13 +45,13 @@ status_t app_will_initialize(const char *config_path, const char *log_path)
rv = context_parse_config();
if (rv != CORE_OK) return rv;
others = context_self()->trace_level.others;
others = context_self()->logger.trace.others;
if (others)
{
d_trace_level(&_app_init, others);
}
context_self()->log.path = log_path;
context_self()->logger.path = log_path;
rv = app_logger_init();
if (rv != CORE_OK) return rv;
@ -146,53 +146,53 @@ static status_t app_logger_init()
{
status_t rv;
if (context_self()->log.console >= 0)
if (context_self()->logger.console >= 0)
{
rv = d_msg_console_init(context_self()->log.console);
rv = d_msg_console_init(context_self()->logger.console);
if (rv != CORE_OK)
{
d_error("console logger init failed : (file:%d)",
context_self()->log.console);
context_self()->logger.console);
return rv;
}
d_print(" Console Logging '%d'\n", context_self()->log.console);
d_print(" Console Logging '%d'\n", context_self()->logger.console);
}
if (context_self()->log.syslog)
if (context_self()->logger.syslog)
{
d_msg_syslog_init(context_self()->log.syslog);
d_print(" Syslog Logging '%s'\n", context_self()->log.syslog);
d_msg_syslog_init(context_self()->logger.syslog);
d_print(" Syslog Logging '%s'\n", context_self()->logger.syslog);
}
if (context_self()->log.socket.file &&
context_self()->log.socket.unix_domain)
if (context_self()->logger.network.file &&
context_self()->logger.network.unix_domain)
{
if (context_self()->log.path)
context_self()->log.socket.file = context_self()->log.path;
if (context_self()->logger.path)
context_self()->logger.network.file = context_self()->logger.path;
rv = d_msg_socket_init(context_self()->log.socket.unix_domain);
rv = d_msg_network_init(context_self()->logger.network.unix_domain);
if (rv != CORE_OK)
{
d_error("socket logger init failed : (unix_domain:%s, file:%s)",
context_self()->log.socket.unix_domain,
context_self()->log.socket.file);
d_error("Network logger init failed : (unix_domain:%s, file:%s)",
context_self()->logger.network.unix_domain,
context_self()->logger.network.file);
return rv;
}
d_print(" Socket Logging '%s' on %s\n",
context_self()->log.socket.file,
context_self()->log.socket.unix_domain);
d_print(" Network Logging '%s' on %s\n",
context_self()->logger.network.file,
context_self()->logger.network.unix_domain);
}
if (context_self()->log.file)
if (context_self()->logger.file)
{
if (context_self()->log.path)
context_self()->log.file = context_self()->log.path;
if (context_self()->logger.path)
context_self()->logger.file = context_self()->logger.path;
rv = d_msg_file_init(context_self()->log.file);
rv = d_msg_file_init(context_self()->logger.file);
if (rv != CORE_OK)
{
d_error("file logger init failed : (file:%s)",
context_self()->log.file);
context_self()->logger.file);
return rv;
}
d_print(" File Logging '%s'\n", context_self()->log.file);
d_print(" File Logging '%s'\n", context_self()->logger.file);
}
return CORE_OK;
@ -203,15 +203,15 @@ static status_t app_logger_start()
{
status_t rv;
if (context_self()->log.socket.file &&
context_self()->log.socket.unix_domain)
if (context_self()->logger.network.file &&
context_self()->logger.network.unix_domain)
{
rv = d_msg_socket_start(context_self()->log.socket.file);
rv = d_msg_network_start(context_self()->logger.network.file);
if (rv != CORE_OK)
{
d_error("socket logger start failed : (unix_domain:%s, file:%s)",
context_self()->log.socket.unix_domain,
context_self()->log.socket.file);
d_error("Network logger start failed : (unix_domain:%s, file:%s)",
context_self()->logger.network.unix_domain,
context_self()->logger.network.file);
return rv;
}
}
@ -221,10 +221,10 @@ static status_t app_logger_start()
static status_t app_logger_stop()
{
if (context_self()->log.socket.file &&
context_self()->log.socket.unix_domain)
if (context_self()->logger.network.file &&
context_self()->logger.network.unix_domain)
{
d_msg_socket_stop();
d_msg_network_stop();
}
return CORE_OK;
@ -232,20 +232,20 @@ static status_t app_logger_stop()
static status_t app_logger_final()
{
if (context_self()->log.console >= 0)
if (context_self()->logger.console >= 0)
{
d_msg_console_final();
}
if (context_self()->log.syslog)
if (context_self()->logger.syslog)
{
d_msg_syslog_final();
}
if (context_self()->log.socket.file &&
context_self()->log.socket.unix_domain)
if (context_self()->logger.network.file &&
context_self()->logger.network.unix_domain)
{
d_msg_socket_final();
d_msg_network_final();
}
if (context_self()->log.file)
if (context_self()->logger.file)
{
d_msg_file_final();
}

View File

@ -30,7 +30,7 @@ status_t app_initialize(const char *config_path, const char *log_path)
rv = app_will_initialize(config_path, log_path);
if (rv != CORE_OK) return rv;
others = context_self()->trace_level.others;
others = context_self()->logger.trace.others;
if (others)
{
d_trace_level(&_epc_main, others);

View File

@ -17,7 +17,7 @@ status_t app_initialize(const char *config_path, const char *log_path)
rv = app_will_initialize(config_path, log_path);
if (rv != CORE_OK) return rv;
others = context_self()->trace_level.others;
others = context_self()->logger.trace.others;
if (others)
{
d_trace_level(&_hss_main, others);

View File

@ -111,8 +111,8 @@ status_t hss_context_parse_config()
status_t hss_context_setup_trace_module()
{
int fd = context_self()->trace_level.fd;
int others = context_self()->trace_level.others;
int fd = context_self()->logger.trace.fd;
int others = context_self()->logger.trace.others;
if (fd)
{

View File

@ -17,7 +17,7 @@ status_t app_initialize(const char *config_path, const char *log_path)
rv = app_will_initialize(config_path, log_path);
if (rv != CORE_OK) return rv;
others = context_self()->trace_level.others;
others = context_self()->logger.trace.others;
if (others)
{
d_trace_level(&_mme_main, others);

View File

@ -920,11 +920,11 @@ status_t mme_context_parse_config()
status_t mme_context_setup_trace_module()
{
int s1ap = context_self()->trace_level.s1ap;
int nas = context_self()->trace_level.nas;
int fd = context_self()->trace_level.fd;
int gtp = context_self()->trace_level.gtp;
int others = context_self()->trace_level.others;
int s1ap = context_self()->logger.trace.s1ap;
int nas = context_self()->logger.trace.nas;
int fd = context_self()->logger.trace.fd;
int gtp = context_self()->logger.trace.gtp;
int others = context_self()->logger.trace.others;
if (s1ap)
{

View File

@ -17,7 +17,7 @@ status_t app_initialize(const char *config_path, const char *log_path)
rv = app_will_initialize(config_path, log_path);
if (rv != CORE_OK) return rv;
others = context_self()->trace_level.others;
others = context_self()->logger.trace.others;
if (others)
{
d_trace_level(&_pcrf_main, others);

View File

@ -112,8 +112,8 @@ status_t pcrf_context_parse_config()
status_t pcrf_context_setup_trace_module()
{
int fd = context_self()->trace_level.fd;
int others = context_self()->trace_level.others;
int fd = context_self()->logger.trace.fd;
int others = context_self()->logger.trace.others;
if (fd)
{

View File

@ -17,7 +17,7 @@ status_t app_initialize(const char *config_path, const char *log_path)
rv = app_will_initialize(config_path, log_path);
if (rv != CORE_OK) return rv;
others = context_self()->trace_level.others;
others = context_self()->logger.trace.others;
if (others)
{
d_trace_level(&_pgw_main, others);

View File

@ -333,9 +333,9 @@ status_t pgw_context_parse_config()
status_t pgw_context_setup_trace_module()
{
int fd = context_self()->trace_level.fd;
int gtp = context_self()->trace_level.gtp;
int others = context_self()->trace_level.others;
int fd = context_self()->logger.trace.fd;
int gtp = context_self()->logger.trace.gtp;
int others = context_self()->logger.trace.others;
if (fd)
{

View File

@ -17,7 +17,7 @@ status_t app_initialize(const char *config_path, const char *log_path)
rv = app_will_initialize(config_path, log_path);
if (rv != CORE_OK) return rv;
others = context_self()->trace_level.others;
others = context_self()->logger.trace.others;
if (others)
{
d_trace_level(&_sgw_main, others);

View File

@ -194,8 +194,8 @@ status_t sgw_context_parse_config()
status_t sgw_context_setup_trace_module()
{
int gtp = context_self()->trace_level.gtp;
int others = context_self()->trace_level.others;
int gtp = context_self()->logger.trace.gtp;
int others = context_self()->logger.trace.others;
if (gtp)
{