Mod aaa-12 modify remote and pty
RCA: SOL: 修改人:zhangtao 检视人:
This commit is contained in:
parent
fef6e14e78
commit
3b27ad602a
|
@ -38,7 +38,7 @@ PLAT_ARM64_CFLAGS := -fPIC -I../../Common -I../common/trace -I../user/netlink_ua
|
||||||
PLAT_LINUX_CFLAGS := $(PLAT_ARM64_CFLAGS)
|
PLAT_LINUX_CFLAGS := $(PLAT_ARM64_CFLAGS)
|
||||||
|
|
||||||
|
|
||||||
PLAT_ARM64_LDFLAGS := -fPIC -shared -lpthread
|
PLAT_ARM64_LDFLAGS := -fPIC -shared
|
||||||
PLAT_LINUX_LDFLAGS := $(PLAT_ARM64_LDFLAGS)
|
PLAT_LINUX_LDFLAGS := $(PLAT_ARM64_LDFLAGS)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ VPATH = ../user/ulog/log-sched
|
||||||
|
|
||||||
# set the source file, don't used .o because of ...
|
# set the source file, don't used .o because of ...
|
||||||
|
|
||||||
COMMON_SRCS = log_file.c log_console.c log_tty.c log_remote.c log_common.c log_sched.c
|
COMMON_SRCS = log_file.c log_console.c log_pty.c log_remote.c log_common.c log_sched.c
|
||||||
|
|
||||||
# MRS Board Source Files
|
# MRS Board Source Files
|
||||||
PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
||||||
|
@ -38,12 +38,12 @@ PLAT_ARM64_CFLAGS := -fPIC -I../../Common -I../common/rpc -I../user/ulog
|
||||||
PLAT_LINUX_CFLAGS := $(PLAT_ARM64_CFLAGS)
|
PLAT_LINUX_CFLAGS := $(PLAT_ARM64_CFLAGS)
|
||||||
|
|
||||||
|
|
||||||
PLAT_ARM64_LDFLAGS := -lpthread
|
PLAT_ARM64_LDFLAGS :=
|
||||||
PLAT_LINUX_LDFLAGS := $(PLAT_ARM64_LDFLAGS)
|
PLAT_LINUX_LDFLAGS := $(PLAT_ARM64_LDFLAGS)
|
||||||
|
|
||||||
#gcc libs
|
#gcc libs
|
||||||
ARM64_LIBS := ./libopenrpc-arm64.so ./libulogapi-arm64.so ../thirdparty/arm64/libev-arm64.so
|
ARM64_LIBS := ./libopenrpc-arm64.so ./libulogapi-arm64.so ../thirdparty/arm64/libev-arm64.so -lpthread
|
||||||
LINUX_LIBS := ./libopenrpc-linux.so ./libulogapi-linux.so ../thirdparty/x86_64/libev-linux.so
|
LINUX_LIBS := ./libopenrpc-linux.so ./libulogapi-linux.so ../thirdparty/x86_64/libev-linux.so -lpthread
|
||||||
|
|
||||||
ifeq ($(PLAT_ARM64), TRUE)
|
ifeq ($(PLAT_ARM64), TRUE)
|
||||||
DEPEND_LIB += ./debug/libopenrpc-arm64.so ./debug/libulogapi-arm64.so
|
DEPEND_LIB += ./debug/libopenrpc-arm64.so ./debug/libulogapi-arm64.so
|
||||||
|
|
|
@ -21,7 +21,7 @@ typedef struct _rpc_module rpc_module;
|
||||||
#define MODULE_REG_ARRAY \
|
#define MODULE_REG_ARRAY \
|
||||||
{ \
|
{ \
|
||||||
{"ConfigManger#0", "127.0.0.1", 10002, 1}, \
|
{"ConfigManger#0", "127.0.0.1", 10002, 1}, \
|
||||||
{RPC_MODULE_SYSLOG_NAME, "127.0.0.1", 10003, 2} \
|
{RPC_MODULE_SYSLOG_NAME, "127.0.0.1", 10003, 1} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif /* RPC_MODULE_H_ */
|
#endif /* RPC_MODULE_H_ */
|
||||||
|
|
|
@ -29,14 +29,17 @@ static int copy_file(const char *src, const char *dst)
|
||||||
char buff[1024];
|
char buff[1024];
|
||||||
int len;
|
int len;
|
||||||
int n;
|
int n;
|
||||||
while(feof(src_fp) > 0)
|
while((len = fread(buff, 1, sizeof(buff), src_fp)) > 0)
|
||||||
{
|
{
|
||||||
len = fread(buff, 1, sizeof(buff), src_fp);
|
|
||||||
n = fwrite(buff, 1, len ,dst_fp);
|
n = fwrite(buff, 1, len ,dst_fp);
|
||||||
if (n != len) {
|
if (n != len) {
|
||||||
ULOG_ERR(g_log, "Configure file which is written[length:%d, actual len:%n] is failure:%s", n, len, strerror(errno));
|
ULOG_ERR(g_log, "Configure file which is written[length:%d, actual len:%n] is failure:%s", n, len, strerror(errno));
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (feof(src_fp) == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
@ -93,7 +96,8 @@ END:
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret == 1) && (exist_backup == 1)) {
|
if (exist_backup == 1) {
|
||||||
|
if (ret == 1) {
|
||||||
// 恢复备份配置
|
// 恢复备份配置
|
||||||
if (rename(bak_file, conf_path_file) < 0) {
|
if (rename(bak_file, conf_path_file) < 0) {
|
||||||
ULOG_ERR(g_log, "Restoring configure file:%s is failure:%s", conf_path_file, strerror(errno));
|
ULOG_ERR(g_log, "Restoring configure file:%s is failure:%s", conf_path_file, strerror(errno));
|
||||||
|
@ -103,6 +107,7 @@ END:
|
||||||
ULOG_WARNING(g_log, "Delete back file:%s is failure", bak_file);
|
ULOG_WARNING(g_log, "Delete back file:%s is failure", bak_file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -124,7 +129,7 @@ int write_conf_content(FILE *fp, const u8 level, const char *filter_mod, void *a
|
||||||
int i;
|
int i;
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
char line[MAX_LINE_SZ + 100] = {0};
|
char line[MAX_LINE_SZ + 100] = {0};
|
||||||
ULOG_INFO(g_log, "filter module:%s\n", filter_mod);
|
ULOG_DEBUG(g_log, "filter module:%s\n", filter_mod);
|
||||||
if ((filter_mod != NULL) && (strlen(filter_mod) > 0)) {
|
if ((filter_mod != NULL) && (strlen(filter_mod) > 0)) {
|
||||||
snprintf(line, sizeof(line), FILTER_CONTENT, filter_mod);
|
snprintf(line, sizeof(line), FILTER_CONTENT, filter_mod);
|
||||||
if (fputs(line, fp) == EOF) {
|
if (fputs(line, fp) == EOF) {
|
||||||
|
|
|
@ -3,18 +3,19 @@
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include "log_tty.h"
|
#include "log_pty.h"
|
||||||
#include "log_common.h"
|
#include "log_common.h"
|
||||||
|
|
||||||
#define LOG_CONF_TTY_FILE_NAME "log-tty.conf"
|
#define LOG_DEV_PTY_DIR LOG_DEV_DIR"pts/"
|
||||||
|
#define LOG_CONF_PTY_FILE_NAME "log-pty.conf"
|
||||||
|
|
||||||
|
|
||||||
static int write_tty_content(FILE *fp, const u8 level, const char *filter_mod, void *arg)
|
static int write_pty_content(FILE *fp, const u8 level, const char *filter_mod, void *arg)
|
||||||
{
|
{
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
|
|
||||||
if ((dir = opendir(LOG_DEV_DIR)) == NULL) {
|
if ((dir = opendir(LOG_DEV_PTY_DIR)) == NULL) {
|
||||||
ULOG_ERR(g_log, "Open dir:[%s] is failure:%d\n", LOG_DEV_DIR, strerror(errno));
|
ULOG_ERR(g_log, "Open dir:[%s] is failure:%d\n", LOG_DEV_PTY_DIR, strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,21 +29,18 @@ static int write_tty_content(FILE *fp, const u8 level, const char *filter_mod, v
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((strstr(ptr->d_name, "tty") == NULL)
|
if (strstr(ptr->d_name, "ptmx") != NULL) {
|
||||||
|| (strcmp(ptr->d_name, "tty") == 0)
|
|
||||||
|| (strcmp(ptr->d_name, "ttyprintk") == 0)
|
|
||||||
|| (strstr(ptr->d_name, "ttyS") != NULL)) {
|
|
||||||
ULOG_DEBUG(g_log,"The file:[%s] isn't redirected\n", ptr->d_name);
|
ULOG_DEBUG(g_log,"The file:[%s] isn't redirected\n", ptr->d_name);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ULOG_DEBUG(g_log, "tty name:%s", ptr->d_name);
|
ULOG_DEBUG(g_log, "pty name:%s", ptr->d_name);
|
||||||
if (snprintf(path, sizeof(path), "%s%s", LOG_DEV_DIR, ptr->d_name) < 0) {
|
if (snprintf(path, sizeof(path), "%s%s", LOG_DEV_PTY_DIR, ptr->d_name) < 0) {
|
||||||
ULOG_ERR(g_log, "Setting tty of log[%s] is failure", ptr->d_name);
|
ULOG_ERR(g_log, "Setting pty of log[%s] is failure", ptr->d_name);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (write_conf_content_authorizing(fp, level, filter_mod, path) != 0) {
|
if (write_conf_content_authorizing(fp, level, filter_mod, path) != 0) {
|
||||||
ULOG_ERR(g_log, "Writing tty[module:%s] of log is failure", filter_mod);
|
ULOG_ERR(g_log, "Writing pty[module:%s] of log is failure", filter_mod);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,27 +49,27 @@ static int write_tty_content(FILE *fp, const u8 level, const char *filter_mod, v
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int config_log_tty(const log_tty_t *conf)
|
static int config_log_pty(const log_pty_t *conf)
|
||||||
{
|
{
|
||||||
if (log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_TTY_FILE_NAME, conf->module_name,
|
if (log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_PTY_FILE_NAME, conf->module_name,
|
||||||
write_tty_content, NULL) != 0) {
|
write_pty_content, NULL) != 0) {
|
||||||
ULOG_ERR(g_log, "Log's tty configure which is written is failure");
|
ULOG_ERR(g_log, "Log's pty configure which is written is failure");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void rpc_conf_log_tty(rpc_conn *conn, pointer input, int input_len, pointer data)
|
void rpc_conf_log_pty(rpc_conn *conn, pointer input, int input_len, pointer data)
|
||||||
{
|
{
|
||||||
u32 need_len = sizeof(log_tty_t);
|
u32 need_len = sizeof(log_pty_t);
|
||||||
if (input_len < need_len) {
|
if (input_len < need_len) {
|
||||||
ULOG_WARNING(g_log,
|
ULOG_WARNING(g_log,
|
||||||
"The input paramter of rpc log tty is needed length of %u, but the actual length is %u",
|
"The input paramter of rpc log pty is needed length of %u, but the actual length is %u",
|
||||||
need_len, input_len);
|
need_len, input_len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
config_log_tty((const log_tty_t *)input);
|
config_log_pty((const log_pty_t *)input);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
#ifndef _LOG_PTY_H
|
||||||
|
#define _LOG_PTY_H
|
||||||
|
|
||||||
|
#include "log_console.h"
|
||||||
|
|
||||||
|
typedef log_console_t log_pty_t;
|
||||||
|
|
||||||
|
void rpc_conf_log_pty(rpc_conn *conn, pointer input, int input_len, pointer data);
|
||||||
|
|
||||||
|
#endif
|
|
@ -20,44 +20,90 @@ static rfc_key_fmt rfc_tbl[] = {
|
||||||
{LOG_RFC_5424, "RFC5424fmt"}
|
{LOG_RFC_5424, "RFC5424fmt"}
|
||||||
};
|
};
|
||||||
|
|
||||||
static int match_line(const log_remote_host_t *conf)
|
typedef int (*op_func)(const log_remote_host_t *conf);
|
||||||
{
|
|
||||||
|
|
||||||
|
static int add_remote_host(const log_remote_host_t *conf);
|
||||||
|
static int del_remote_host(const log_remote_host_t *conf);
|
||||||
|
|
||||||
|
static op_func remote_funcs[] = {
|
||||||
|
add_remote_host,
|
||||||
|
del_remote_host
|
||||||
|
};
|
||||||
|
|
||||||
|
static int match_remote_config(const char *line, const void *src)
|
||||||
|
{
|
||||||
|
char text_level[MAX_LINE_SZ], old_redirect[MAX_LINE_SZ];
|
||||||
|
int n;
|
||||||
|
|
||||||
|
ULOG_DEBUG(g_log, "The line:%s will be matched", line);
|
||||||
|
n = sscanf(line, "%s"REDIRECT_SEPERATE"%s", text_level, old_redirect);
|
||||||
|
if (errno != 0) {
|
||||||
|
// 错误发生
|
||||||
|
ULOG_ERR(g_log, "Parsing remote line is failure:%s", strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n == 2) {
|
||||||
|
// 匹配到
|
||||||
|
// 是否相同配置判读
|
||||||
|
ULOG_DEBUG(g_log, "%s will compare with %s", old_redirect, (const char *)src);
|
||||||
|
if (strcmp(old_redirect, src) == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 未能识别行
|
||||||
|
ULOG_DEBUG(g_log, "The line:%s can't be parsed", line);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int remote_conf_content(FILE *fp, const u8 level, const char *filter_mod, void *arg)
|
static int remote_conf_content(FILE *fp, const u8 level, const char *filter_mod,
|
||||||
|
int (*match_cb)(const char *line, const void *src),
|
||||||
|
int (*final_cb)(FILE *fp, const u8 level, const char *filter_mod, void *arg),
|
||||||
|
void *arg)
|
||||||
{
|
{
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
FILE *bak_fp = NULL;
|
FILE *bak_fp = NULL;
|
||||||
char path[MAX_PATH_SZ];
|
char path[MAX_PATH_SZ];
|
||||||
snprintf(path, sizeof(path), BAK_FILE, LOG_CONF_REMOTE_FILE_NAME);
|
snprintf(path, sizeof(path), BAK_FILE, LOG_CONF_REMOTE_FILE_NAME);
|
||||||
bak_fp = fopen(bak_fp, "r");
|
bak_fp = fopen(path, "r");
|
||||||
if (bak_fp == NULL) {
|
if (bak_fp == NULL) {
|
||||||
ULOG_ERR(g_log, "Opening remote back file:%s is failure:%s", path, strerror(errno));
|
if (errno == ENOENT) {
|
||||||
|
goto FINAL_PHASE;
|
||||||
|
} else {
|
||||||
|
ULOG_ERR(g_log, "Opening remote backup file:%s is failure:%s", path, strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char *line = NULL;
|
char *line = NULL;
|
||||||
ssize_t n, n1;
|
ssize_t n, n1;
|
||||||
char *pad, *host, *rfc_fmt;
|
char text_level[MAX_LINE_SZ], old_redirect[MAX_LINE_SZ];
|
||||||
u16 port;
|
|
||||||
while ((n = getline(&line, &n, bak_fp)) != -1) {
|
while ((n = getline(&line, &n, bak_fp)) != -1) {
|
||||||
n1 = sscanf(line, "%s"REDIRECT_SEPERATE"%s:%u:%s", &pad, &host, &port, &rfc_fmt);
|
int match = match_cb(line, arg);
|
||||||
if (n1 == 4) {
|
if (match == -1) {
|
||||||
// 匹配到
|
ULOG_ERR(g_log, "Configure which is matched is failure");
|
||||||
} if (errno != 0) {
|
} else if (match == 0) {
|
||||||
// 错误发生
|
ULOG_DEBUG(g_log, "Be matched");
|
||||||
} else {
|
|
||||||
// 未知行,跳过
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write_conf_content(fp, level, filter_mod, arg) != 0) {
|
ULOG_DEBUG(g_log, "Recover old line:%s to file:%s", line, path);
|
||||||
ULOG_ERR(g_log, "Write remote configure is failure");
|
n1 = fwrite(line, 1, n, fp);
|
||||||
|
if (n != n1) {
|
||||||
|
ULOG_ERR(g_log, "Recovering old line:%s to file is failure:%s", line, strerror(errno));
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FINAL_PHASE:
|
||||||
|
if (final_cb != NULL) {
|
||||||
|
if (final_cb(fp, level, filter_mod, arg) != 0) {
|
||||||
|
ULOG_ERR(g_log, "Executing final callback is failure");
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
END:
|
END:
|
||||||
|
@ -71,8 +117,19 @@ END:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int add_remote_conf_content(FILE *fp, const u8 level, const char *filter_mod, void *arg)
|
||||||
|
{
|
||||||
|
return remote_conf_content(fp, level, filter_mod, match_remote_config, write_conf_content, arg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int del_remote_conf_content(FILE *fp, const u8 level, const char *filter_mod, void *arg)
|
||||||
|
{
|
||||||
|
return remote_conf_content(fp, level, filter_mod, match_remote_config, NULL, arg);
|
||||||
|
}
|
||||||
|
|
||||||
static int add_remote_host(const log_remote_host_t *conf)
|
static int add_remote_host(const log_remote_host_t *conf)
|
||||||
{
|
{
|
||||||
|
ULOG_INFO(g_log, "Adding remote log server[%s:%u], rfc is %s", conf->host, conf->port, rfc_tbl[conf->rfc].fmt);
|
||||||
char prefix[1] = "";
|
char prefix[1] = "";
|
||||||
if (conf->rfc == LOG_RFC_5424) {
|
if (conf->rfc == LOG_RFC_5424) {
|
||||||
strcat(prefix, "@");
|
strcat(prefix, "@");
|
||||||
|
@ -84,8 +141,8 @@ static int add_remote_host(const log_remote_host_t *conf)
|
||||||
ULOG_ERR(g_log, "Setting remote redirect[%s:%u:%s] is faulure", conf->host, conf->port, rfc_tbl[conf->rfc].fmt);
|
ULOG_ERR(g_log, "Setting remote redirect[%s:%u:%s] is faulure", conf->host, conf->port, rfc_tbl[conf->rfc].fmt);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (log_conf_append(7, LOG_CONF_PATH, LOG_CONF_REMOTE_FILE_NAME, NULL,
|
if (log_conf(7, LOG_CONF_PATH, LOG_CONF_REMOTE_FILE_NAME, NULL,
|
||||||
write_conf_content, (void *)redirect) != 0) {
|
add_remote_conf_content, (void *)redirect) != 0) {
|
||||||
ULOG_ERR(g_log, "Adding remote server[%s:%u:%s] is faulure", conf->host, conf->port, rfc_tbl[conf->rfc].fmt);
|
ULOG_ERR(g_log, "Adding remote server[%s:%u:%s] is faulure", conf->host, conf->port, rfc_tbl[conf->rfc].fmt);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -95,6 +152,25 @@ static int add_remote_host(const log_remote_host_t *conf)
|
||||||
|
|
||||||
static int del_remote_host(const log_remote_host_t *conf)
|
static int del_remote_host(const log_remote_host_t *conf)
|
||||||
{
|
{
|
||||||
|
int ret;
|
||||||
|
char prefix[1] = "";
|
||||||
|
if (conf->rfc == LOG_RFC_5424) {
|
||||||
|
strcat(prefix, "@");
|
||||||
|
};
|
||||||
|
char redirect[MAX_LINE_SZ];
|
||||||
|
if (snprintf(redirect, sizeof(redirect), "%s@%s:%u:%s",
|
||||||
|
prefix, conf->host, conf->port, rfc_tbl[conf->rfc].fmt) < 0) {
|
||||||
|
ULOG_ERR(g_log, "Setting remote redirect[%s:%u:%s] is faulure", conf->host, conf->port, rfc_tbl[conf->rfc].fmt);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (log_conf(7, LOG_CONF_PATH, LOG_CONF_REMOTE_FILE_NAME, NULL,
|
||||||
|
del_remote_conf_content, (void *)redirect) != 0) {
|
||||||
|
ULOG_ERR(g_log, "Adding remote server[%s:%u:%s] is faulure", conf->host, conf->port, rfc_tbl[conf->rfc].fmt);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int config_log_remote_host(const log_remote_host_t *conf)
|
static int config_log_remote_host(const log_remote_host_t *conf)
|
||||||
|
@ -103,9 +179,12 @@ static int config_log_remote_host(const log_remote_host_t *conf)
|
||||||
ULOG_WARNING(g_log, "Unknown rfc format key:%u", conf->rfc);
|
ULOG_WARNING(g_log, "Unknown rfc format key:%u", conf->rfc);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
if (conf->op >= LOG_REMOTE_MAX) {
|
||||||
|
ULOG_WARNING(g_log, "Unknown operation type:%u", conf->op);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return remote_funcs[conf->op](conf);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rpc_conf_log_remote(rpc_conn *conn, pointer input, int input_len, pointer data)
|
void rpc_conf_log_remote(rpc_conn *conn, pointer input, int input_len, pointer data)
|
||||||
|
|
|
@ -7,7 +7,8 @@
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
LOG_REMOTE_OP_ADD = 0,
|
LOG_REMOTE_OP_ADD = 0,
|
||||||
LOG_REMOTE_OP_DEL
|
LOG_REMOTE_OP_DEL,
|
||||||
|
LOG_REMOTE_MAX
|
||||||
} log_op_t;
|
} log_op_t;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
|
|
@ -2,12 +2,14 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <semaphore.h>
|
||||||
|
|
||||||
#include "rpc_server.h"
|
#include "rpc_server.h"
|
||||||
#include "ulog_api.h"
|
#include "ulog_api.h"
|
||||||
#include "log_file.h"
|
#include "log_file.h"
|
||||||
#include "log_console.h"
|
#include "log_console.h"
|
||||||
#include "log_tty.h"
|
#include "log_pty.h"
|
||||||
#include "log_remote.h"
|
#include "log_remote.h"
|
||||||
#include "rpc_module.h"
|
#include "rpc_module.h"
|
||||||
|
|
||||||
|
@ -16,9 +18,21 @@
|
||||||
|
|
||||||
#define SERVICE_LOG_FILE_NAME "log-file"
|
#define SERVICE_LOG_FILE_NAME "log-file"
|
||||||
#define SERIVCE_LOG_CONSOLE_NAME "log-console"
|
#define SERIVCE_LOG_CONSOLE_NAME "log-console"
|
||||||
#define SERVICE_LOG_TTY_NAME "log-tty"
|
#define SERVICE_LOG_PTY_NAME "log-pty"
|
||||||
|
#define SERVICE_LOG_REMOTE_NAME "log-remote"
|
||||||
|
|
||||||
ulog_t *g_log = NULL;
|
ulog_t *g_log = NULL;
|
||||||
|
static sem_t g_sem;
|
||||||
|
|
||||||
|
|
||||||
|
void signal_exit()
|
||||||
|
{
|
||||||
|
if (sem_post(&g_sem) == -1) {
|
||||||
|
ULOG_ERR(g_log, "Posting semaphore is failure:%s", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
ULOG_DEBUG(g_log, "Receive shutdown signal");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
|
@ -53,14 +67,22 @@ int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
ULOG_ERR(g_log, "start server error");
|
ULOG_ERR(g_log, "start server error");
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (sem_init(&g_sem, 0, 0) != 0) {
|
||||||
|
ULOG_ERR(g_log, "Init sem is failure:%s", strerror(errno));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
signal(SIGINT, signal_exit);
|
||||||
ULOG_INFO(g_log, "Server of log schedule is started");
|
ULOG_INFO(g_log, "Server of log schedule is started");
|
||||||
|
|
||||||
/* 注册配置处理函数 */
|
/* 注册配置处理函数 */
|
||||||
rpc_server_regservice(server, SERVICE_LOG_FILE_NAME, "conf_log_file", rpc_conf_log_file);
|
rpc_server_regservice(server, SERVICE_LOG_FILE_NAME, "conf_log_file", rpc_conf_log_file);
|
||||||
rpc_server_regservice(server, SERIVCE_LOG_CONSOLE_NAME, "conf_log_console", rpc_conf_log_console);
|
rpc_server_regservice(server, SERIVCE_LOG_CONSOLE_NAME, "conf_log_console", rpc_conf_log_console);
|
||||||
rpc_server_regservice(server, SERVICE_LOG_TTY_NAME, "conf_log_tty", rpc_conf_log_tty);
|
rpc_server_regservice(server, SERVICE_LOG_PTY_NAME, "conf_log_pty", rpc_conf_log_pty);
|
||||||
|
rpc_server_regservice(server, SERVICE_LOG_REMOTE_NAME, "conf_log_remote", rpc_conf_log_remote);
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
log_file_t log = {0};
|
log_file_t log = {0};
|
||||||
log.is_compress = LOG_UNCOMPRESS; //LOG_COMPRESS;
|
log.is_compress = LOG_UNCOMPRESS; //LOG_COMPRESS;
|
||||||
|
@ -75,17 +97,25 @@ int main(int argc, char **argv)
|
||||||
rpc_conf_log_console(NULL, &console, sizeof(console), NULL);
|
rpc_conf_log_console(NULL, &console, sizeof(console), NULL);
|
||||||
|
|
||||||
|
|
||||||
log_tty_t tty = {0};
|
log_pty_t tty = {0};
|
||||||
//strcpy(tty.module_name, "111");
|
//strcpy(tty.module_name, "111");
|
||||||
tty.level = LOG_DEBUG;
|
tty.level = LOG_DEBUG;
|
||||||
tty.on = 1;
|
tty.on = 1;
|
||||||
rpc_conf_log_tty(NULL, &tty, sizeof(tty), NULL);
|
rpc_conf_log_pty(NULL, &tty, sizeof(tty), NULL);
|
||||||
|
|
||||||
log_remote_host_t remote = {0};
|
log_remote_host_t remote = {0};
|
||||||
strcpy(remote.host, "192.168.3.1");
|
remote.op = LOG_REMOTE_OP_DEL;
|
||||||
|
strcpy(remote.host, "192.168.3.11");
|
||||||
remote.rfc = LOG_RFC_5424;
|
remote.rfc = LOG_RFC_5424;
|
||||||
remote.port = 514;
|
remote.port = 514;
|
||||||
rpc_conf_log_remote(NULL, &remote, sizeof(remote), NULL);
|
rpc_conf_log_remote(NULL, &remote, sizeof(remote), NULL);
|
||||||
|
*/
|
||||||
|
if (sem_wait(&g_sem) == -1) {
|
||||||
|
ULOG_ERR(g_log, "Waitting semaphore is failure:%s", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ULOG_INFO(g_log, "%s is shutdown", LOG_SCHED_MODULE_NAME);
|
||||||
END:
|
END:
|
||||||
ulog_close(g_log);
|
ulog_close(g_log);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
#ifndef _LOG_TTY_H
|
|
||||||
#define _LOG_TTY_H
|
|
||||||
|
|
||||||
#include "log_console.h"
|
|
||||||
|
|
||||||
typedef log_console_t log_tty_t;
|
|
||||||
|
|
||||||
void rpc_conf_log_tty(rpc_conn *conn, pointer input, int input_len, pointer data);
|
|
||||||
|
|
||||||
#endif
|
|
Loading…
Reference in New Issue