Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Achou.Wang
accel-ppp
提交
06ea9ff8
A
accel-ppp
项目概览
Achou.Wang
/
accel-ppp
通知
6
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
A
accel-ppp
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
06ea9ff8
编写于
11月 15, 2010
作者:
D
Dmitry Kozlov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
log: implemented log_tcp logging target which sends logs to specified host over tcp/ip
上级
b85986e5
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
306 addition
and
7 deletion
+306
-7
accel-pptpd/accel-pptp.conf.5
accel-pptpd/accel-pptp.conf.5
+6
-0
accel-pptpd/log.c
accel-pptpd/log.c
+1
-1
accel-pptpd/log.h
accel-pptpd/log.h
+1
-1
accel-pptpd/logs/CMakeLists.txt
accel-pptpd/logs/CMakeLists.txt
+3
-1
accel-pptpd/logs/log_file.c
accel-pptpd/logs/log_file.c
+3
-3
accel-pptpd/logs/log_pgsql.c
accel-pptpd/logs/log_pgsql.c
+1
-1
accel-pptpd/logs/log_tcp.c
accel-pptpd/logs/log_tcp.c
+291
-0
未找到文件。
accel-pptpd/accel-pptp.conf.5
浏览文件 @
06ea9ff8
...
...
@@ -29,6 +29,9 @@ containes list of modules to load
.BI log_file
This is logging target which logs messages to files. It support per-session/per-user features.
.TP
.BI log_tcp
This is logging target which logs messages over TCP/IP.
.TP
.BI log_pgsql
This is logging target which logs messages to PostgreSQL.
.TP
...
...
@@ -248,6 +251,9 @@ Path to file to write general log.
.BI "log-emerg=" file
Path to file to write emergency messages.
.TP
.BI "log-tcp=" x.x.x.x:port
Send logs to specified host.
.TP
.BI "copy=" n
If this options is given and greater then zero logging engine will duplicate session log in general log.
(Useful when per-session/per-user logs are not used)
...
...
accel-pptpd/log.c
浏览文件 @
06ea9ff8
...
...
@@ -87,7 +87,7 @@ static void do_log(int level, const char *fmt, va_list ap, struct ppp_t *ppp)
m
=
clone_msg
(
cur_msg
);
if
(
!
m
)
break
;
t
->
log
(
m
,
ppp
);
t
->
log
(
t
,
m
,
ppp
);
}
out:
...
...
accel-pptpd/log.h
浏览文件 @
06ea9ff8
...
...
@@ -39,7 +39,7 @@ struct log_target_t
{
struct
list_head
entry
;
void
(
*
log
)(
struct
log_msg_t
*
,
struct
ppp_t
*
ppp
);
void
(
*
log
)(
struct
log_
target_t
*
,
struct
log_
msg_t
*
,
struct
ppp_t
*
ppp
);
void
(
*
reopen
)(
void
);
};
...
...
accel-pptpd/logs/CMakeLists.txt
浏览文件 @
06ea9ff8
ADD_LIBRARY
(
log_file SHARED log_file.c
)
TARGET_LINK_LIBRARIES
(
log_file rt
)
INSTALL
(
TARGETS log_file
ADD_LIBRARY
(
log_tcp SHARED log_tcp.c
)
INSTALL
(
TARGETS log_file log_tcp
LIBRARY DESTINATION usr/lib/accel-pptp
)
...
...
accel-pptpd/logs/log_file.c
浏览文件 @
06ea9ff8
...
...
@@ -261,7 +261,7 @@ static void set_hdr(struct log_msg_t *msg, struct ppp_t *ppp)
msg
->
hdr
->
len
=
strlen
(
msg
->
hdr
->
msg
);
}
static
void
general_log
(
struct
log_msg_t
*
msg
,
struct
ppp_t
*
ppp
)
static
void
general_log
(
struct
log_
target_t
*
t
,
struct
log_
msg_t
*
msg
,
struct
ppp_t
*
ppp
)
{
if
(
ppp
&&
!
conf_copy
)
{
log_free_msg
(
msg
);
...
...
@@ -286,7 +286,7 @@ static struct log_file_pd_t *find_pd(struct ppp_t *ppp, void *pd_key)
return
NULL
;
}
static
void
per_user_log
(
struct
log_msg_t
*
msg
,
struct
ppp_t
*
ppp
)
static
void
per_user_log
(
struct
log_
target_t
*
t
,
struct
log_
msg_t
*
msg
,
struct
ppp_t
*
ppp
)
{
struct
log_file_pd_t
*
lpd
;
...
...
@@ -306,7 +306,7 @@ static void per_user_log(struct log_msg_t *msg, struct ppp_t *ppp)
queue_log
(
&
lpd
->
lf
,
msg
);
}
static
void
per_session_log
(
struct
log_msg_t
*
msg
,
struct
ppp_t
*
ppp
)
static
void
per_session_log
(
struct
log_
target_t
*
t
,
struct
log_
msg_t
*
msg
,
struct
ppp_t
*
ppp
)
{
struct
log_file_pd_t
*
lpd
;
...
...
accel-pptpd/logs/log_pgsql.c
浏览文件 @
06ea9ff8
...
...
@@ -193,7 +193,7 @@ static void queue_log(struct log_msg_t *msg)
}
static
void
general_log
(
struct
log_msg_t
*
msg
,
struct
ppp_t
*
ppp
)
static
void
general_log
(
struct
log_
target_t
*
t
,
struct
log_
msg_t
*
msg
,
struct
ppp_t
*
ppp
)
{
set_hdr
(
msg
,
ppp
);
queue_log
(
msg
);
...
...
accel-pptpd/logs/log_tcp.c
0 → 100644
浏览文件 @
06ea9ff8
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include "log.h"
#include "triton.h"
#include "events.h"
#include "ppp.h"
#include "spinlock.h"
#include "mempool.h"
#include "memdebug.h"
struct
tcp_target_t
{
struct
log_target_t
target
;
struct
list_head
entry
;
struct
triton_md_handler_t
hnd
;
struct
triton_timer_t
conn_timer
;
struct
sockaddr_in
addr
;
char
*
buf
;
int
buf_size
;
int
buf_pos
;
spinlock_t
lock
;
struct
list_head
queue
;
int
queue_len
;
int
connected
:
1
;
int
wait
:
1
;
};
static
int
conf_connect_interval
=
5
;
static
int
conf_queue_len
=
1000
;
static
struct
triton_context_t
tcp_ctx
;
static
const
char
*
level_name
[]
=
{
" msg"
,
"error"
,
" warn"
,
" info"
,
"debug"
};
static
void
start_connect
(
struct
tcp_target_t
*
t
);
static
void
disconnect
(
struct
tcp_target_t
*
t
)
{
triton_md_unregister_handler
(
&
t
->
hnd
);
close
(
t
->
hnd
.
fd
);
start_connect
(
t
);
}
static
void
unpack_msg
(
struct
tcp_target_t
*
t
,
struct
log_msg_t
*
msg
)
{
struct
log_chunk_t
*
chunk
;
int
pos
=
strlen
(
msg
->
hdr
->
msg
);
strcpy
(
t
->
buf
,
msg
->
hdr
->
msg
);
list_for_each_entry
(
chunk
,
msg
->
chunks
,
entry
)
{
memcpy
(
t
->
buf
+
pos
,
chunk
->
msg
,
chunk
->
len
);
pos
+=
chunk
->
len
;
}
t
->
buf_size
=
pos
;
t
->
buf_pos
=
0
;
}
static
int
send_log
(
struct
tcp_target_t
*
t
)
{
struct
log_msg_t
*
msg
;
int
n
;
while
(
1
)
{
spin_lock
(
&
t
->
lock
);
if
(
!
t
->
queue_len
)
{
t
->
wait
=
0
;
spin_unlock
(
&
t
->
lock
);
return
0
;
}
msg
=
list_entry
(
t
->
queue
.
next
,
typeof
(
*
msg
),
entry
);
list_del
(
&
msg
->
entry
);
t
->
queue_len
--
;
spin_unlock
(
&
t
->
lock
);
unpack_msg
(
t
,
msg
);
log_free_msg
(
msg
);
while
(
t
->
buf_pos
!=
t
->
buf_size
)
{
n
=
write
(
t
->
hnd
.
fd
,
t
->
buf
+
t
->
buf_pos
,
t
->
buf_size
-
t
->
buf_pos
);
if
(
n
<
0
)
{
if
(
errno
==
EAGAIN
)
return
1
;
if
(
errno
!=
EPIPE
)
log_emerg
(
"log-tcp: write: %s
\n
"
,
strerror
(
errno
));
disconnect
(
t
);
return
0
;
}
t
->
buf_pos
+=
n
;
}
}
}
static
void
queue_log
(
struct
tcp_target_t
*
t
,
struct
log_msg_t
*
msg
)
{
int
r
;
spin_lock
(
&
t
->
lock
);
if
(
t
->
queue_len
==
conf_queue_len
)
{
spin_unlock
(
&
t
->
lock
);
log_free_msg
(
msg
);
}
list_add_tail
(
&
msg
->
entry
,
&
t
->
queue
);
t
->
queue_len
++
;
if
(
t
->
connected
)
{
r
=
t
->
wait
;
t
->
wait
=
1
;
}
else
r
=
1
;
spin_unlock
(
&
t
->
lock
);
if
(
!
r
)
{
if
(
send_log
(
t
))
triton_md_enable_handler
(
&
t
->
hnd
,
MD_MODE_WRITE
);
}
}
static
void
set_hdr
(
struct
log_msg_t
*
msg
,
struct
ppp_t
*
ppp
)
{
struct
tm
tm
;
char
timestamp
[
32
];
localtime_r
(
&
msg
->
timestamp
.
tv_sec
,
&
tm
);
strftime
(
timestamp
,
sizeof
(
timestamp
),
"%Y-%m-%d %H:%M:%S"
,
&
tm
);
sprintf
(
msg
->
hdr
->
msg
,
"[%s]: %s: %s: "
,
timestamp
,
level_name
[
msg
->
level
],
ppp
?
ppp
->
ifname
:
""
);
msg
->
hdr
->
len
=
strlen
(
msg
->
hdr
->
msg
);
}
static
void
general_log
(
struct
log_target_t
*
lt
,
struct
log_msg_t
*
msg
,
struct
ppp_t
*
ppp
)
{
struct
tcp_target_t
*
t
=
container_of
(
lt
,
typeof
(
*
t
),
target
);
set_hdr
(
msg
,
ppp
);
queue_log
(
t
,
msg
);
}
static
int
log_tcp_write
(
struct
triton_md_handler_t
*
h
)
{
struct
tcp_target_t
*
t
=
container_of
(
h
,
typeof
(
*
t
),
hnd
);
if
(
!
send_log
(
t
))
triton_md_disable_handler
(
h
,
MD_MODE_WRITE
);
return
0
;
}
static
int
log_tcp_connect
(
struct
triton_md_handler_t
*
h
)
{
struct
tcp_target_t
*
t
=
container_of
(
h
,
typeof
(
*
t
),
hnd
);
if
(
connect
(
t
->
hnd
.
fd
,
&
t
->
addr
,
sizeof
(
t
->
addr
)))
{
if
(
errno
==
EAGAIN
)
return
0
;
if
(
errno
==
EINPROGRESS
)
return
0
;
log_emerg
(
"log-tcp: connect: %s
\n
"
,
strerror
(
errno
));
triton_md_unregister_handler
(
&
t
->
hnd
);
close
(
t
->
hnd
.
fd
);
triton_timer_add
(
&
tcp_ctx
,
&
t
->
conn_timer
,
0
);
return
0
;
}
t
->
hnd
.
write
=
log_tcp_write
;
triton_md_disable_handler
(
&
t
->
hnd
,
MD_MODE_WRITE
);
spin_lock
(
&
t
->
lock
);
t
->
connected
=
1
;
t
->
wait
=
1
;
spin_unlock
(
&
t
->
lock
);
send_log
(
t
);
return
0
;
}
static
void
connect_timer
(
struct
triton_timer_t
*
timer
)
{
struct
tcp_target_t
*
t
=
container_of
(
timer
,
typeof
(
*
t
),
conn_timer
);
triton_timer_del
(
timer
);
start_connect
(
t
);
}
static
void
start_connect
(
struct
tcp_target_t
*
t
)
{
t
->
hnd
.
write
=
log_tcp_connect
;
t
->
hnd
.
fd
=
socket
(
PF_INET
,
SOCK_STREAM
,
0
);
if
(
!
t
->
hnd
.
fd
)
{
log_emerg
(
"log-tcp: socket: %s
\n
"
,
strerror
(
errno
));
return
;
}
if
(
fcntl
(
t
->
hnd
.
fd
,
F_SETFL
,
O_NONBLOCK
))
{
log_emerg
(
"log-tcp: failed to set nonblocking mode: %s
\n
"
,
strerror
(
errno
));
close
(
t
->
hnd
.
fd
);
return
;
}
if
(
connect
(
t
->
hnd
.
fd
,
&
t
->
addr
,
sizeof
(
t
->
addr
)))
{
if
(
errno
!=
EINPROGRESS
)
{
log_emerg
(
"log-tcp: connect: %s
\n
"
,
strerror
(
errno
));
close
(
t
->
hnd
.
fd
);
return
;
}
}
triton_md_register_handler
(
&
tcp_ctx
,
&
t
->
hnd
);
triton_md_enable_handler
(
&
t
->
hnd
,
MD_MODE_WRITE
);
}
static
int
start_log
(
const
char
*
_opt
)
{
struct
tcp_target_t
*
t
;
char
*
opt
=
strdup
(
_opt
);
int
port
;
char
*
d
;
d
=
strchr
(
opt
,
':'
);
if
(
!
d
)
goto
err
;
*
d
=
0
;
port
=
atoi
(
d
+
1
);
if
(
port
<=
0
)
goto
err
;
t
=
_malloc
(
sizeof
(
*
t
));
memset
(
t
,
0
,
sizeof
(
*
t
));
t
->
buf
=
_malloc
(
LOG_MAX_SIZE
+
64
);
t
->
conn_timer
.
expire_tv
.
tv_sec
=
conf_connect_interval
;
t
->
conn_timer
.
expire
=
connect_timer
;
t
->
target
.
log
=
general_log
;
memset
(
&
t
->
addr
,
0
,
sizeof
(
t
->
addr
));
t
->
addr
.
sin_family
=
AF_INET
;
t
->
addr
.
sin_port
=
htons
(
port
);
t
->
addr
.
sin_addr
.
s_addr
=
inet_addr
(
opt
);
INIT_LIST_HEAD
(
&
t
->
queue
);
start_connect
(
t
);
log_register_target
(
&
t
->
target
);
return
0
;
err:
free
(
opt
);
return
-
1
;
}
static
void
__init
init
(
void
)
{
struct
conf_sect_t
*
s
=
conf_get_section
(
"log"
);
struct
conf_option_t
*
opt
;
if
(
!
s
)
return
;
triton_context_register
(
&
tcp_ctx
,
NULL
);
list_for_each_entry
(
opt
,
&
s
->
items
,
entry
)
{
if
(
strcmp
(
opt
->
name
,
"log-tcp"
))
continue
;
if
(
!
opt
->
val
||
start_log
(
opt
->
val
))
log_emerg
(
"log: log-tcp: invalid format: '%s'
\n
"
,
opt
->
val
);
}
triton_context_wakeup
(
&
tcp_ctx
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录