X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsnmp_agent.c;h=0d1c5778a553e605ccb5ad831361f28c2dfb4ef0;hb=06fe1074812c7f0b903c9aa8d0d9e47036b552b5;hp=6a1968581abb09df32c0b251eaeb5e3e53663105;hpb=217ec252adf547f2dd048489e2498bc31e8f70db;p=collectd.git diff --git a/src/snmp_agent.c b/src/snmp_agent.c index 6a196858..0d1c5778 100644 --- a/src/snmp_agent.c +++ b/src/snmp_agent.c @@ -71,7 +71,7 @@ struct data_definition_s { char *type; char *type_instance; const table_definition_t *table; - _Bool is_instance; + bool is_instance; oid_t *oids; size_t oids_len; double scale; @@ -90,7 +90,7 @@ struct snmp_agent_ctx_s { }; typedef struct snmp_agent_ctx_s snmp_agent_ctx_t; -static snmp_agent_ctx_t *g_agent = NULL; +static snmp_agent_ctx_t *g_agent; #define CHECK_DD_TYPE(_dd, _p, _pi, _t, _ti) \ (_dd->plugin ? !strcmp(_dd->plugin, _p) : 0) && \ @@ -124,7 +124,7 @@ static int snmp_agent_oid_to_string(char *buf, size_t buf_size, char *oid_str_ptr[MAX_OID_LEN]; for (size_t i = 0; i < o->oid_len; i++) { - ssnprintf(oid_str[i], sizeof(oid_str[i]), "%lu", (unsigned long)o->oid[i]); + snprintf(oid_str[i], sizeof(oid_str[i]), "%lu", (unsigned long)o->oid[i]); oid_str_ptr[i] = oid_str[i]; } @@ -166,7 +166,7 @@ static void snmp_agent_dump_data(void) { DEBUG(PLUGIN_NAME ": TypeInstance: %s", dd->type_instance); for (size_t i = 0; i < dd->oids_len; i++) { snmp_agent_oid_to_string(oid_str, sizeof(oid_str), &dd->oids[i]); - DEBUG(PLUGIN_NAME ": OID[%zu]: %s", i, oid_str); + DEBUG(PLUGIN_NAME ": OID[%" PRIsz "]: %s", i, oid_str); } DEBUG(PLUGIN_NAME ": Scale: %g", dd->scale); DEBUG(PLUGIN_NAME ": Shift: %g", dd->shift); @@ -190,7 +190,7 @@ static void snmp_agent_dump_data(void) { DEBUG(PLUGIN_NAME ": TypeInstance: %s", dd->type_instance); for (size_t i = 0; i < dd->oids_len; i++) { snmp_agent_oid_to_string(oid_str, sizeof(oid_str), &dd->oids[i]); - DEBUG(PLUGIN_NAME ": OID[%zu]: %s", i, oid_str); + DEBUG(PLUGIN_NAME ": OID[%" PRIsz "]: %s", i, oid_str); } DEBUG(PLUGIN_NAME ": Scale: %g", dd->scale); DEBUG(PLUGIN_NAME ": Shift: %g", dd->shift); @@ -283,9 +283,10 @@ static int snmp_agent_validate_data(void) { return 0; } -static void snmp_agent_generate_oid2string(oid_t *oid, size_t offset, char *key) { - int key_len = oid->oid[offset]; - int i; +static void snmp_agent_generate_oid2string(oid_t *oid, size_t offset, + char *key) { + size_t key_len = oid->oid[offset]; + size_t i; for (i = 0; i < key_len && offset < oid->oid_len; i++) key[i] = oid->oid[++offset]; @@ -294,10 +295,10 @@ static void snmp_agent_generate_oid2string(oid_t *oid, size_t offset, char *key) } static int snmp_agent_generate_string2oid(oid_t *oid, const char *key) { - int key_len = strlen(key); + size_t key_len = strlen(key); oid->oid[oid->oid_len++] = key_len; - for (int i = 0; i < key_len; i++) { + for (size_t i = 0; i < key_len; i++) { oid->oid[oid->oid_len++] = key[i]; if (oid->oid_len >= MAX_OID_LEN) { ERROR(PLUGIN_NAME ": Conversion key string %s to OID failed", key); @@ -369,9 +370,9 @@ static int snmp_agent_table_row_remove(table_definition_t *td, .severity = NOTIF_WARNING, .time = cdtime(), .plugin = PLUGIN_NAME}; sstrncpy(n.host, hostname_g, sizeof(n.host)); sstrncpy(n.plugin_instance, ins, sizeof(n.plugin_instance)); - ssnprintf(n.message, sizeof(n.message), - "Removed data row from table %s instance %s index %d", td->name, - ins, (index != NULL) ? *index : -1); + snprintf(n.message, sizeof(n.message), + "Removed data row from table %s instance %s index %d", td->name, ins, + (index != NULL) ? *index : -1); plugin_dispatch_notification(&n); if (td->index_oid.oid_len) { @@ -629,9 +630,9 @@ snmp_agent_table_oid_handler(struct netsnmp_mib_handler_s *handler, if (dd->is_instance) { requests->requestvb->type = ASN_OCTET_STR; - snmp_set_var_typed_value(requests->requestvb, - requests->requestvb->type, (const u_char *)instance, - strlen((instance))); + snmp_set_var_typed_value( + requests->requestvb, requests->requestvb->type, + (const u_char *)instance, strlen((instance))); pthread_mutex_unlock(&g_agent->lock); @@ -1116,12 +1117,6 @@ static int snmp_agent_config_table(oconfig_item_t *ci) { } } - llentry_t *entry = llentry_create(td->name, td); - if (entry == NULL) { - snmp_agent_free_table(&td); - return -ENOMEM; - } - td->instance_index = c_avl_create((int (*)(const void *, const void *))strcmp); if (td->instance_index == NULL) { @@ -1136,6 +1131,11 @@ static int snmp_agent_config_table(oconfig_item_t *ci) { return -ENOMEM; } + llentry_t *entry = llentry_create(td->name, td); + if (entry == NULL) { + snmp_agent_free_table(&td); + return -ENOMEM; + } llist_append(g_agent->tables, entry); return 0; @@ -1318,9 +1318,9 @@ static int snmp_agent_update_index(table_definition_t *td, .severity = NOTIF_OKAY, .time = cdtime(), .plugin = PLUGIN_NAME}; sstrncpy(n.host, hostname_g, sizeof(n.host)); sstrncpy(n.plugin_instance, ins, sizeof(n.plugin_instance)); - ssnprintf(n.message, sizeof(n.message), - "Data row added to table %s instance %s index %d", td->name, ins, - (index != NULL) ? *index : -1); + snprintf(n.message, sizeof(n.message), + "Data row added to table %s instance %s index %d", td->name, ins, + (index != NULL) ? *index : -1); plugin_dispatch_notification(&n); return 0;