From e28617ad0f43bd925dd2e1d674f09b78ee980242 Mon Sep 17 00:00:00 2001 From: zhangtaohz Date: Mon, 22 Jul 2019 18:21:38 +0800 Subject: [PATCH] =?UTF-8?q?Add=20=20aaa-12=20add=20syslog=20schedule=20mod?= =?UTF-8?q?ule=20RCA=EF=BC=9A=20SOL=EF=BC=9A=20=E4=BF=AE=E6=94=B9=E4=BA=BA?= =?UTF-8?q?=EF=BC=9Azhangtao=20=E6=A3=80=E8=A7=86=E4=BA=BA=EF=BC=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Common/common_types.h | 20 +++++ Common/trace_def.h | 14 +--- Makefile | 13 +++- .../build/user.ulog.syslog_sched.Makefile | 76 +++++++++++++++++++ Platform/user/ulog/syslog-schedule/log_file.c | 7 ++ Platform/user/ulog/syslog-schedule/log_file.h | 20 +++++ .../user/ulog/syslog-schedule/log_sched.c | 41 ++++++++++ 7 files changed, 176 insertions(+), 15 deletions(-) create mode 100755 Common/common_types.h create mode 100755 Platform/build/user.ulog.syslog_sched.Makefile create mode 100755 Platform/user/ulog/syslog-schedule/log_file.c create mode 100755 Platform/user/ulog/syslog-schedule/log_file.h create mode 100755 Platform/user/ulog/syslog-schedule/log_sched.c diff --git a/Common/common_types.h b/Common/common_types.h new file mode 100755 index 000000000..4f60e3d7d --- /dev/null +++ b/Common/common_types.h @@ -0,0 +1,20 @@ +#ifndef _COMMON_TYPES_H +#define _COMMON_TYPES_H + +#ifndef u8 +typedef unsigned char u8; +#endif + +#ifndef u16 +typedef unsigned short u16; +#endif + +#ifndef u32 +typedef unsigned int u32; +#endif + +#ifndef u32 +typedef unsigned long long u64; +#endif + +#endif \ No newline at end of file diff --git a/Common/trace_def.h b/Common/trace_def.h index d66e3e943..95829543e 100755 --- a/Common/trace_def.h +++ b/Common/trace_def.h @@ -4,19 +4,7 @@ #include #include - -#ifndef u8 -typedef unsigned char u8; -#endif - -#ifndef u16 -typedef unsigned short u16; -#endif - -#ifndef u32 -typedef unsigned int u32; -#endif - +#include "common_types.h" typedef enum { TRACE_SUCCESS = 0, diff --git a/Makefile b/Makefile index f1b483e98..863a5738d 100755 --- a/Makefile +++ b/Makefile @@ -28,9 +28,9 @@ MAKE_FLAGS += -j$(shell cat /proc/cpuinfo | grep processor | wc -l) endif endif -.PHONY : demo conntrack netlink trace openrpc usermanager configm redismq database +.PHONY : demo conntrack netlink trace openrpc usermanager configm redismq ulog database -all: demo conntrack netlink trace openrpc usermanager configm redismq database +all: demo conntrack netlink trace openrpc usermanager configm redismq ulog database ifeq ($(OPT), install) #$(shell `find ../release -name "*.zip" -delete`) @@ -160,6 +160,15 @@ else $(MLOG)make all $(MAKE_FLAGS) -C Platform/build -f user.redismq.Makefile MLOG=$(MLOG) DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=redismq endif +ulog: +ifeq ($(OPT), clean) + $(MLOG)make $(MAKE_FLAGS) -C Platform/build -f user.ulog.syslog_sched.Makefile cleanall MLOG=$(MLOG) MAKE_TARGET=syslog-sched +else ifeq ($(OPT), install) + $(MLOG)make $(MAKE_FLAGS) -C Platform/build -f user.ulog.syslog_sched.Makefile install DIR=$(DIR) MLOG=$(MLOG) MAKE_TARGET=syslog-sched +else + $(MLOG)make all $(MAKE_FLAGS) -C Platform/build -f user.ulog.syslog_sched.Makefile MLOG=$(MLOG) DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=syslog-sched +endif + database: ifeq ($(OPT), clean) $(MLOG)make $(MAKE_FLAGS) -C Platform/build -f user.database.Makefile cleanall MLOG=$(MLOG) MAKE_TARGET=database diff --git a/Platform/build/user.ulog.syslog_sched.Makefile b/Platform/build/user.ulog.syslog_sched.Makefile new file mode 100755 index 000000000..ffa9dcb1d --- /dev/null +++ b/Platform/build/user.ulog.syslog_sched.Makefile @@ -0,0 +1,76 @@ +# target name, the target name must have the same name of c source file +TARGET_NAME=syslog-sched + +# target +# for linux module driver: KO +# for application: EXE +# for dynamic library: DLL +TARGET_TYPE = EXE + +# target object +# for application: APP +# for device driver: DRV +TARGET_OBJ = APP + +# custom install dir +TARGET_BOX = + +#debug mode or release mode +DEBUG = TRUE + +PLAT_LINUX ?= TRUE +PLAT_ARM64 ?= TRUE + +VPATH = ../user/ulog/syslog-schedule + +# source code + +# set the source file, don't used .o because of ... + +COMMON_SRCS = log_file.c log_sched.c + +# MRS Board Source Files +PLAT_LINUX_SRCS = $(COMMON_SRCS) +PLAT_ARM64_SRCS = $(COMMON_SRCS) + +# gcc CFLAGS +PLAT_ARM64_CFLAGS := -fPIC -I../../Common -I../common/rpc +PLAT_LINUX_CFLAGS := $(PLAT_ARM64_CFLAGS) + + +PLAT_ARM64_LDFLAGS := -lpthread +PLAT_LINUX_LDFLAGS := $(PLAT_ARM64_LDFLAGS) + +#gcc libs +ARM64_LIBS := ./libopenrpc-arm64.so ../thirdparty/arm64/libev-arm64.so +LINUX_LIBS := ./libopenrpc-linux.so ../thirdparty/x86_64/libev-linux.so + +ifeq ($(PLAT_ARM64), TRUE) +DEPEND_LIB += ./debug/libopenrpc-arm64.so +USER_CLEAN_ITEMS += ./libopenrpc-arm64.so +endif + +ifeq ($(PLAT_LINUX), TRUE) +DEPEND_LIB += ./debug/libopenrpc-linux.so +USER_CLEAN_ITEMS += ./libopenrpc-linux.so +endif + +# this line must be at below of thus, because of... +include ../../Common/common.Makefile + +ifneq ($(MAKECMDGOALS), clean) +ifneq ($(MAKECMDGOALS), cleanall) +ifneq ($(notdir $(DEPEND_LIB)), $(wildcard $(DEPEND_LIB))) +$(shell $(CP) $(DEPEND_LIB) ./) +endif +endif +endif + +ifeq ($(MAKECMDGOALS), ) +$(shell find ./ -name "$(TARGET)-*.ko" -delete) +else +ifeq ($(MAKECMDGOALS), all) +$(shell find ./ -name "$(TARGET)-*.ko" -delete) +endif +endif + diff --git a/Platform/user/ulog/syslog-schedule/log_file.c b/Platform/user/ulog/syslog-schedule/log_file.c new file mode 100755 index 000000000..c6780a43b --- /dev/null +++ b/Platform/user/ulog/syslog-schedule/log_file.c @@ -0,0 +1,7 @@ +#include "log_file.h" + +int conf_log_file(rpc_conn *conn, pointer input, int input_len, pointer data) +{ + return 0; +} + diff --git a/Platform/user/ulog/syslog-schedule/log_file.h b/Platform/user/ulog/syslog-schedule/log_file.h new file mode 100755 index 000000000..c87bbf145 --- /dev/null +++ b/Platform/user/ulog/syslog-schedule/log_file.h @@ -0,0 +1,20 @@ +#ifndef __LOG_H +#define __LOG_H + +#include +#include "common_types.h" +#include "rpc_common.h" + + +typedef struct _log_file { + u8 level; + char path[PATH_MAX]; + u32 compress_over_days; + u32 del_over_days; + u64 compress_over_size; + u64 del_over_size; +} log_file_t; + +int conf_log_file(rpc_conn *conn, pointer input, int input_len, pointer data); + +#endif diff --git a/Platform/user/ulog/syslog-schedule/log_sched.c b/Platform/user/ulog/syslog-schedule/log_sched.c new file mode 100755 index 000000000..97031aaf4 --- /dev/null +++ b/Platform/user/ulog/syslog-schedule/log_sched.c @@ -0,0 +1,41 @@ +#include +#include + +#include "log_file.h" + +#define SYSLOG_SCHED_RPC_NAME "syslog_schedule_rpc" + +#define SERVICE_LOG_FILE_NAME "log_file" + +int main(int argc, char **argv) +{ + int run_daemon = 0; + char *options = "d"; + int opt; + + while ((opt = getopt(argc, argv, options)) != -1) { + switch (opt) { + case 'd': + run_daemon = 1; + break; + } + } + + if (run_daemon) { + if (daemon(0, 0) == -1) { + return 1; + } + } + + rpc_server *server = rpc_server_create_ex(SYSLOG_SCHED_RPC_NAME); + if (server = NULL) + { + printf("start server error\n"); + return 1; + + } + printf("Server of log schedule is started\n"); + + /* 注册配置处理函数 */ + rpc_server_regservice(server, SERVICE_LOG_FILE_NAME, "conf_log_file", conf_log_file); +}