summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7778f85)
raw | patch | inline | side by side (parent: 7778f85)
author | Pavel Rochnyack <pavel2000@ngs.ru> | |
Thu, 13 Jul 2017 11:51:31 +0000 (18:51 +0700) | ||
committer | Pavel Rochnyack <pavel2000@ngs.ru> | |
Thu, 13 Jul 2017 15:22:48 +0000 (22:22 +0700) |
* Do not start working thread if plugin not configured.
That allows to avoid useless CPU consumption by polling loop.
* Do not register 'write' / 'missing' callbacks if there was no <Table> configured.
These callbacks do not do anything in this case.
* Registration of 'shutdown' callback delayed to 'init' phase.
That allows to avoid useless CPU consumption by polling loop.
* Do not register 'write' / 'missing' callbacks if there was no <Table> configured.
These callbacks do not do anything in this case.
* Registration of 'shutdown' callback delayed to 'init' phase.
src/snmp_agent.c | patch | blob | history |
diff --git a/src/snmp_agent.c b/src/snmp_agent.c
index 456d43e0ab933724cb2c3332a299e4d7e70e8653..6a1968581abb09df32c0b251eaeb5e3e53663105 100644 (file)
--- a/src/snmp_agent.c
+++ b/src/snmp_agent.c
(_dd->type ? !strcmp(_dd->type, _t) : 0) && \
(_dd->type_instance ? !strcmp(_dd->type_instance, _ti) : 1)
+static int snmp_agent_shutdown(void);
static void *snmp_agent_thread_run(void *arg);
static int snmp_agent_register_oid(oid_t *oid, Netsnmp_Node_Handler *handler);
static int snmp_agent_set_vardata(void *dst_buf, size_t *dst_buf_len,
static int snmp_agent_init(void) {
int ret;
- ret = snmp_agent_preinit();
- if (ret != 0)
- return ret;
+ if (g_agent == NULL || ((llist_head(g_agent->scalars) == NULL) &&
+ (llist_head(g_agent->tables) == NULL))) {
+ ERROR(PLUGIN_NAME ": snmp_agent_init: plugin not configured");
+ return -EINVAL;
+ }
+
+ plugin_register_shutdown(PLUGIN_NAME, snmp_agent_shutdown);
ret = snmp_agent_register_scalar_oids();
if (ret != 0)
return ret;
}
+ if (llist_head(g_agent->tables) != NULL) {
+ plugin_register_write(PLUGIN_NAME, snmp_agent_collect, NULL);
+ plugin_register_missing(PLUGIN_NAME, snmp_agent_clear_missing, NULL);
+ }
+
return 0;
}
void module_register(void) {
plugin_register_init(PLUGIN_NAME, snmp_agent_init);
plugin_register_complex_config(PLUGIN_NAME, snmp_agent_config);
- plugin_register_write(PLUGIN_NAME, snmp_agent_collect, NULL);
- plugin_register_missing(PLUGIN_NAME, snmp_agent_clear_missing, NULL);
- plugin_register_shutdown(PLUGIN_NAME, snmp_agent_shutdown);
}