diff options
author | Anders Kaseorg <andersk@mit.edu> | 2012-06-29 00:57:48 -0400 |
---|---|---|
committer | Holger Weiss <holger@zedat.fu-berlin.de> | 2012-06-29 13:39:11 +0200 |
commit | 028d50d6f99e647a325a0a68303016382c4bbdc9 (patch) | |
tree | 1d9a14635602169d137409becfa108cd6bdb371c /plugins/check_snmp.c | |
parent | 9976876584e5a1df6e1c9315212c3d274df7a12e (diff) | |
download | monitoring-plugins-028d50d6f99e647a325a0a68303016382c4bbdc9.tar.gz |
Die when asprintf fails
Fixes many instances of
warning: ignoring return value of 'asprintf', declared with attribute warn_unused_result [-Wunused-result]
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
Diffstat (limited to 'plugins/check_snmp.c')
-rw-r--r-- | plugins/check_snmp.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index a5a88d25..2d9861bc 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -255,9 +255,9 @@ main (int argc, char **argv) | |||
255 | command_line = calloc (9 + numauthpriv + 1 + numoids + 1, sizeof (char *)); | 255 | command_line = calloc (9 + numauthpriv + 1 + numoids + 1, sizeof (char *)); |
256 | command_line[0] = snmpcmd; | 256 | command_line[0] = snmpcmd; |
257 | command_line[1] = strdup ("-t"); | 257 | command_line[1] = strdup ("-t"); |
258 | asprintf (&command_line[2], "%d", timeout_interval); | 258 | xasprintf (&command_line[2], "%d", timeout_interval); |
259 | command_line[3] = strdup ("-r"); | 259 | command_line[3] = strdup ("-r"); |
260 | asprintf (&command_line[4], "%d", retries); | 260 | xasprintf (&command_line[4], "%d", retries); |
261 | command_line[5] = strdup ("-m"); | 261 | command_line[5] = strdup ("-m"); |
262 | command_line[6] = strdup (miblist); | 262 | command_line[6] = strdup (miblist); |
263 | command_line[7] = "-v"; | 263 | command_line[7] = "-v"; |
@@ -267,16 +267,16 @@ main (int argc, char **argv) | |||
267 | command_line[9 + i] = authpriv[i]; | 267 | command_line[9 + i] = authpriv[i]; |
268 | } | 268 | } |
269 | 269 | ||
270 | asprintf (&command_line[9 + numauthpriv], "%s:%s", server_address, port); | 270 | xasprintf (&command_line[9 + numauthpriv], "%s:%s", server_address, port); |
271 | 271 | ||
272 | /* This is just for display purposes, so it can remain a string */ | 272 | /* This is just for display purposes, so it can remain a string */ |
273 | asprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s %s:%s", | 273 | xasprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s %s:%s", |
274 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]", | 274 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]", |
275 | server_address, port); | 275 | server_address, port); |
276 | 276 | ||
277 | for (i = 0; i < numoids; i++) { | 277 | for (i = 0; i < numoids; i++) { |
278 | command_line[9 + numauthpriv + 1 + i] = oids[i]; | 278 | command_line[9 + numauthpriv + 1 + i] = oids[i]; |
279 | asprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); | 279 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); |
280 | } | 280 | } |
281 | 281 | ||
282 | command_line[9 + numauthpriv + 1 + numoids] = NULL; | 282 | command_line[9 + numauthpriv + 1 + numoids] = NULL; |
@@ -371,14 +371,14 @@ main (int argc, char **argv) | |||
371 | if (dq_count) { /* unfinished line */ | 371 | if (dq_count) { /* unfinished line */ |
372 | /* copy show verbatim first */ | 372 | /* copy show verbatim first */ |
373 | if (!mult_resp) mult_resp = strdup(""); | 373 | if (!mult_resp) mult_resp = strdup(""); |
374 | asprintf (&mult_resp, "%s%s:\n%s\n", mult_resp, oids[i], show); | 374 | xasprintf (&mult_resp, "%s%s:\n%s\n", mult_resp, oids[i], show); |
375 | /* then strip out unmatched double-quote from single-line output */ | 375 | /* then strip out unmatched double-quote from single-line output */ |
376 | if (show[0] == '"') show++; | 376 | if (show[0] == '"') show++; |
377 | 377 | ||
378 | /* Keep reading until we match end of double-quoted string */ | 378 | /* Keep reading until we match end of double-quoted string */ |
379 | for (line++; line < chld_out.lines; line++) { | 379 | for (line++; line < chld_out.lines; line++) { |
380 | ptr = chld_out.line[line]; | 380 | ptr = chld_out.line[line]; |
381 | asprintf (&mult_resp, "%s%s\n", mult_resp, ptr); | 381 | xasprintf (&mult_resp, "%s%s\n", mult_resp, ptr); |
382 | 382 | ||
383 | COUNT_SEQ(ptr, bk_count, dq_count) | 383 | COUNT_SEQ(ptr, bk_count, dq_count) |
384 | while (dq_count && ptr[0] != '\n' && ptr[0] != '\0') { | 384 | while (dq_count && ptr[0] != '\n' && ptr[0] != '\0') { |
@@ -424,11 +424,11 @@ main (int argc, char **argv) | |||
424 | /* Convert to per second, then use multiplier */ | 424 | /* Convert to per second, then use multiplier */ |
425 | temp_double = temp_double/duration*rate_multiplier; | 425 | temp_double = temp_double/duration*rate_multiplier; |
426 | iresult = get_status(temp_double, thlds[i]); | 426 | iresult = get_status(temp_double, thlds[i]); |
427 | asprintf (&show, conv, temp_double); | 427 | xasprintf (&show, conv, temp_double); |
428 | } | 428 | } |
429 | } else { | 429 | } else { |
430 | iresult = get_status(response_value[i], thlds[i]); | 430 | iresult = get_status(response_value[i], thlds[i]); |
431 | asprintf (&show, conv, response_value[i]); | 431 | xasprintf (&show, conv, response_value[i]); |
432 | } | 432 | } |
433 | } | 433 | } |
434 | 434 | ||
@@ -472,16 +472,16 @@ main (int argc, char **argv) | |||
472 | 472 | ||
473 | /* Prepend a label for this OID if there is one */ | 473 | /* Prepend a label for this OID if there is one */ |
474 | if (nlabels >= (size_t)1 && (size_t)i < nlabels && labels[i] != NULL) | 474 | if (nlabels >= (size_t)1 && (size_t)i < nlabels && labels[i] != NULL) |
475 | asprintf (&outbuff, "%s%s%s %s%s%s", outbuff, | 475 | xasprintf (&outbuff, "%s%s%s %s%s%s", outbuff, |
476 | (i == 0) ? " " : output_delim, | 476 | (i == 0) ? " " : output_delim, |
477 | labels[i], mark (iresult), show, mark (iresult)); | 477 | labels[i], mark (iresult), show, mark (iresult)); |
478 | else | 478 | else |
479 | asprintf (&outbuff, "%s%s%s%s%s", outbuff, (i == 0) ? " " : output_delim, | 479 | xasprintf (&outbuff, "%s%s%s%s%s", outbuff, (i == 0) ? " " : output_delim, |
480 | mark (iresult), show, mark (iresult)); | 480 | mark (iresult), show, mark (iresult)); |
481 | 481 | ||
482 | /* Append a unit string for this OID if there is one */ | 482 | /* Append a unit string for this OID if there is one */ |
483 | if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL) | 483 | if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL) |
484 | asprintf (&outbuff, "%s %s", outbuff, unitv[i]); | 484 | xasprintf (&outbuff, "%s %s", outbuff, unitv[i]); |
485 | 485 | ||
486 | /* Write perfdata with whatever can be parsed by strtod, if possible */ | 486 | /* Write perfdata with whatever can be parsed by strtod, if possible */ |
487 | ptr = NULL; | 487 | ptr = NULL; |
@@ -523,7 +523,7 @@ main (int argc, char **argv) | |||
523 | 523 | ||
524 | current_length=0; | 524 | current_length=0; |
525 | for(i=0; i<total_oids; i++) { | 525 | for(i=0; i<total_oids; i++) { |
526 | asprintf(&temp_string,"%.0f",response_value[i]); | 526 | xasprintf(&temp_string,"%.0f",response_value[i]); |
527 | if(temp_string==NULL) | 527 | if(temp_string==NULL) |
528 | die(STATE_UNKNOWN,_("Cannot asprintf()")); | 528 | die(STATE_UNKNOWN,_("Cannot asprintf()")); |
529 | response_length = strlen(temp_string); | 529 | response_length = strlen(temp_string); |
@@ -869,7 +869,7 @@ validate_arguments () | |||
869 | die(STATE_UNKNOWN, _("No OIDs specified\n")); | 869 | die(STATE_UNKNOWN, _("No OIDs specified\n")); |
870 | 870 | ||
871 | if (proto == NULL) | 871 | if (proto == NULL) |
872 | asprintf(&proto, DEFAULT_PROTOCOL); | 872 | xasprintf(&proto, DEFAULT_PROTOCOL); |
873 | 873 | ||
874 | if ((strcmp(proto,"1") == 0) || (strcmp(proto, "2c")==0)) { /* snmpv1 or snmpv2c */ | 874 | if ((strcmp(proto,"1") == 0) || (strcmp(proto, "2c")==0)) { /* snmpv1 or snmpv2c */ |
875 | numauthpriv = 2; | 875 | numauthpriv = 2; |
@@ -879,7 +879,7 @@ validate_arguments () | |||
879 | } | 879 | } |
880 | else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */ | 880 | else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */ |
881 | if (seclevel == NULL) | 881 | if (seclevel == NULL) |
882 | asprintf(&seclevel, "noAuthNoPriv"); | 882 | xasprintf(&seclevel, "noAuthNoPriv"); |
883 | 883 | ||
884 | if (strcmp(seclevel, "noAuthNoPriv") == 0) { | 884 | if (strcmp(seclevel, "noAuthNoPriv") == 0) { |
885 | numauthpriv = 2; | 885 | numauthpriv = 2; |
@@ -892,7 +892,7 @@ validate_arguments () | |||
892 | } | 892 | } |
893 | 893 | ||
894 | if (authproto == NULL ) | 894 | if (authproto == NULL ) |
895 | asprintf(&authproto, DEFAULT_AUTH_PROTOCOL); | 895 | xasprintf(&authproto, DEFAULT_AUTH_PROTOCOL); |
896 | 896 | ||
897 | if (secname == NULL) | 897 | if (secname == NULL) |
898 | die(STATE_UNKNOWN, _("Required parameter: %s\n"), "secname"); | 898 | die(STATE_UNKNOWN, _("Required parameter: %s\n"), "secname"); |
@@ -913,7 +913,7 @@ validate_arguments () | |||
913 | authpriv[7] = strdup (authpasswd); | 913 | authpriv[7] = strdup (authpasswd); |
914 | } else if ( strcmp(seclevel, "authPriv") == 0 ) { | 914 | } else if ( strcmp(seclevel, "authPriv") == 0 ) { |
915 | if (privproto == NULL ) | 915 | if (privproto == NULL ) |
916 | asprintf(&privproto, DEFAULT_PRIV_PROTOCOL); | 916 | xasprintf(&privproto, DEFAULT_PRIV_PROTOCOL); |
917 | 917 | ||
918 | if (privpasswd == NULL) | 918 | if (privpasswd == NULL) |
919 | die(STATE_UNKNOWN, _("Required parameter: %s\n"), "privpasswd"); | 919 | die(STATE_UNKNOWN, _("Required parameter: %s\n"), "privpasswd"); |