parent
3e45a258d8
commit
d4229eb20f
|
@ -175,7 +175,7 @@ DEBUG_CFLAGS := -g3
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# 设置 gcc 编译优化等级参数
|
# 设置 gcc 编译优化等级参数
|
||||||
DEBUG_CFLAGS += -O2
|
#DEBUG_CFLAGS += -O2
|
||||||
|
|
||||||
LINUX_EXTFLAG += $(DEBUG_CFLAGS)
|
LINUX_EXTFLAG += $(DEBUG_CFLAGS)
|
||||||
|
|
||||||
|
@ -259,7 +259,7 @@ else ifeq ($(TARGET_OBJ), APP)
|
||||||
ARM64_EXTFLAG += $(DEBUG_CFLAGS) -I$(ARM64_SDK_INCLUDE)
|
ARM64_EXTFLAG += $(DEBUG_CFLAGS) -I$(ARM64_SDK_INCLUDE)
|
||||||
|
|
||||||
# show all warring
|
# show all warring
|
||||||
#CFLAGS += -Wall
|
CFLAGS += -Wall
|
||||||
|
|
||||||
# 设置 ARM64 交叉编译链接目录
|
# 设置 ARM64 交叉编译链接目录
|
||||||
ARM64_DRV_LDFLAGS := --sysroot=${SDKTARGETSYSROOT}
|
ARM64_DRV_LDFLAGS := --sysroot=${SDKTARGETSYSROOT}
|
||||||
|
|
|
@ -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_common.c log_sched.c
|
COMMON_SRCS = log_file.c log_console.c log_tty.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)
|
||||||
|
|
|
@ -10,18 +10,18 @@
|
||||||
|
|
||||||
#define BAK_FILE "/tmp/%s"
|
#define BAK_FILE "/tmp/%s"
|
||||||
|
|
||||||
int write_log_conf(const u8 level, const char *conf_path, const char *conf_file,
|
int write_log_conf(const u8 level, const char *conf_path, const char *conf_file, const char *filter_mod,
|
||||||
const char *rediect_path, const char *filter_mod)
|
int (*cb_content)(FILE *fp, const u8 level, const char *filter_mod, void *arg), void *arg)
|
||||||
{
|
{
|
||||||
FILE *fp = NULL;
|
FILE *fp = NULL;
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
u8 exist_backup = 1;
|
u8 exist_backup = 1;
|
||||||
|
|
||||||
/********** rsyslog configure **********/
|
/********** rsyslog configure **********/
|
||||||
char conf_path_file[MAX_LINE_SIZE];
|
char conf_path_file[MAX_PATH_SZ];
|
||||||
snprintf(conf_path_file, sizeof(conf_path_file), "%s%s", conf_path, conf_file);
|
snprintf(conf_path_file, sizeof(conf_path_file), "%s%s", conf_path, conf_file);
|
||||||
|
|
||||||
char bak_file[MAX_LINE_SIZE];
|
char bak_file[MAX_PATH_SZ];
|
||||||
snprintf(bak_file, sizeof(bak_file), BAK_FILE, conf_file);
|
snprintf(bak_file, sizeof(bak_file), BAK_FILE, conf_file);
|
||||||
if (rename(conf_path_file, bak_file) < 0) {
|
if (rename(conf_path_file, bak_file) < 0) {
|
||||||
if (errno == ENOENT) {
|
if (errno == ENOENT) {
|
||||||
|
@ -39,8 +39,34 @@ int write_log_conf(const u8 level, const char *conf_path, const char *conf_file,
|
||||||
goto END;
|
goto END;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ULOG_DEBUG(g_log, "cb_content:%x", cb_content);
|
||||||
|
if (cb_content(fp, level, filter_mod, arg) != 0) {
|
||||||
|
ULOG_ERR(g_log, "Callback log content is failure");
|
||||||
|
goto END;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
END:
|
||||||
|
if (fp != NULL) {
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((ret == 1) && (exist_backup == 1)) {
|
||||||
|
// 恢复备份配置
|
||||||
|
if (rename(bak_file, conf_path_file) < 0) {
|
||||||
|
ULOG_ERR(g_log, "Restoring configure file:%s is failure:%s", conf_path_file, strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int write_conf_content(FILE *fp, const u8 level, const char *filter_mod, void *arg)
|
||||||
|
{
|
||||||
int i;
|
int i;
|
||||||
char line[MAX_LINE_SIZE + 100] = {0};
|
int ret = 1;
|
||||||
|
char line[MAX_LINE_SZ + 100] = {0};
|
||||||
|
ULOG_INFO(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) {
|
||||||
|
@ -50,7 +76,6 @@ int write_log_conf(const u8 level, const char *conf_path, const char *conf_file,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
char tmp[20];
|
char tmp[20];
|
||||||
line[0] = '\0'; // 清零
|
line[0] = '\0'; // 清零
|
||||||
for (i = 0; i <= level;) {
|
for (i = 0; i <= level;) {
|
||||||
|
@ -66,7 +91,8 @@ int write_log_conf(const u8 level, const char *conf_path, const char *conf_file,
|
||||||
}
|
}
|
||||||
strcat(line, " ");
|
strcat(line, " ");
|
||||||
|
|
||||||
strcat(line, rediect_path);
|
strcat(line, (const char *)arg);
|
||||||
|
strcat(line, "\n");
|
||||||
|
|
||||||
if (fputs(line, fp) == EOF) {
|
if (fputs(line, fp) == EOF) {
|
||||||
ULOG_ERR(g_log, "Configure file which is written is failure:%s", strerror(errno));
|
ULOG_ERR(g_log, "Configure file which is written is failure:%s", strerror(errno));
|
||||||
|
@ -75,26 +101,31 @@ int write_log_conf(const u8 level, const char *conf_path, const char *conf_file,
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
END:
|
END:
|
||||||
if (fp != NULL) {
|
|
||||||
fclose(fp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((ret == 1) && (exist_backup == 1)) {
|
|
||||||
// 回复备份配置
|
|
||||||
if (rename(bak_file, conf_path_file) < 0) {
|
|
||||||
ULOG_ERR(g_log, "Restoring configure file:%s is failure:%s", conf_path_file, strerror(errno));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int modify_authorizing(const char *redirect_path)
|
int modify_authorizing(const char *redirect_path)
|
||||||
{
|
{
|
||||||
if (chmod(redirect_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) < 0) {
|
if (chmod(redirect_path, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) < 0) {
|
||||||
ULOG_ERR(g_log, "Authorizing of %s which is modified is failure:%s", strerror(errno));
|
ULOG_ERR(g_log, "Authorizing of %s which is modified is failure:%s", redirect_path, strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int write_conf_content_authorizing(FILE *fp, const u8 level, const char *filter_mod, void *arg)
|
||||||
|
{
|
||||||
|
if (write_conf_content(fp, level, filter_mod, arg) != 0) {
|
||||||
|
ULOG_ERR(g_log, "configure of log conosle which is written is failure");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modify_authorizing((const char *)arg) != 0) {
|
||||||
|
ULOG_ERR(g_log, "Modifying authorizing of %s is failure", (const char *)arg);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
|
|
||||||
#include "ulog_api.h"
|
#include "ulog_api.h"
|
||||||
|
|
||||||
#define MAX_LINE_SIZE 1024
|
#define MAX_LINE_SZ 1024
|
||||||
|
#define MAX_PATH_SZ MAX_LINE_SZ
|
||||||
|
|
||||||
#define LOG_CONF_PATH "/etc/rsyslog.d/"
|
#define LOG_CONF_PATH "/etc/rsyslog.d/"
|
||||||
|
|
||||||
|
@ -25,10 +26,9 @@ static level_str_t g_level_array[] = {
|
||||||
{LOG_DEBUG, "debug"}
|
{LOG_DEBUG, "debug"}
|
||||||
};
|
};
|
||||||
|
|
||||||
int write_log_conf(const u8 level, const char *conf_path, const char *conf_file,
|
int write_log_conf(const u8 level, const char *conf_path, const char *conf_file, const char *filter_mod,
|
||||||
const char *rediect_path, const char *filter_mod);
|
int (*cb_content)(FILE *fp, const u8 level, const char *filter_mod, void *arg), void *arg);
|
||||||
int modify_authorizing(const char *redirect_path);
|
int write_conf_content(FILE *fp, const u8 level, const char *filter_mod, void *arg);
|
||||||
|
int write_conf_content_authorizing(FILE *fp, const u8 level, const char *filter_mod, void *arg);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -7,13 +7,9 @@
|
||||||
|
|
||||||
static int config_log_console(const log_console_t *conf)
|
static int config_log_console(const log_console_t *conf)
|
||||||
{
|
{
|
||||||
if (write_log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_COSOLE_FILE_NAME, LOG_REDIRECT_CONSOLE, conf->module_name) != 0) {
|
if (write_log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_COSOLE_FILE_NAME, conf->module_name,
|
||||||
ULOG_ERR(g_log, "configure of log conosle which is written is failure");
|
write_conf_content_authorizing, (void *)LOG_REDIRECT_CONSOLE) != 0) {
|
||||||
return 1;
|
ULOG_ERR(g_log, "Log configure which is written is failure");
|
||||||
}
|
|
||||||
|
|
||||||
if (modify_authorizing(LOG_REDIRECT_CONSOLE) != 0) {
|
|
||||||
ULOG_ERR(g_log, "Modifying authorizing of %s is failure", LOG_REDIRECT_CONSOLE);
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -103,7 +103,9 @@ static int conf_log_file(const log_file_t *conf)
|
||||||
strncpy(path, DEFAULT_LOG_FILE, sizeof(path));
|
strncpy(path, DEFAULT_LOG_FILE, sizeof(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (write_log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_FILE_NAME, path, NULL) != 0) {
|
ULOG_DEBUG(g_log, "write_conf_content:%x", write_conf_content);
|
||||||
|
if (write_log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_FILE_NAME, NULL,
|
||||||
|
write_conf_content, (void *)path) != 0) {
|
||||||
ULOG_ERR(g_log, "Log configure which is written is failure");
|
ULOG_ERR(g_log, "Log configure which is written is failure");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,8 +8,6 @@
|
||||||
#include "rpc_common.h"
|
#include "rpc_common.h"
|
||||||
#include "log_common.h"
|
#include "log_common.h"
|
||||||
|
|
||||||
#define MAX_LOG_PATH MAX_LINE_SIZE
|
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
LOG_UNCOMPRESS = 0,
|
LOG_UNCOMPRESS = 0,
|
||||||
LOG_COMPRESS
|
LOG_COMPRESS
|
||||||
|
@ -17,7 +15,7 @@ typedef enum {
|
||||||
|
|
||||||
typedef struct _log_file {
|
typedef struct _log_file {
|
||||||
u8 level;
|
u8 level;
|
||||||
char path[MAX_LOG_PATH];
|
char path[MAX_PATH_SZ];
|
||||||
log_compress_t is_compress;
|
log_compress_t is_compress;
|
||||||
u32 del_over_days;
|
u32 del_over_days;
|
||||||
u64 del_over_size;
|
u64 del_over_size;
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
#include "log_common.h"
|
#include "log_common.h"
|
||||||
|
|
||||||
#define LOG_CONF_TTY_FILE_NAME "log-tty.conf"
|
#define LOG_CONF_TTY_FILE_NAME "log-tty.conf"
|
||||||
#define LOG_DEV_DIR "/dev"
|
#define LOG_DEV_DIR "/dev/"
|
||||||
|
|
||||||
static int config_log_tty(const log_tty_t *conf)
|
static int write_tty_content(FILE *fp, const u8 level, const char *filter_mod, void *arg)
|
||||||
{
|
{
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ static int config_log_tty(const log_tty_t *conf)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct dirent *ptr;
|
struct dirent *ptr;
|
||||||
|
char path[MAX_PATH_SZ];
|
||||||
while ((ptr = readdir(dir)) != NULL) {
|
while ((ptr = readdir(dir)) != NULL) {
|
||||||
if ((strcmp(ptr->d_name, ".") == 0)
|
if ((strcmp(ptr->d_name, ".") == 0)
|
||||||
|| (strcmp(ptr->d_name, "..") == 0)
|
|| (strcmp(ptr->d_name, "..") == 0)
|
||||||
|
@ -32,17 +33,29 @@ static int config_log_tty(const log_tty_t *conf)
|
||||||
|| (strcmp(ptr->d_name, "ttyprintk") == 0)
|
|| (strcmp(ptr->d_name, "ttyprintk") == 0)
|
||||||
|| (strstr(ptr->d_name, "ttyS") != NULL)) {
|
|| (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;
|
||||||
|
}
|
||||||
|
|
||||||
|
ULOG_DEBUG(g_log, "tty name:%s", ptr->d_name);
|
||||||
|
snprintf(path, sizeof(path), "%s%s", LOG_DEV_DIR, ptr->d_name);
|
||||||
|
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);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
return 0;
|
||||||
if (write_log_conf_authorizing(conf->level, LOG_CONF_PATH,
|
}
|
||||||
LOG_CONF_COSOLE_FILE_NAME, LOG_REDIRECT_CONSOLE, conf->module_name) != 0) {
|
|
||||||
ULOG_ERR(g_log, "Writing tty[module:%s] of log is failure", conf->module_name);
|
static int config_log_tty(const log_tty_t *conf)
|
||||||
return 1;
|
{
|
||||||
}
|
if (write_log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_TTY_FILE_NAME, conf->module_name,
|
||||||
*/
|
write_tty_content, NULL) != 0) {
|
||||||
|
ULOG_ERR(g_log, "Log's tty configure which is written is failure");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue