mirror of
https://github.com/haiwen/libsearpc.git
synced 2025-08-12 09:51:40 +00:00
Filter rpc slow log include password (#61)
* Filter rpc slow log include password * Add filtered funcs list Co-authored-by: 杨赫然 <heran.yang@seafile.com>
This commit is contained in:
parent
54145b03f4
commit
15f6f0b9f4
@ -39,6 +39,7 @@ static GHashTable *service_table;
|
|||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
static FILE *slow_log_fp = NULL;
|
static FILE *slow_log_fp = NULL;
|
||||||
static gint64 slow_threshold;
|
static gint64 slow_threshold;
|
||||||
|
static GList *filtered_funcs;
|
||||||
static pthread_mutex_t slow_log_lock;
|
static pthread_mutex_t slow_log_lock;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -201,7 +202,8 @@ searpc_server_init (RegisterMarshalFunc register_func)
|
|||||||
int
|
int
|
||||||
searpc_server_init_with_slow_log (RegisterMarshalFunc register_func,
|
searpc_server_init_with_slow_log (RegisterMarshalFunc register_func,
|
||||||
const char *slow_log_path,
|
const char *slow_log_path,
|
||||||
gint64 slow_threshold_in)
|
gint64 slow_threshold_in,
|
||||||
|
GList *filtered_funcs_in)
|
||||||
{
|
{
|
||||||
if (slow_log_path) {
|
if (slow_log_path) {
|
||||||
slow_log_fp = fopen (slow_log_path, "a+");
|
slow_log_fp = fopen (slow_log_path, "a+");
|
||||||
@ -210,6 +212,7 @@ searpc_server_init_with_slow_log (RegisterMarshalFunc register_func,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
slow_threshold = slow_threshold_in;
|
slow_threshold = slow_threshold_in;
|
||||||
|
filtered_funcs = filtered_funcs_in;
|
||||||
|
|
||||||
pthread_mutex_init (&slow_log_lock, NULL);
|
pthread_mutex_init (&slow_log_lock, NULL);
|
||||||
}
|
}
|
||||||
@ -305,6 +308,21 @@ searpc_server_register_function (const char *svc_name,
|
|||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
rpc_include_passwd (const char *fname) {
|
||||||
|
GList *ptr;
|
||||||
|
char *rpc_name;
|
||||||
|
|
||||||
|
for (ptr = filtered_funcs; ptr; ptr = ptr->next) {
|
||||||
|
rpc_name = ptr->data;
|
||||||
|
if (g_strcmp0 (fname, rpc_name) == 0) {
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_slow_log_if_necessary (const char *svc_name, const char *func, gsize len,
|
print_slow_log_if_necessary (const char *svc_name, const char *func, gsize len,
|
||||||
const struct timeval *start,
|
const struct timeval *start,
|
||||||
@ -381,10 +399,12 @@ searpc_server_call_function (const char *svc_name,
|
|||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
if (slow_log_fp) {
|
if (slow_log_fp) {
|
||||||
|
if (!filtered_funcs || !rpc_include_passwd (fitem->fname)) {
|
||||||
gettimeofday(&end, NULL);
|
gettimeofday(&end, NULL);
|
||||||
timersub(&end, &start, &intv);
|
timersub(&end, &start, &intv);
|
||||||
print_slow_log_if_necessary (svc_name, func, len, &start, &intv);
|
print_slow_log_if_necessary (svc_name, func, len, &start, &intv);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
json_decref(array);
|
json_decref(array);
|
||||||
|
@ -52,7 +52,8 @@ void searpc_server_init (RegisterMarshalFunc register_func);
|
|||||||
LIBSEARPC_API int
|
LIBSEARPC_API int
|
||||||
searpc_server_init_with_slow_log (RegisterMarshalFunc register_func,
|
searpc_server_init_with_slow_log (RegisterMarshalFunc register_func,
|
||||||
const char *slow_log_path,
|
const char *slow_log_path,
|
||||||
gint64 slow_threshold_in);
|
gint64 slow_threshold_in,
|
||||||
|
GList *filtered_funcs_in);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used in log rotate.
|
* Used in log rotate.
|
||||||
|
Loading…
Reference in New Issue
Block a user