Merge branch 'master' of http://git.komect.net/ISG/secogateway
This commit is contained in:
commit
e7981f4831
|
@ -1,13 +1,17 @@
|
|||
#ifndef _ULOG_API_H
|
||||
#define _ULOG_API_H
|
||||
|
||||
#include <syslog.h>
|
||||
|
||||
#include "common_types.h"
|
||||
|
||||
#define MAX_MODULE_NAME_SZ 16
|
||||
|
||||
typedef struct _ulog {
|
||||
char module_name[MAX_MODULE_NAME_SZ];
|
||||
} ulog_t;
|
||||
|
||||
ulog_t *ulog_init(const char *module_name);
|
||||
ulog_t *ulog_init(const char *module_name, u8 is_print);
|
||||
void ulog_close(ulog_t *log);
|
||||
void ulog_record(const ulog_t *log, int level, const char *fmt, ...);
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@ import org.opendaylight.aaa.api.model.Domain;
|
|||
import org.opendaylight.aaa.api.model.Domains;
|
||||
import org.opendaylight.aaa.api.model.IDMError;
|
||||
import org.opendaylight.aaa.api.model.Roles;
|
||||
import org.opendaylight.aaa.shiro.idm.DomainHandler;
|
||||
|
||||
public class DomainHandlerTest extends HandlerTest {
|
||||
|
||||
|
@ -63,12 +64,13 @@ public class DomainHandlerTest extends HandlerTest {
|
|||
clientResponse = target("/v1/domains").request().post(entity(domainData));
|
||||
assertEquals(201, clientResponse.getStatus());
|
||||
|
||||
|
||||
// check update domain data
|
||||
domainData.put("name", "dom1Update");
|
||||
clientResponse = target("/v1/domains/1").request().put(entity(domainData));
|
||||
assertEquals(200, clientResponse.getStatus());
|
||||
|
||||
|
||||
|
||||
clientResponse = target("/v1/domains/101").request().put(entity(domainData));
|
||||
assertEquals(404, clientResponse.getStatus());
|
||||
|
||||
|
@ -170,6 +172,16 @@ public class DomainHandlerTest extends HandlerTest {
|
|||
clientResponse = target("/v1/domains/3/users/0/roles/0").request().delete();
|
||||
assertEquals(404, clientResponse.getStatus());
|
||||
|
||||
|
||||
// check delete grant for invalid user
|
||||
clientResponse = target("/v1/domains/0/users/15/roles/0").request().delete();
|
||||
assertEquals(404, clientResponse.getStatus());
|
||||
|
||||
// check delete grant for invalid role
|
||||
clientResponse = target("/v1/domains/0/users/0/roles/134").request().delete();
|
||||
assertEquals(404, clientResponse.getStatus());
|
||||
|
||||
|
||||
// check delete domain
|
||||
clientResponse = target("/v1/domains/1").request().delete();
|
||||
assertEquals(204, clientResponse.getStatus());
|
||||
|
@ -198,6 +210,7 @@ public class DomainHandlerTest extends HandlerTest {
|
|||
clientResponse = target("/v1/domains/1/users/0/roles").request().post(entity(grantData));
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
|
||||
package org.opendaylight.aaa.shiro.idm.rest.test;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.opendaylight.aaa.api.model.IDMError;
|
||||
import org.opendaylight.aaa.api.model.User;
|
||||
|
@ -59,7 +58,7 @@ public class UserHandlerTest extends HandlerTest {
|
|||
}
|
||||
|
||||
// check create user
|
||||
Map<String, String> usrData = new HashMap<>();
|
||||
Map<String, Object> usrData = new HashMap<>();
|
||||
usrData.put("name", "usr1");
|
||||
// usrData.put("description", "test user");
|
||||
// usrData.put("enabled", "true");
|
||||
|
@ -80,13 +79,71 @@ public class UserHandlerTest extends HandlerTest {
|
|||
assertEquals(500, e.getResponse().getStatus());
|
||||
}
|
||||
|
||||
// check update user data
|
||||
// check create user missing enable data and with long name
|
||||
usrData.remove("enable");
|
||||
usrData.put("name", getLongName());
|
||||
try {
|
||||
clientResponse = target("/v1/users").request().post(entity(usrData));
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
} catch (WebApplicationException e) {
|
||||
assertEquals(500, e.getResponse().getStatus());
|
||||
}
|
||||
|
||||
// check create user missing domain data and too long
|
||||
usrData.put("name", "usr1Update");
|
||||
clientResponse = target("/v1/users/1").request().put(entity(usrData));
|
||||
assertEquals(200, clientResponse.getStatus());
|
||||
usrData.remove("domainid");
|
||||
try {
|
||||
clientResponse = target("/v1/users").request().post(entity(usrData));
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
} catch (WebApplicationException e) {
|
||||
assertEquals(500, e.getResponse().getStatus());
|
||||
}
|
||||
|
||||
usrData.put("domainid", getLongName());
|
||||
try {
|
||||
clientResponse = target("/v1/users").request().post(entity(usrData));
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
} catch (WebApplicationException e) {
|
||||
assertEquals(500, e.getResponse().getStatus());
|
||||
}
|
||||
|
||||
usrData.put("domainid", "0");
|
||||
// check create user description data too long
|
||||
usrData.put("description", getLongName());
|
||||
try {
|
||||
clientResponse = target("/v1/users").request().post(entity(usrData));
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
} catch (WebApplicationException e) {
|
||||
assertEquals(500, e.getResponse().getStatus());
|
||||
}
|
||||
usrData.put("description", "Test user");
|
||||
// check create user missing email data and too long
|
||||
usrData.remove("email");
|
||||
try {
|
||||
clientResponse = target("/v1/users").request().post(entity(usrData));
|
||||
assertEquals(201, clientResponse.getStatus());
|
||||
} catch (WebApplicationException e) {
|
||||
assertEquals(500, e.getResponse().getStatus());
|
||||
}
|
||||
|
||||
usrData.put("email", getLongName());
|
||||
try {
|
||||
clientResponse = target("/v1/users").request().post(entity(usrData));
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
} catch (WebApplicationException e) {
|
||||
assertEquals(500, e.getResponse().getStatus());
|
||||
}
|
||||
|
||||
usrData.put("email", "user1@usr.org");
|
||||
|
||||
// check create user missing password data and too long
|
||||
usrData = checkPasswordError(usrData);
|
||||
//check update user
|
||||
checkPutMethod(usrData);
|
||||
|
||||
usr = target("/v1/users/1").request().get(User.class);
|
||||
assertNotNull(usr);
|
||||
assertTrue(usr.getName().equals("usr1Update"));
|
||||
assertEquals("usr1Update", usr.getName());
|
||||
|
||||
// check delete user
|
||||
clientResponse = target("/v1/users/1").request().delete();
|
||||
|
@ -112,6 +169,107 @@ public class UserHandlerTest extends HandlerTest {
|
|||
clientResponse = target("/v1/users").request().post(entity(usrData));
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
}
|
||||
|
||||
private Map<String, Object> checkPasswordError(Map<String, Object> usrData) {
|
||||
usrData.remove("password");
|
||||
Response clientResponse;
|
||||
try {
|
||||
clientResponse = target("/v1/users").request().post(entity(usrData));
|
||||
assertEquals(407, clientResponse.getStatus());
|
||||
} catch (WebApplicationException e) {
|
||||
assertEquals(500, e.getResponse().getStatus());
|
||||
}
|
||||
|
||||
usrData.put("password", getLongName());
|
||||
try {
|
||||
clientResponse = target("/v1/users").request().post(entity(usrData));
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
} catch (WebApplicationException e) {
|
||||
assertEquals(500, e.getResponse().getStatus());
|
||||
}
|
||||
|
||||
usrData.put("password", "");
|
||||
try {
|
||||
clientResponse = target("/v1/users").request().post(entity(usrData));
|
||||
assertEquals(407, clientResponse.getStatus());
|
||||
} catch (WebApplicationException e) {
|
||||
assertEquals(500, e.getResponse().getStatus());
|
||||
}
|
||||
|
||||
usrData.put("password", "111");
|
||||
try {
|
||||
clientResponse = target("/v1/users").request().post(entity(usrData));
|
||||
assertEquals(407, clientResponse.getStatus());
|
||||
} catch (WebApplicationException e) {
|
||||
assertEquals(500, e.getResponse().getStatus());
|
||||
}
|
||||
usrData.put("password", "12434356");
|
||||
try {
|
||||
clientResponse = target("/v1/users").request().post(entity(usrData));
|
||||
assertEquals(407, clientResponse.getStatus());
|
||||
} catch (WebApplicationException e) {
|
||||
assertEquals(500, e.getResponse().getStatus());
|
||||
}
|
||||
|
||||
usrData.put("password", "ChangeZbadPa$$w0rd");
|
||||
return usrData;
|
||||
}
|
||||
|
||||
private Map<String, Object> checkPutMethod(Map<String, Object> usrData) {
|
||||
// check update user data
|
||||
usrData.put("name", getLongName());
|
||||
Response clientResponse = target("/v1/users/1").request().put(entity(usrData));
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
|
||||
// check update user data with long pwd
|
||||
usrData.put("password", getLongName());
|
||||
clientResponse = target("/v1/users/1").request().put(entity(usrData));
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
|
||||
|
||||
|
||||
// check update user data
|
||||
usrData.put("description", getLongName());
|
||||
clientResponse = target("/v1/users/1").request().put(entity(usrData));
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
|
||||
|
||||
// check update user data
|
||||
usrData.put("email", getLongName());
|
||||
clientResponse = target("/v1/users/1").request().put(entity(usrData));
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
|
||||
// check update user data
|
||||
usrData.put("domainid",getLongName());
|
||||
clientResponse = target("/v1/users/1").request().put(entity(usrData));
|
||||
assertEquals(400, clientResponse.getStatus());
|
||||
|
||||
|
||||
// check update user data
|
||||
usrData.put("description", "Test user");
|
||||
usrData.put("email", "user1@usr.org");
|
||||
usrData.put("password", "ChangeZbadPa$$w0rd");
|
||||
usrData.put("domainid", "0");
|
||||
usrData.put("name", "usr1Update");
|
||||
|
||||
clientResponse = target("/v1/users/101").request().put(entity(usrData));
|
||||
assertEquals(404, clientResponse.getStatus());
|
||||
|
||||
clientResponse = target("/v1/users/1").request().put(entity(usrData));
|
||||
assertEquals(200, clientResponse.getStatus());
|
||||
return usrData;
|
||||
|
||||
}
|
||||
|
||||
private String getLongName() {
|
||||
return "abcdefg1234567890vbnabcdefg1234567890vbn" +
|
||||
"abcdefg1234567890vbnabcdefg1234567890vbn" +
|
||||
"abcdefg1234567890vbnabcdefg1234567890vbn" +
|
||||
"abcdefg1234567890vbnabcdefg1234567890vbn" +
|
||||
"abcdefg1234567890vbnabcdefg1234567890vbn" +
|
||||
"abcdefg1234567890vbnabcdefg1234567890vbn" +
|
||||
"abcdefg1234567890vbnabcdefg1234567890vbn";
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Revision history
|
||||
|
|
6
Makefile
6
Makefile
|
@ -162,14 +162,14 @@ 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
|
||||
$(MLOG)make $(MAKE_FLAGS) -C Platform/build -f user.ulog.api.Makefile cleanall MLOG=$(MLOG) MAKE_TARGET=ulog-api
|
||||
$(MLOG)make $(MAKE_FLAGS) -C Platform/build -f user.ulog.log_sched.Makefile cleanall MLOG=$(MLOG) MAKE_TARGET=log-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
|
||||
$(MLOG)make $(MAKE_FLAGS) -C Platform/build -f user.ulog.api.Makefile install DIR=$(DIR) MLOG=$(MLOG) MAKE_TARGET=ulog-api
|
||||
$(MLOG)make $(MAKE_FLAGS) -C Platform/build -f user.ulog.log_sched.Makefile install DIR=$(DIR) MLOG=$(MLOG) MAKE_TARGET=log-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
|
||||
$(MLOG)make all $(MAKE_FLAGS) -C Platform/build -f user.ulog.api.Makefile MLOG=$(MLOG) DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=ulog-api
|
||||
$(MLOG)make all $(MAKE_FLAGS) -C Platform/build -f user.ulog.log_sched.Makefile MLOG=$(MLOG) DISABLE_WARRING=$(DIS_BUILD_WARRING) MAKE_TARGET=log-sched
|
||||
endif
|
||||
|
||||
database:
|
||||
|
|
|
@ -34,7 +34,7 @@ PLAT_LINUX_SRCS = $(COMMON_SRCS)
|
|||
PLAT_ARM64_SRCS = $(COMMON_SRCS)
|
||||
|
||||
# gcc CFLAGS
|
||||
PLAT_ARM64_CFLAGS := -fPIC -I../../Common
|
||||
PLAT_ARM64_CFLAGS := -fPIC -I../../Common -I../user/ulog
|
||||
PLAT_LINUX_CFLAGS := $(PLAT_ARM64_CFLAGS)
|
||||
|
||||
|
||||
|
@ -44,6 +44,7 @@ PLAT_LINUX_LDFLAGS := $(PLAT_ARM64_LDFLAGS)
|
|||
|
||||
#gcc libs
|
||||
|
||||
|
||||
# this line must be at below of thus, because of...
|
||||
include ../../Common/common.Makefile
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# target name, the target name must have the same name of c source file
|
||||
TARGET_NAME=syslog-sched
|
||||
TARGET_NAME=log-sched
|
||||
|
||||
# target
|
||||
# for linux module driver: KO
|
||||
|
@ -21,20 +21,20 @@ DEBUG = TRUE
|
|||
PLAT_LINUX ?= TRUE
|
||||
PLAT_ARM64 ?= TRUE
|
||||
|
||||
VPATH = ../user/ulog/syslog-schedule
|
||||
VPATH = ../user/ulog/log-sched
|
||||
|
||||
# source code
|
||||
|
||||
# set the source file, don't used .o because of ...
|
||||
|
||||
COMMON_SRCS = log_file.c log_sched.c
|
||||
COMMON_SRCS = log_file.c log_console.c log_common.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_ARM64_CFLAGS := -fPIC -I../../Common -I../common/rpc -I../user/ulog
|
||||
PLAT_LINUX_CFLAGS := $(PLAT_ARM64_CFLAGS)
|
||||
|
||||
|
||||
|
@ -42,17 +42,17 @@ 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
|
||||
ARM64_LIBS := ./libopenrpc-arm64.so ./libulogapi-arm64.so ../thirdparty/arm64/libev-arm64.so
|
||||
LINUX_LIBS := ./libopenrpc-linux.so ./libulogapi-linux.so ../thirdparty/x86_64/libev-linux.so
|
||||
|
||||
ifeq ($(PLAT_ARM64), TRUE)
|
||||
DEPEND_LIB += ./debug/libopenrpc-arm64.so
|
||||
USER_CLEAN_ITEMS += ./libopenrpc-arm64.so
|
||||
DEPEND_LIB += ./debug/libopenrpc-arm64.so ./debug/libulogapi-arm64.so
|
||||
USER_CLEAN_ITEMS += ./libopenrpc-arm64.so ./libulogapi-arm64.so
|
||||
endif
|
||||
|
||||
ifeq ($(PLAT_LINUX), TRUE)
|
||||
DEPEND_LIB += ./debug/libopenrpc-linux.so
|
||||
USER_CLEAN_ITEMS += ./libopenrpc-linux.so
|
||||
DEPEND_LIB += ./debug/libopenrpc-linux.so ./debug/libulogapi-linux.so
|
||||
USER_CLEAN_ITEMS += ./libopenrpc-linux.so ./libulogapi-linux.so
|
||||
endif
|
||||
|
||||
# this line must be at below of thus, because of...
|
|
@ -14,7 +14,7 @@
|
|||
#define CM_CONFIG_GET 4
|
||||
#define CM_CONFIG_GET_ALL 5
|
||||
|
||||
#define CM_BUFF_SIZE BUFFER_SIZE
|
||||
#define CM_BUFF_SIZE BUF_MAX_SIZE
|
||||
|
||||
#define CONFIG_RECOVERY_DONE "/tmp/config_recovery"
|
||||
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
|
||||
#define WORKER_LEN 4
|
||||
#define BACKLOG 5
|
||||
#define BUFFER_SIZE 2048
|
||||
#define BUF_MAX_SIZE 163840
|
||||
#define BUFFER_SIZE (BUF_MAX_SIZE + 40960)
|
||||
#define RPC_VERSION "RPC/1.0"
|
||||
#define TIMEOUT 120
|
||||
#define TIMEWARN 200
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
#define MODULE_NAME_LEN 32
|
||||
#define IP_STR_LEN 32
|
||||
|
||||
#define RPC_MODULE_SYSLOG_NAME "syslog-schedule-rpc"
|
||||
|
||||
struct _rpc_module {
|
||||
char module_name[MODULE_NAME_LEN];
|
||||
char host[IP_STR_LEN];
|
||||
|
@ -18,7 +20,8 @@ typedef struct _rpc_module rpc_module;
|
|||
|
||||
#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} \
|
||||
}
|
||||
|
||||
#endif /* RPC_MODULE_H_ */
|
||||
|
|
|
@ -208,6 +208,38 @@ void cm_config_recovery()
|
|||
return;
|
||||
}
|
||||
|
||||
ret_code cm_config_proc_pre(char **input, char **output, int *buff_len)
|
||||
{
|
||||
static char *cm_set_buff = NULL;
|
||||
static char *cm_get_buff = NULL;
|
||||
|
||||
if(cm_set_buff == NULL)
|
||||
{
|
||||
cm_set_buff = rpc_new(char, CM_BUFF_SIZE);
|
||||
}
|
||||
|
||||
if(cm_get_buff == NULL)
|
||||
{
|
||||
cm_get_buff = rpc_new(char, CM_BUFF_SIZE);
|
||||
}
|
||||
|
||||
if(cm_get_buff == NULL || cm_set_buff == NULL)
|
||||
{
|
||||
return RET_NOMEM;
|
||||
}
|
||||
|
||||
memset(cm_set_buff, 0, CM_BUFF_SIZE);
|
||||
memset(cm_get_buff, 0, CM_BUFF_SIZE);
|
||||
|
||||
*input = cm_set_buff;
|
||||
*output = cm_get_buff;
|
||||
|
||||
*buff_len = CM_BUFF_SIZE;
|
||||
|
||||
return RET_OK;
|
||||
}
|
||||
|
||||
|
||||
/* 配置处理入口函数,所有的配置,均在此函数中处理 */
|
||||
void cm_config_process(rpc_conn *conn, pointer input, int input_len, void* data)
|
||||
{
|
||||
|
@ -253,17 +285,12 @@ void cm_config_process(rpc_conn *conn, pointer input, int input_len, void* data)
|
|||
return;
|
||||
}
|
||||
|
||||
cm_set_buff = rpc_new(char, buff_len);
|
||||
cm_get_buff = rpc_new(char, buff_len);
|
||||
if(cm_get_buff == NULL || cm_set_buff == NULL)
|
||||
if(cm_config_proc_pre(&cm_set_buff, &cm_get_buff, &buff_len) != RET_OK)
|
||||
{
|
||||
cm_return(conn, RET_NOMEM, "not enough memery");
|
||||
cm_return(conn, RET_NOMEM, "not enough memory");
|
||||
return;
|
||||
}
|
||||
|
||||
memset(cm_set_buff, 0, buff_len);
|
||||
memset(cm_get_buff, 0, buff_len);
|
||||
|
||||
memcpy(cm_set_buff, config_msg->config_buff, config_len);
|
||||
|
||||
/*config check*/
|
||||
|
@ -278,7 +305,7 @@ void cm_config_process(rpc_conn *conn, pointer input, int input_len, void* data)
|
|||
if(ret != RET_OK)
|
||||
{
|
||||
cm_return(conn, ret, cm_get_buff);
|
||||
goto exit;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -332,15 +359,11 @@ void cm_config_process(rpc_conn *conn, pointer input, int input_len, void* data)
|
|||
if(ret != RET_OK)
|
||||
{
|
||||
cm_return(conn, ret, cm_get_buff);
|
||||
goto exit;
|
||||
return;
|
||||
}
|
||||
|
||||
rpc_return(conn, cm_get_buff, buff_len);
|
||||
|
||||
exit:
|
||||
rpc_free(cm_set_buff);
|
||||
rpc_free(cm_get_buff);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
/* 类型定义 */
|
||||
|
||||
/* IP CONFIG */
|
||||
#define IPCONFIG_MODULE 0x00000001
|
||||
#define NETCONFIG_MODULE 0x00000001
|
||||
|
||||
/* USER MANAGER CONFIG */
|
||||
#define USER_MANAGER_CONFIG_MODULE 0x00000002
|
||||
|
@ -26,7 +26,7 @@
|
|||
|
||||
|
||||
/* config id define*/
|
||||
#define IPCONFIG_V4 (uint64)((uint64)IPCONFIG_MODULE<<32|1)
|
||||
#define IPCONFIG_V4 (uint64)((uint64)NETCONFIG_MODULE<<32|1)
|
||||
|
||||
#define USER_MANAGER_CONFIG_GROUP (uint64)((uint64)USER_MANAGER_CONFIG_MODULE<<32|1)
|
||||
#define USER_MANAGER_CONFIG_USER (uint64)((uint64)USER_MANAGER_CONFIG_MODULE<<32|2)
|
||||
|
|
|
@ -106,18 +106,44 @@ void rpc_worker_start(rpc_worker_thread *th) {
|
|||
pthread_create(&pid, NULL, thread_worker_handler, th);
|
||||
}
|
||||
|
||||
//#define CONFIGM_UNIX_SOCKET "configm.socket"
|
||||
void rpc_get_unix_socket_dir(char* socket_dir)
|
||||
{
|
||||
static char *dir_path = "/var/run/configm";
|
||||
|
||||
if(access(dir_path, R_OK) == 0)
|
||||
{
|
||||
sprintf(socket_dir, "%s/", dir_path);
|
||||
return;
|
||||
}
|
||||
|
||||
if(mkdir(dir_path, 0777) != 0)
|
||||
{
|
||||
rpc_log_error("create recovery file error");
|
||||
strcpy(socket_dir, "");
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(socket_dir, "%s/", dir_path);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
boolean rpc_unix_sockets_get(int port, int *psfd)
|
||||
{
|
||||
struct sockaddr_un serun;
|
||||
int listenfd, size;
|
||||
char socket_path[32];
|
||||
//char *socket_path = CONFIGM_UNIX_SOCKET;
|
||||
char socket_dir[32];
|
||||
int flag = 1;
|
||||
int buff_len = BUFFER_SIZE * 2;
|
||||
|
||||
memset(socket_dir, 0, 32);
|
||||
memset(socket_path, 0, 32);
|
||||
snprintf(socket_path, 32, "%d.socket", port);
|
||||
|
||||
rpc_get_unix_socket_dir(socket_dir);
|
||||
snprintf(socket_path, 32, "%s%d.socket", socket_dir, port);
|
||||
|
||||
if ((listenfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
|
||||
{
|
||||
|
@ -129,6 +155,8 @@ boolean rpc_unix_sockets_get(int port, int *psfd)
|
|||
setsockopt(listenfd, SOL_SOCKET, SO_KEEPALIVE, &flag, sizeof(flag));
|
||||
//reuse
|
||||
setsockopt(listenfd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag));
|
||||
setsockopt(listenfd, SOL_SOCKET, SO_RCVBUF, &buff_len, sizeof(buff_len));
|
||||
setsockopt(listenfd, SOL_SOCKET, SO_SNDBUF, &buff_len, sizeof(buff_len));
|
||||
|
||||
|
||||
memset(&serun, 0, sizeof(serun));
|
||||
|
@ -159,20 +187,26 @@ boolean rpc_unix_socketc_get(char *host, int port, int*pcfd)
|
|||
{
|
||||
struct sockaddr_un cliun;
|
||||
socklen_t cliun_len;
|
||||
char socket_path[32];
|
||||
char socket_dir[32];
|
||||
int buff_len = BUFFER_SIZE * 2;
|
||||
int sockfd;
|
||||
int len;
|
||||
char socket_path[32];
|
||||
|
||||
memset(socket_dir, 0, 32);
|
||||
memset(socket_path, 0, 32);
|
||||
snprintf(socket_path, 32, "%d.socket", port);
|
||||
|
||||
//char *socket_path = CONFIGM_UNIX_SOCKET;
|
||||
rpc_get_unix_socket_dir(socket_dir);
|
||||
snprintf(socket_path, 32, "%s%d.socket", socket_dir, port);
|
||||
|
||||
if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0)
|
||||
{
|
||||
rpc_log_error("client socket error");
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &buff_len, sizeof(buff_len));
|
||||
setsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &buff_len, sizeof(buff_len));
|
||||
|
||||
memset(&cliun, 0, sizeof(cliun));
|
||||
cliun.sun_family = AF_UNIX;
|
||||
|
@ -195,6 +229,7 @@ boolean rpc_tcp_sockets_get(int port, int *psfd)
|
|||
struct sockaddr_in addr;
|
||||
int sfd;
|
||||
int flag = 1;
|
||||
int buff_len = BUFFER_SIZE * 2;
|
||||
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_addr.s_addr = INADDR_ANY;
|
||||
|
@ -208,6 +243,9 @@ boolean rpc_tcp_sockets_get(int port, int *psfd)
|
|||
//reuse
|
||||
setsockopt(sfd, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag));
|
||||
|
||||
setsockopt(sfd, SOL_SOCKET, SO_RCVBUF, &buff_len, sizeof(buff_len));
|
||||
setsockopt(sfd, SOL_SOCKET, SO_SNDBUF, &buff_len, sizeof(buff_len));
|
||||
|
||||
if (bind(sfd, (struct sockaddr*) &addr, sizeof(addr)) == -1)
|
||||
{
|
||||
rpc_log_error("bind error");
|
||||
|
@ -231,6 +269,7 @@ int rpc_tcp_socketc_get(char *host, int port, int*pcfd)
|
|||
{
|
||||
int cfd;
|
||||
struct sockaddr_in addr;
|
||||
int buff_len = BUFFER_SIZE * 2;
|
||||
|
||||
memset(&addr, 0, sizeof(addr));
|
||||
addr.sin_family = AF_INET;
|
||||
|
@ -239,6 +278,9 @@ int rpc_tcp_socketc_get(char *host, int port, int*pcfd)
|
|||
|
||||
cfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
setsockopt(cfd, SOL_SOCKET, SO_RCVBUF, &buff_len, sizeof(buff_len));
|
||||
setsockopt(cfd, SOL_SOCKET, SO_SNDBUF, &buff_len, sizeof(buff_len));
|
||||
|
||||
if (connect(cfd, (struct sockaddr*) &addr, sizeof(addr)) == -1)
|
||||
{
|
||||
rpc_log_error("connect error");
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "ulog.h"
|
||||
#include "log_common.h"
|
||||
|
||||
#define FILTER_CONTENT ":msg,contains,\""MODULE_FMT"\"\n"
|
||||
|
||||
#define BAK_FILE "/tmp/%s"
|
||||
|
||||
int write_log_conf(const u8 level, const char *conf_path, const char *conf_file,
|
||||
const char *rediect_path, const char *filter_mod)
|
||||
{
|
||||
FILE *fp = NULL;
|
||||
int ret = 1;
|
||||
u8 exist_backup = 1;
|
||||
|
||||
/********** rsyslog configure **********/
|
||||
char conf_path_file[MAX_LINE_SIZE];
|
||||
snprintf(conf_path_file, sizeof(conf_path_file), "%s%s", conf_path, conf_file);
|
||||
|
||||
char bak_file[MAX_LINE_SIZE];
|
||||
snprintf(bak_file, sizeof(bak_file), BAK_FILE, conf_file);
|
||||
if (rename(conf_path_file, bak_file) < 0) {
|
||||
if (errno == ENOENT) {
|
||||
exist_backup = 0;
|
||||
ULOG_INFO(g_log, "Been not exist, Configure file:%s is need to backup");
|
||||
} else {
|
||||
ULOG_ERR(g_log, "Baking configure file:%s is failure:%s %d", conf_path_file, strerror(errno), errno);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
fp = fopen(conf_path_file, "w");
|
||||
if (fp == NULL) {
|
||||
ULOG_ERR(g_log, "Opening log configure file:%s is failure:%s", conf_path_file, strerror(errno));
|
||||
goto END;
|
||||
}
|
||||
|
||||
int i;
|
||||
char line[MAX_LINE_SIZE + 100] = {0};
|
||||
if ((filter_mod != NULL) && (strlen(filter_mod) > 0)) {
|
||||
snprintf(line, sizeof(line), FILTER_CONTENT, filter_mod);
|
||||
if (fputs(line, fp) == EOF) {
|
||||
ULOG_ERR(g_log, "Message filter:%s of configure file which is written is failure:%s",
|
||||
filter_mod, strerror(errno));
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char tmp[20];
|
||||
line[0] = '\0'; // 清零
|
||||
for (i = 0; i <= level;) {
|
||||
if (snprintf(tmp, sizeof(tmp), "*.=%s", g_level_array[i].str) < 0) {
|
||||
ULOG_ERR(g_log, "Setting content of log file configure is failure");
|
||||
goto END;
|
||||
}
|
||||
strcat(line, tmp);
|
||||
i++;
|
||||
if (level >= i) {
|
||||
strcat(line, ";");
|
||||
}
|
||||
}
|
||||
strcat(line, " ");
|
||||
|
||||
strcat(line, rediect_path);
|
||||
|
||||
if (fputs(line, fp) == EOF) {
|
||||
ULOG_ERR(g_log, "Configure file which is written is failure:%s", strerror(errno));
|
||||
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 modify_authorizing(const char *redirect_path)
|
||||
{
|
||||
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));
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
#ifndef _LOG_COMMON_H
|
||||
#define _LOG_COMMON_H
|
||||
|
||||
#include "ulog_api.h"
|
||||
|
||||
#define MAX_LINE_SIZE 1024
|
||||
|
||||
#define LOG_CONF_PATH "/etc/rsyslog.d/"
|
||||
|
||||
typedef struct _level_str {
|
||||
u32 level;
|
||||
char str[10];
|
||||
} level_str_t;
|
||||
|
||||
extern ulog_t *g_log;
|
||||
|
||||
static level_str_t g_level_array[] = {
|
||||
{LOG_EMERG, "emerg"},
|
||||
{LOG_ALERT, "alert"},
|
||||
{LOG_CRIT, "crit"},
|
||||
{LOG_ERR, "err"},
|
||||
{LOG_WARNING, "warn"},
|
||||
{LOG_NOTICE, "notice"},
|
||||
{LOG_INFO, "info"},
|
||||
{LOG_DEBUG, "debug"}
|
||||
};
|
||||
|
||||
int write_log_conf(const u8 level, const char *conf_path, const char *conf_file,
|
||||
const char *rediect_path, const char *filter_mod);
|
||||
int modify_authorizing(const char *redirect_path);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,35 @@
|
|||
#include "log_console.h"
|
||||
#include "log_common.h"
|
||||
|
||||
#define LOG_CONF_COSOLE_FILE_NAME "log-console.conf"
|
||||
|
||||
#define LOG_REDIRECT_CONSOLE "/dev/console"
|
||||
|
||||
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) {
|
||||
ULOG_ERR(g_log, "configure of log conosle which is written is failure");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (modify_authorizing(LOG_REDIRECT_CONSOLE) != 0) {
|
||||
ULOG_ERR(g_log, "Modifying authorizing of %s is failure", LOG_REDIRECT_CONSOLE);
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer data)
|
||||
{
|
||||
u32 need_len = sizeof(log_console_t);
|
||||
if (input_len < need_len) {
|
||||
ULOG_WARNING(g_log,
|
||||
"The input paramter of rpc log console is needed length of %u, but the actual length is %u",
|
||||
need_len, input_len);
|
||||
return;
|
||||
}
|
||||
|
||||
config_log_console((const log_console_t *)input);
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef _LOG_CONSOLE_H
|
||||
#define _LOG_CONSOLE_H
|
||||
|
||||
#include "ulog_api.h"
|
||||
#include "common_types.h"
|
||||
#include "rpc_common.h"
|
||||
|
||||
typedef struct _log_console {
|
||||
u8 level;
|
||||
u8 on;
|
||||
char module_name[MAX_MODULE_NAME_SZ];
|
||||
} log_console_t;
|
||||
|
||||
void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer data);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,137 @@
|
|||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "log_file.h"
|
||||
#include "log_common.h"
|
||||
|
||||
#define LOG_CONF_FILE_NAME "log-file.conf"
|
||||
|
||||
#define LOG_LOGRATATE_FILE_NAME "/etc/logrotate.d/log-syslog"
|
||||
|
||||
#define DEFAULT_LOG_FILE "/var/log/syslog-test"
|
||||
#define DEFAULT_LOG_DEL_OVER_DAYS (30 * 6)
|
||||
|
||||
#define LOGROTATE_CONF "%s\n" \
|
||||
"{\n" \
|
||||
" rotate %u\n" \
|
||||
" daily\n" \
|
||||
" missingok\n" \
|
||||
"%s" \
|
||||
" postrotate\n" \
|
||||
" /usr/lib/rsyslog/rsyslog-rotate\n" \
|
||||
" endscript\n" \
|
||||
"}"
|
||||
|
||||
#define STR_COMPRESS " compress\n"
|
||||
|
||||
/*
|
||||
typedef struct _level_str {
|
||||
u32 level;
|
||||
char str[10];
|
||||
} level_str_t;
|
||||
|
||||
|
||||
static level_str_t g_level_array[] = {
|
||||
{LOG_EMERG, "emerg"},
|
||||
{LOG_ALERT, "alert"},
|
||||
{LOG_CRIT, "crit"},
|
||||
{LOG_ERR, "err"},
|
||||
{LOG_WARNING, "warn"},
|
||||
{LOG_NOTICE, "notice"},
|
||||
{LOG_INFO, "info"},
|
||||
{LOG_DEBUG, "debug"}
|
||||
};
|
||||
*/
|
||||
|
||||
#define MAX_LOG_LEVEL_VALUE (sizeof(g_level_array) / sizeof(level_str_t))
|
||||
|
||||
static int write_logratate_conf(const log_file_t *conf, const char *log_path)
|
||||
{
|
||||
int ret = 1;
|
||||
FILE *fp = NULL;
|
||||
/********** logrotate **********/
|
||||
char str_compress[sizeof(STR_COMPRESS)] = {0};
|
||||
if (conf->is_compress == LOG_COMPRESS) {
|
||||
strncpy(str_compress, STR_COMPRESS, sizeof(str_compress));
|
||||
}
|
||||
|
||||
u32 days = DEFAULT_LOG_DEL_OVER_DAYS;
|
||||
if (conf->del_over_days > 0) {
|
||||
days = conf->del_over_days;
|
||||
}
|
||||
|
||||
char line[1024] = {0};
|
||||
if (snprintf(line, sizeof(line), LOGROTATE_CONF, log_path, days, str_compress) < 0) {
|
||||
ULOG_ERR(g_log, "Setting content of logratote is failure");
|
||||
goto END;
|
||||
}
|
||||
|
||||
|
||||
fp = fopen(LOG_LOGRATATE_FILE_NAME, "w");
|
||||
if (fp == NULL) {
|
||||
ULOG_ERR(g_log, "Opening logratate file:%s is failure:%s", LOG_CONF_FILE_NAME, strerror(errno));
|
||||
goto END;
|
||||
}
|
||||
|
||||
if (fputs(line, fp) == EOF) {
|
||||
ULOG_ERR(g_log, "Configure file of logratate which is written is failure:%s", strerror(errno));
|
||||
goto END;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
END:
|
||||
if (fp != NULL) {
|
||||
fclose(fp);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int conf_log_file(const log_file_t *conf)
|
||||
{
|
||||
int ret = 1;
|
||||
u32 max_level = MAX_LOG_LEVEL_VALUE;
|
||||
if (conf->level > max_level) {
|
||||
ULOG_WARNING(g_log, "Configure log level:%u more than max value:%u", conf->level, max_level);
|
||||
return 1;
|
||||
}
|
||||
|
||||
char path[sizeof(conf->path)];
|
||||
if (strlen(conf->path) > 0) {
|
||||
strncpy(path, conf->path, sizeof(path));
|
||||
} else {
|
||||
strncpy(path, DEFAULT_LOG_FILE, sizeof(path));
|
||||
}
|
||||
|
||||
if (write_log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_FILE_NAME, path, NULL) != 0) {
|
||||
ULOG_ERR(g_log, "Log configure which is written is failure");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/********** logrotate **********/
|
||||
if (write_logratate_conf(conf, path) != 0) {
|
||||
ULOG_ERR(g_log, "Logratate configure which is written is failure");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
if (conf->del_over_size > 0) {
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void rpc_conf_log_file(rpc_conn *conn, pointer input, int input_len, pointer data)
|
||||
{
|
||||
u32 need_len = sizeof(log_file_t);
|
||||
if (input_len < need_len) {
|
||||
ULOG_WARNING(g_log,
|
||||
"The input paramter of rpc log file is needed length of %u, but the actual length is %u",
|
||||
need_len, input_len);
|
||||
return;
|
||||
}
|
||||
|
||||
conf_log_file((const log_file_t *)input);
|
||||
//rpc_return_null(conn);
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
#ifndef __LOG_H
|
||||
#define __LOG_H
|
||||
|
||||
#include <syslog.h>
|
||||
#include <linux/limits.h>
|
||||
|
||||
#include "common_types.h"
|
||||
#include "rpc_common.h"
|
||||
#include "log_common.h"
|
||||
|
||||
#define MAX_LOG_PATH MAX_LINE_SIZE
|
||||
|
||||
typedef enum {
|
||||
LOG_UNCOMPRESS = 0,
|
||||
LOG_COMPRESS
|
||||
} log_compress_t;
|
||||
|
||||
typedef struct _log_file {
|
||||
u8 level;
|
||||
char path[MAX_LOG_PATH];
|
||||
log_compress_t is_compress;
|
||||
u32 del_over_days;
|
||||
u64 del_over_size;
|
||||
} log_file_t;
|
||||
|
||||
void rpc_conf_log_file(rpc_conn *conn, pointer input, int input_len, pointer data);
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,72 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "rpc_server.h"
|
||||
#include "ulog_api.h"
|
||||
#include "log_file.h"
|
||||
#include "log_console.h"
|
||||
#include "rpc_module.h"
|
||||
|
||||
|
||||
#define LOG_SCHED_MODULE_NAME "log-sched"
|
||||
#define SERVICE_LOG_FILE_NAME "log-file"
|
||||
|
||||
ulog_t *g_log = NULL;
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
g_log = ulog_init(LOG_SCHED_MODULE_NAME, !run_daemon);
|
||||
if (g_log == NULL) {
|
||||
fprintf(stderr, "Initiating ulog is failure");
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (run_daemon) {
|
||||
if (daemon(0, 0) == -1) {
|
||||
ULOG_ERR(g_log, "Setting daemon running is failure:%s", strerror(errno));
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
|
||||
rpc_server *server = rpc_server_create_ex(RPC_MODULE_SYSLOG_NAME);
|
||||
if (server == NULL)
|
||||
{
|
||||
ULOG_ERR(g_log, "start server error");
|
||||
return 1;
|
||||
|
||||
}
|
||||
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);
|
||||
|
||||
log_file_t log = {0};
|
||||
log.is_compress = LOG_UNCOMPRESS; //LOG_COMPRESS;
|
||||
log.del_over_days = 10;
|
||||
log.level = LOG_DEBUG;
|
||||
rpc_conf_log_file(NULL, &log, sizeof(log), NULL);
|
||||
|
||||
log_console_t console = {0};
|
||||
strcpy(console.module_name, "111");
|
||||
console.level = LOG_DEBUG;
|
||||
console.on = 1;
|
||||
rpc_conf_log_console(NULL, &console, sizeof(console), NULL);
|
||||
END:
|
||||
ulog_close(g_log);
|
||||
return 0;
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
#include "log_file.h"
|
||||
|
||||
int conf_log_file(rpc_conn *conn, pointer input, int input_len, pointer data)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
#ifndef __LOG_H
|
||||
#define __LOG_H
|
||||
|
||||
#include <linux/limits.h>
|
||||
#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
|
|
@ -1,41 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#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);
|
||||
}
|
|
@ -1,14 +1,16 @@
|
|||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include "ulog.h"
|
||||
#include "common_types.h"
|
||||
#include "ulog_api.h"
|
||||
|
||||
#define LOG_MSG_SZ 1024
|
||||
|
||||
ulog_t *ulog_init(const char *module_name)
|
||||
ulog_t *ulog_init(const char *module_name, u8 is_print)
|
||||
{
|
||||
ulog_t *log;
|
||||
u32 len = sizeof(module_name);
|
||||
u32 len = strlen(module_name);
|
||||
|
||||
if (len > MAX_MODULE_NAME_SZ) {
|
||||
fprintf(stderr, "The length:%d of module_name can't more than %d", len, MAX_MODULE_NAME_SZ);
|
||||
|
@ -22,30 +24,35 @@ ulog_t *ulog_init(const char *module_name)
|
|||
}
|
||||
strncpy(log->module_name, module_name, len);
|
||||
|
||||
int opt = LOG_PERROR |LOG_PID;
|
||||
if (is_print > 0) {
|
||||
opt |= LOG_CONS;
|
||||
}
|
||||
openlog(log->module_name, opt, LOG_USER);
|
||||
|
||||
return log;
|
||||
}
|
||||
|
||||
void ulog_close(ulog_t *log)
|
||||
{
|
||||
if (log == NULL) {
|
||||
return;
|
||||
if (log != NULL) {
|
||||
free(log);
|
||||
}
|
||||
|
||||
free(log);
|
||||
closelog();
|
||||
}
|
||||
|
||||
void ulog_record(const ulog_t *log, int level, const char *fmt, ...)
|
||||
{
|
||||
if (log == NULL) {
|
||||
perror("Log is null");
|
||||
fprintf(stderr, "Log is null");
|
||||
return;
|
||||
}
|
||||
|
||||
char log_buf[LOG_MSG_SZ];
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
vsnprintf(log_buf, sizeof(log_buf), log_buf, args);
|
||||
vsnprintf(log_buf, sizeof(log_buf), fmt, args);
|
||||
va_end(args);
|
||||
syslog(level, "[%s] %s", log->module_name, log_buf);
|
||||
syslog(level, MODULE_FMT" %s", log->module_name, log_buf);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
#ifndef _ULOG_H
|
||||
#define _ULOG_H
|
||||
|
||||
#define MODULE_FMT "[%s]"
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue