提交 bf534029 编写于 作者: D Dmitry Kozlov

net-snmp: run snmp in "special" thread

NET-SNMP is built on top of stale file descriptor multiplexing mechanism (select)
which prevents to use descriptors with number >= 1024.
Due to accel-ppp uses a lots of descriptors NET-SNMP easy overflows this limit and fails
and even may crash whole accel-ppp process.
This patch runs snmp in special thread which does not share file descritor table
with main process, so it can use less descriptors and live in __FD_SETSIZE limit.
Signed-off-by: NDmitry Kozlov <xeb@mail.ru>
上级 918f808e
#include <pthread.h> #include <pthread.h>
#include <signal.h> #include <signal.h>
#include <sys/wait.h>
#include <net-snmp/net-snmp-config.h> #include <net-snmp/net-snmp-config.h>
#include <net-snmp/net-snmp-includes.h> #include <net-snmp/net-snmp-includes.h>
...@@ -26,8 +27,8 @@ static int conf_master = 0; ...@@ -26,8 +27,8 @@ static int conf_master = 0;
static oid* oid_prefix; static oid* oid_prefix;
static size_t oid_prefix_size;*/ static size_t oid_prefix_size;*/
static pthread_t snmp_thr;
static int snmp_term = 0; static int snmp_term = 0;
static int snmp_pid;
/*int accel_ppp_alloc_oid(oid tail, size_t size, oid **oid) /*int accel_ppp_alloc_oid(oid tail, size_t size, oid **oid)
{ {
...@@ -70,7 +71,7 @@ static int agent_log(int major, int minor, void *serv_arg, void *cl_arg) ...@@ -70,7 +71,7 @@ static int agent_log(int major, int minor, void *serv_arg, void *cl_arg)
return 0; return 0;
} }
static void *snmp_thread(void *a) static int snmp_thread(void *a)
{ {
sigset_t set; sigset_t set;
...@@ -107,22 +108,22 @@ static void *snmp_thread(void *a) ...@@ -107,22 +108,22 @@ static void *snmp_thread(void *a)
if (conf_master) if (conf_master)
init_master_agent(); init_master_agent();
while (!snmp_term) { while (!snmp_term)
agent_check_and_process(1); agent_check_and_process(1);
}
snmp_shutdown(conf_agent_name); snmp_shutdown(conf_agent_name);
SOCK_CLEANUP; SOCK_CLEANUP;
return NULL; return 0;
} }
static void snmp_ctx_close(struct triton_context_t *ctx) static void snmp_ctx_close(struct triton_context_t *ctx)
{ {
int status;
snmp_term = 1; snmp_term = 1;
pthread_cancel(snmp_thr); kill(snmp_pid, 32);
pthread_join(snmp_thr, NULL); waitpid(snmp_pid, &status, 0);
triton_context_unregister(ctx); triton_context_unregister(ctx);
} }
...@@ -146,7 +147,8 @@ static void init(void) ...@@ -146,7 +147,8 @@ static void init(void)
if (opt) if (opt)
conf_oid_prefix = opt;*/ conf_oid_prefix = opt;*/
pthread_create(&snmp_thr, NULL, snmp_thread, NULL); snmp_pid = clone(snmp_thread, malloc(1024*1024) + 1024*1024, CLONE_SIGHAND|CLONE_FS|CLONE_VM|CLONE_THREAD, NULL);
triton_context_register(&ctx, NULL); triton_context_register(&ctx, NULL);
triton_context_wakeup(&ctx); triton_context_wakeup(&ctx);
triton_collect_cpu_usage(); triton_collect_cpu_usage();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册