X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fsnmp.c;h=408defa9b4ea385336d66d429d10560422fb6b59;hb=e7929dac268957cbbd9082717759c3917ac1b51e;hp=4311ff1670b5f92a6e2927d16420e2c1c5f8a011;hpb=8cf1acdb96d027b1d48c9dfb74fea313e63ceedf;p=collectd.git diff --git a/src/snmp.c b/src/snmp.c index 4311ff16..408defa9 100644 --- a/src/snmp.c +++ b/src/snmp.c @@ -707,14 +707,14 @@ static value_t csnmp_value_list_to_value (struct variable_list *vl, int type, || (vl->type == ASN_GAUGE)) { temp = (uint32_t) *vl->val.integer; - DEBUG ("snmp plugin: Parsed int32 value is %llu.", temp); + DEBUG ("snmp plugin: Parsed int32 value is %"PRIu64".", temp); } else if (vl->type == ASN_COUNTER64) { temp = (uint32_t) vl->val.counter64->high; temp = temp << 32; temp += (uint32_t) vl->val.counter64->low; - DEBUG ("snmp plugin: Parsed int64 value is %llu.", temp); + DEBUG ("snmp plugin: Parsed int64 value is %"PRIu64".", temp); } else { @@ -779,7 +779,7 @@ static int csnmp_check_res_left_subtree (const host_definition_t *host, if (vb == NULL) { ERROR ("snmp plugin: host %s: Expected one more variable for " - "the instance.."); + "the instance..", host->name); return (-1); } @@ -909,7 +909,7 @@ static int csnmp_dispatch_table (host_definition_t *host, data_definition_t *dat strncpy (vl.host, host->name, sizeof (vl.host)); vl.host[sizeof (vl.host) - 1] = '\0'; - strcpy (vl.plugin, "snmp"); + sstrncpy (vl.plugin, "snmp", sizeof (vl.plugin)); vl.interval = host->interval; vl.time = time (NULL); @@ -1120,10 +1120,6 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) vb = res->variables; if (vb == NULL) { - if (res != NULL) - snmp_free_pdu (res); - res = NULL; - status = -1; break; } @@ -1132,10 +1128,7 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) * subtree */ if (csnmp_check_res_left_subtree (host, data, res) != 0) { - if (res != NULL) - snmp_free_pdu (res); - res = NULL; - + status = 0; break; } @@ -1157,11 +1150,7 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) (vb != NULL) && (vb->next_variable != NULL); vb = vb->next_variable) /* do nothing */; - if (vb == NULL) - { - status = -1; - break; - } + assert (vb != NULL); /* Copy OID to oid_list[data->values_len] */ memcpy (oid_list[data->values_len].oid, vb->name, @@ -1224,6 +1213,10 @@ static int csnmp_read_table (host_definition_t *host, data_definition_t *data) res = NULL; } /* while (status == 0) */ + if (res != NULL) + snmp_free_pdu (res); + res = NULL; + if (status == 0) csnmp_dispatch_table (host, data, instance_list, value_table); @@ -1301,7 +1294,7 @@ static int csnmp_read_value (host_definition_t *host, data_definition_t *data) strncpy (vl.host, host->name, sizeof (vl.host)); vl.host[sizeof (vl.host) - 1] = '\0'; - strcpy (vl.plugin, "snmp"); + sstrncpy (vl.plugin, "snmp", sizeof (vl.plugin)); strncpy (vl.type_instance, data->instance.string, sizeof (vl.type_instance)); vl.type_instance[sizeof (vl.type_instance) - 1] = '\0'; @@ -1400,8 +1393,8 @@ static int csnmp_read_host (host_definition_t *host) if ((time_end - time_start) > host->interval) { WARNING ("snmp plugin: Host `%s' should be queried every %i seconds, " - "but reading all values takes %i seconds.", - host->name, host->interval, time_end - time_start); + "but reading all values takes %u seconds.", + host->name, host->interval, (unsigned int) (time_end - time_start)); } return (0);