[添加文件]
1.添加CertStore源代码程序文件 [目录层次介绍] 1.conf为配置文件 2.make为Makefile配置文件 3.release为执行make tarball后生成的安装包文件 4.src源代码 src/components 使用的静态库所需的头文件(libevent、openssl、hiredis) src/inc 系统所需头文件 src/lib 静态库 src/package 安装包临时目录 src/rt 功能函数代码 [编译运行] 1.cd src && make 2../cert_store --debug[release/deamon] [安装包使用] 1.cd src && make tarball 2.cd release (获取安装包) 2.1.tar -zxvf xxxx.tar.gz 2.2 cd xxx.tar.gz && make install [版本问题] 1.证书生成代码屏蔽(未调通) 2.Redis超时处理未完成 3.连接响应断开后,资源未释放
This commit is contained in:
43
src/rt/rt.mk
Normal file
43
src/rt/rt.mk
Normal file
@@ -0,0 +1,43 @@
|
||||
|
||||
|
||||
# standard component Makefile header
|
||||
sp := $(sp).x
|
||||
dirstack_$(sp) := $(d)
|
||||
d := $(dir)
|
||||
|
||||
# component specification
|
||||
|
||||
OBJS_$(d) :=\
|
||||
$(OBJ_DIR)/rt_file.o\
|
||||
$(OBJ_DIR)/rt_stdlib.o\
|
||||
$(OBJ_DIR)/rt_string.o\
|
||||
$(OBJ_DIR)/rt_time.o\
|
||||
$(OBJ_DIR)/rt_util.o\
|
||||
|
||||
|
||||
CFLAGS_LOCAL += -I$(d)
|
||||
$(OBJS_$(d)): CFLAGS_LOCAL := -std=gnu99 -W -Wall -Wunused-parameter -g -O3 \
|
||||
-I$(d)\
|
||||
|
||||
|
||||
# standard component Makefile rules
|
||||
|
||||
DEPS_$(d) := $(OBJS_$(d):.o=.d)
|
||||
|
||||
#LIBS_LIST := $(LIBS_LIST) $(LIBRARY)
|
||||
LIBS_LIST := $(LIBS_LIST)
|
||||
|
||||
CLEAN_LIST := $(CLEAN_LIST) $(OBJS_$(d)) $(DEPS_$(d))
|
||||
|
||||
-include $(DEPS_$(d))
|
||||
|
||||
#$(LIBRARY): $(OBJS)
|
||||
# $(MYARCHIVE)
|
||||
|
||||
$(OBJ_DIR)/%.o: $(d)/%.c
|
||||
$(COMPILE)
|
||||
|
||||
# standard component Makefile footer
|
||||
|
||||
d := $(dirstack_$(sp))
|
||||
sp := $(basename $(sp))
|
||||
29
src/rt/rt_common.h
Normal file
29
src/rt/rt_common.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* rt_common.h
|
||||
* Created by fengweihao
|
||||
* 30 May, 2018
|
||||
* Func: System timer control interface
|
||||
*/
|
||||
|
||||
#ifndef __RT_COMMON_H__
|
||||
#define __RT_COMMON_H__
|
||||
|
||||
#include <assert.h>
|
||||
#define EVAL_TM_STYLE "%Y-%m-%d"
|
||||
|
||||
/** Alway treated the expr as true */
|
||||
#ifndef likely
|
||||
#define likely(expr) __builtin_expect(!!(expr), 1)
|
||||
#endif
|
||||
|
||||
/** Alway treated the expr as false */
|
||||
#ifndef unlikely
|
||||
#define unlikely(expr) __builtin_expect(!!(expr), 0)
|
||||
#endif
|
||||
|
||||
int run_mode;
|
||||
#define MODE_TYPE(x) run_mode & x
|
||||
|
||||
#define __rt_always_inline__ __attribute__((always_inline)) inline
|
||||
|
||||
#endif
|
||||
32
src/rt/rt_file.c
Normal file
32
src/rt/rt_file.c
Normal file
@@ -0,0 +1,32 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <dirent.h>
|
||||
|
||||
#include "rt_common.h"
|
||||
|
||||
int rt_file_exsit(const char *realpath_file)
|
||||
{
|
||||
return (!access(realpath_file, F_OK));
|
||||
}
|
||||
|
||||
int rt_dir_exsit (const char *realpath)
|
||||
{
|
||||
DIR *dir = NULL;
|
||||
int exsit = 0;
|
||||
|
||||
if (unlikely (!realpath))
|
||||
goto finish;
|
||||
|
||||
dir = opendir(realpath);
|
||||
if (!dir) goto finish;
|
||||
|
||||
exsit = 1;
|
||||
closedir(dir);
|
||||
finish:
|
||||
return exsit;
|
||||
}
|
||||
|
||||
7
src/rt/rt_file.h
Normal file
7
src/rt/rt_file.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef __RT_FILE_H__
|
||||
#define __RT_FILE_H__
|
||||
|
||||
extern int rt_file_exsit(const char *);
|
||||
extern int rt_dir_exsit (const char *realpath);
|
||||
|
||||
#endif
|
||||
29
src/rt/rt_stdlib.c
Normal file
29
src/rt/rt_stdlib.c
Normal file
@@ -0,0 +1,29 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "rt_common.h"
|
||||
#include "rt_stdlib.h"
|
||||
|
||||
void *kmalloc(int s,
|
||||
int flags,
|
||||
int __attribute__((__unused__)) node)
|
||||
{
|
||||
void *p;
|
||||
|
||||
if(likely((p = malloc(s)) != NULL)){
|
||||
if(flags & MPF_CLR)
|
||||
memset(p, 0, s);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
void kfree(void *p)
|
||||
{
|
||||
if(likely(p != NULL)){
|
||||
free(p);
|
||||
}
|
||||
|
||||
p = NULL;
|
||||
}
|
||||
|
||||
15
src/rt/rt_stdlib.h
Normal file
15
src/rt/rt_stdlib.h
Normal file
@@ -0,0 +1,15 @@
|
||||
#ifndef __RT_STDLIB_H__
|
||||
#define __RT_STDLIB_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
/** memory flags */
|
||||
#define MPF_CLR (1 << 0) /** Clear it after allocated */
|
||||
|
||||
extern void kfree(void *p);
|
||||
|
||||
void *kmalloc(int s, int flags, int __attribute__((__unused__)) node);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
35
src/rt/rt_string.c
Normal file
35
src/rt/rt_string.c
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "rt_string.h"
|
||||
|
||||
const char *
|
||||
try_val_to_str_idx(const unsigned int val, const struct value_string *vs, int *idx)
|
||||
{
|
||||
int i = 0;
|
||||
if (idx == NULL){
|
||||
goto finish;
|
||||
}
|
||||
|
||||
if(vs) {
|
||||
while (vs[i].strptr) {
|
||||
if (vs[i].value == val) {
|
||||
*idx = i;
|
||||
return(vs[i].strptr);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
finish:
|
||||
*idx = -1;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char*
|
||||
val_to_str(const unsigned int val, const struct value_string *vs)
|
||||
{
|
||||
int ignore_me;
|
||||
|
||||
return try_val_to_str_idx(val, vs, &ignore_me);
|
||||
}
|
||||
|
||||
66
src/rt/rt_string.h
Normal file
66
src/rt/rt_string.h
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifndef __UTIL_STRING_H__
|
||||
#define __UTIL_STRING_H__
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifndef STRLEN
|
||||
#define STRLEN(STR) ((int)strlen((const char *)STR))
|
||||
#endif
|
||||
|
||||
#ifndef ISALNUM
|
||||
#define ISALNUM(S) (isalnum((const char)S))
|
||||
#endif
|
||||
|
||||
#ifndef STRCMP
|
||||
#define STRCMP(S,D) (strcmp((const char *)S, (const char *)D))
|
||||
#endif
|
||||
|
||||
#ifndef STRSTR
|
||||
#define STRSTR(D,S) (strstr((const char *)D,(const char *)S))
|
||||
#endif
|
||||
|
||||
#ifndef STRNCMP
|
||||
#define STRNCMP(S,D,L) (strncmp((const char *)S, (const char *)D, L))
|
||||
#endif
|
||||
|
||||
#ifndef STRCAT
|
||||
#define STRCAT(D,S) (strcat((char *)D, (const char *)S))
|
||||
#endif
|
||||
|
||||
#ifndef FOREVER
|
||||
#define FOREVER for(;;)
|
||||
#endif
|
||||
|
||||
typedef struct atomic {
|
||||
volatile int counter;
|
||||
} atomic_t;
|
||||
|
||||
struct value_string {
|
||||
unsigned int value;
|
||||
const char *strptr;
|
||||
};
|
||||
|
||||
extern const char*
|
||||
val_to_str(const unsigned int val, const struct value_string *vs);
|
||||
|
||||
typedef struct{
|
||||
#define ATOMIC64_SIZE sizeof(long long)
|
||||
int64_t counter;
|
||||
}atomic64_t;
|
||||
|
||||
#define ATOMIC_INIT(i) { (i) }
|
||||
|
||||
#define atomic_read(v) (*(volatile int *)&(v)->counter)
|
||||
#define atomic64_read(v) (*(volatile int64_t *)&(v)->counter)
|
||||
|
||||
#define atomic_add(x, y) (__sync_add_and_fetch((&(((atomic_t *)x)->counter)), (y)))
|
||||
#define atomic64_add(x, y) (__sync_add_and_fetch((&(((atomic64_t *)x)->counter)), (y)))
|
||||
|
||||
static inline void atomic_set(atomic_t *v, int32_t val)
|
||||
{
|
||||
v->counter = val;
|
||||
}
|
||||
|
||||
#endif
|
||||
29
src/rt/rt_sync.h
Normal file
29
src/rt/rt_sync.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* sync.h
|
||||
* Created by Tsihang <qihang@semptian.com>
|
||||
* 1 June, 2015
|
||||
* Func: System startup synchronous operation interface of SPASR
|
||||
* Personal.Q
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __SYSTEM_SYNC_H__
|
||||
#define __SYSTEM_SYNC_H__
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#define rt_pthread_attr pthread_attr_t
|
||||
#define rt_pthread pthread_t
|
||||
#define rt_mutex pthread_mutex_t
|
||||
#define rt_mutex_attr pthread_mutexattr_t
|
||||
#define rt_mutex_init(mut, mutattr ) pthread_mutex_init(mut, mutattr)
|
||||
#define rt_mutex_lock(mut) pthread_mutex_lock(mut)
|
||||
#define rt_mutex_trylock(mut) pthread_mutex_trylock(mut)
|
||||
#define rt_mutex_unlock(mut) pthread_mutex_unlock(mut)
|
||||
#define rt_mutex_destroy(mut) pthread_mutex_destroy(mut)
|
||||
|
||||
#define INIT_MUTEX(name)\
|
||||
rt_mutex name = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
#endif
|
||||
|
||||
58
src/rt/rt_time.c
Normal file
58
src/rt/rt_time.c
Normal file
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* rt_time.c
|
||||
* Created by fengweihao
|
||||
* 30 May, 2018
|
||||
* Func: Time Component
|
||||
*/
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "rt_time.h"
|
||||
|
||||
struct tm *rt_localtime(time_t timep, struct tm *result)
|
||||
{
|
||||
return localtime_r(&timep, result);
|
||||
}
|
||||
|
||||
uint64_t rt_time_s(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return (tv.tv_sec + tv.tv_usec/1000/1000); /** CST timestamp */
|
||||
};
|
||||
|
||||
uint64_t rt_time_ms(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return (tv.tv_sec * 1000 + tv.tv_usec/1000);
|
||||
}
|
||||
|
||||
uint64_t rt_time_ns()
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv, NULL);
|
||||
return (tv.tv_sec * 1000 * 1000 + tv.tv_usec);
|
||||
}
|
||||
|
||||
int rt_tms2str(uint64_t ts, const char *tm_form, char *date, size_t len)
|
||||
{
|
||||
struct tm *tm = NULL;
|
||||
|
||||
assert(date);
|
||||
/** Convert ts to localtime with local time-zone */
|
||||
tm = localtime((time_t *)&ts);
|
||||
return (int)strftime(date, len - 1, tm_form, tm);
|
||||
}
|
||||
|
||||
int rt_curr_tms2str(const char *tm_form, char *date, size_t len)
|
||||
{
|
||||
return rt_tms2str(time(NULL), tm_form, date, len);
|
||||
}
|
||||
|
||||
12
src/rt/rt_time.h
Normal file
12
src/rt/rt_time.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#ifndef __RT_TM_H__
|
||||
#define __RT_TM_H__
|
||||
|
||||
struct tm *rt_localtime(time_t timep, struct tm *result);
|
||||
int rt_tms2str(uint64_t ts, const char *tm_form, char *date, size_t len);
|
||||
int rt_curr_tms2str(const char *tm_form, char *date, size_t len);
|
||||
|
||||
u_int64_t rt_time_s(void);
|
||||
u_int64_t rt_time_ms(void);
|
||||
u_int64_t rt_time_ns();
|
||||
|
||||
#endif
|
||||
53
src/rt/rt_util.c
Normal file
53
src/rt/rt_util.c
Normal file
@@ -0,0 +1,53 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <net/if.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <linux/sockios.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <pwd.h>
|
||||
#include <sys/utsname.h>
|
||||
#include <dirent.h>
|
||||
#include <ctype.h>
|
||||
#include "rt_string.h"
|
||||
#include "rt_common.h"
|
||||
|
||||
void do_system(const char *cmd)
|
||||
{
|
||||
int xret = -1;
|
||||
|
||||
if (likely(cmd)) {
|
||||
xret = system(cmd);
|
||||
if (likely(xret < 0)){
|
||||
;//rt_log_error(ERRNO_FATAL, "%s", strerror(errno));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#define BUF_SIZE 1024
|
||||
void rt_get_pname_by_pid(pid_t pid, char *task_name)
|
||||
{
|
||||
char proc_pid_path[BUF_SIZE];
|
||||
char buf[BUF_SIZE];
|
||||
sprintf(proc_pid_path, "/proc/%d/status", pid);
|
||||
FILE* fp = fopen(proc_pid_path, "r");
|
||||
if(NULL != fp){
|
||||
if( fgets(buf, BUF_SIZE-1, fp)== NULL ){
|
||||
fclose(fp);
|
||||
}
|
||||
fclose(fp);
|
||||
sscanf(buf, "%*s %s", task_name);
|
||||
}
|
||||
}
|
||||
|
||||
7
src/rt/rt_util.h
Normal file
7
src/rt/rt_util.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#ifndef __RT_UTIL_H__
|
||||
#define __RT_UTIL_H__
|
||||
|
||||
void do_system(const char *cmd);
|
||||
void rt_get_pname_by_pid(unsigned long pid, char *task_name) ;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user