diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/extra_opts.c | 2 | ||||
| -rw-r--r-- | lib/extra_opts.h | 2 | ||||
| -rw-r--r-- | lib/output.c | 8 | ||||
| -rw-r--r-- | lib/parse_ini.c | 10 | ||||
| -rw-r--r-- | lib/perfdata.c | 18 | ||||
| -rw-r--r-- | lib/perfdata.h | 3 | ||||
| -rw-r--r-- | lib/states.h | 2 | ||||
| -rw-r--r-- | lib/utils_cmd.c | 12 | ||||
| -rw-r--r-- | lib/utils_cmd.h | 4 |
9 files changed, 32 insertions, 29 deletions
diff --git a/lib/extra_opts.c b/lib/extra_opts.c index 3fe69014..fa64d650 100644 --- a/lib/extra_opts.c +++ b/lib/extra_opts.c | |||
| @@ -120,7 +120,7 @@ char **np_extra_opts(int *argc, char **argv, const char *plugin_name) { | |||
| 120 | } | 120 | } |
| 121 | ea1 = ea_tmp = NULL; | 121 | ea1 = ea_tmp = NULL; |
| 122 | } | 122 | } |
| 123 | } /* lather, rince, repeat */ | 123 | } /* lather, rinse, repeat */ |
| 124 | 124 | ||
| 125 | if (ea_num == (size_t)*argc && extra_args == NULL) { | 125 | if (ea_num == (size_t)*argc && extra_args == NULL) { |
| 126 | /* No extra-opts */ | 126 | /* No extra-opts */ |
diff --git a/lib/extra_opts.h b/lib/extra_opts.h index 3f64360f..3c2d5eb1 100644 --- a/lib/extra_opts.h +++ b/lib/extra_opts.h | |||
| @@ -8,7 +8,7 @@ | |||
| 8 | 8 | ||
| 9 | /* np_extra_opts: Process the --extra-opts arguments and create a new argument | 9 | /* np_extra_opts: Process the --extra-opts arguments and create a new argument |
| 10 | * array with ini-processed and argument-passed arguments together. The | 10 | * array with ini-processed and argument-passed arguments together. The |
| 11 | * ini-procesed arguments always come first (in the order of --extra-opts | 11 | * ini-processed arguments always come first (in the order of --extra-opts |
| 12 | * arguments). If no --extra-opts arguments are provided or returned nothing | 12 | * arguments). If no --extra-opts arguments are provided or returned nothing |
| 13 | * it returns **argv otherwise the new array is returned. --extra-opts are | 13 | * it returns **argv otherwise the new array is returned. --extra-opts are |
| 14 | * always removed from **argv. The original pointers from **argv are kept in | 14 | * always removed from **argv. The original pointers from **argv are kept in |
diff --git a/lib/output.c b/lib/output.c index f283969f..d1a8d3b9 100644 --- a/lib/output.c +++ b/lib/output.c | |||
| @@ -42,7 +42,7 @@ static inline char *fmt_subcheck_perfdata(mp_subcheck check) { | |||
| 42 | 42 | ||
| 43 | while (subchecks != NULL) { | 43 | while (subchecks != NULL) { |
| 44 | if (added > 0) { | 44 | if (added > 0) { |
| 45 | added = asprintf(&result, "%s%s", result, fmt_subcheck_perfdata(subchecks->subcheck)); | 45 | added = asprintf(&result, "%s %s", result, fmt_subcheck_perfdata(subchecks->subcheck)); |
| 46 | } else { | 46 | } else { |
| 47 | // TODO free previous result here? | 47 | // TODO free previous result here? |
| 48 | added = asprintf(&result, "%s", fmt_subcheck_perfdata(subchecks->subcheck)); | 48 | added = asprintf(&result, "%s", fmt_subcheck_perfdata(subchecks->subcheck)); |
| @@ -165,7 +165,7 @@ int mp_add_subcheck_to_subcheck(mp_subcheck check[static 1], mp_subcheck subchec | |||
| 165 | void mp_add_summary(mp_check check[static 1], char *summary) { check->summary = summary; } | 165 | void mp_add_summary(mp_check check[static 1], char *summary) { check->summary = summary; } |
| 166 | 166 | ||
| 167 | /* | 167 | /* |
| 168 | * Generate the summary string of a mp_check object based on it's subchecks | 168 | * Generate the summary string of a mp_check object based on its subchecks |
| 169 | */ | 169 | */ |
| 170 | char *get_subcheck_summary(mp_check check) { | 170 | char *get_subcheck_summary(mp_check check) { |
| 171 | mp_subcheck_list *subchecks = check.subchecks; | 171 | mp_subcheck_list *subchecks = check.subchecks; |
| @@ -175,7 +175,7 @@ char *get_subcheck_summary(mp_check check) { | |||
| 175 | unsigned int critical = 0; | 175 | unsigned int critical = 0; |
| 176 | unsigned int unknown = 0; | 176 | unsigned int unknown = 0; |
| 177 | while (subchecks != NULL) { | 177 | while (subchecks != NULL) { |
| 178 | switch (subchecks->subcheck.state) { | 178 | switch (mp_compute_subcheck_state(subchecks->subcheck)) { |
| 179 | case STATE_OK: | 179 | case STATE_OK: |
| 180 | ok++; | 180 | ok++; |
| 181 | break; | 181 | break; |
| @@ -243,7 +243,7 @@ mp_state_enum mp_compute_check_state(const mp_check check) { | |||
| 243 | } | 243 | } |
| 244 | 244 | ||
| 245 | /* | 245 | /* |
| 246 | * Generate the result state of a mp_check object based on it's own state and it's subchecks states | 246 | * Generate the result state of a mp_check object based on its own state and its subchecks states |
| 247 | */ | 247 | */ |
| 248 | mp_state_enum mp_eval_check_default(const mp_check check) { | 248 | mp_state_enum mp_eval_check_default(const mp_check check) { |
| 249 | assert(check.subchecks != NULL); // a mp_check without subchecks is invalid, die here | 249 | assert(check.subchecks != NULL); // a mp_check without subchecks is invalid, die here |
diff --git a/lib/parse_ini.c b/lib/parse_ini.c index db337622..8a54af58 100644 --- a/lib/parse_ini.c +++ b/lib/parse_ini.c | |||
| @@ -173,7 +173,7 @@ static bool read_defaults(FILE *defaults_file, const char *stanza, np_arg_list * | |||
| 173 | continue; | 173 | continue; |
| 174 | } | 174 | } |
| 175 | switch (current_char) { | 175 | switch (current_char) { |
| 176 | /* globble up comment lines */ | 176 | /* gobble up comment lines */ |
| 177 | case ';': | 177 | case ';': |
| 178 | case '#': | 178 | case '#': |
| 179 | GOBBLE_TO(defaults_file, current_char, '\n'); | 179 | GOBBLE_TO(defaults_file, current_char, '\n'); |
| @@ -352,15 +352,17 @@ static int add_option(FILE *filePointer, np_arg_list **optlst) { | |||
| 352 | optnew->next = NULL; | 352 | optnew->next = NULL; |
| 353 | 353 | ||
| 354 | read_pos = 0; | 354 | read_pos = 0; |
| 355 | optnew->arg = malloc(cfg_len + 1); | 355 | size_t arg_length = cfg_len + 1; |
| 356 | optnew->arg = malloc(arg_length); | ||
| 356 | /* 1-character params needs only one dash */ | 357 | /* 1-character params needs only one dash */ |
| 357 | if (opt_len == 1) { | 358 | if (opt_len == 1) { |
| 358 | strncpy(&optnew->arg[read_pos], "-", 1); | 359 | strncpy(&optnew->arg[read_pos], "-", arg_length); |
| 359 | read_pos += 1; | 360 | read_pos += 1; |
| 360 | } else { | 361 | } else { |
| 361 | strncpy(&optnew->arg[read_pos], "--", 2); | 362 | strncpy(&optnew->arg[read_pos], "--", arg_length); |
| 362 | read_pos += 2; | 363 | read_pos += 2; |
| 363 | } | 364 | } |
| 365 | |||
| 364 | strncpy(&optnew->arg[read_pos], optptr, opt_len); | 366 | strncpy(&optnew->arg[read_pos], optptr, opt_len); |
| 365 | read_pos += opt_len; | 367 | read_pos += opt_len; |
| 366 | if (value) { | 368 | if (value) { |
diff --git a/lib/perfdata.c b/lib/perfdata.c index 2930a8bc..f4eaf843 100644 --- a/lib/perfdata.c +++ b/lib/perfdata.c | |||
| @@ -37,9 +37,9 @@ char *pd_to_string(mp_perfdata pd) { | |||
| 37 | if (strchr(pd.label, '\'') == NULL) { | 37 | if (strchr(pd.label, '\'') == NULL) { |
| 38 | asprintf(&result, "'%s'=", pd.label); | 38 | asprintf(&result, "'%s'=", pd.label); |
| 39 | } else { | 39 | } else { |
| 40 | // we have a illegal single quote in the string | 40 | // we have an illegal single quote in the string |
| 41 | // replace it silently instead of complaining | 41 | // replace it silently instead of complaining |
| 42 | for (char *ptr = pd.label; *ptr == '\0'; ptr++) { | 42 | for (char *ptr = pd.label; *ptr != '\0'; ptr++) { |
| 43 | if (*ptr == '\'') { | 43 | if (*ptr == '\'') { |
| 44 | *ptr = '_'; | 44 | *ptr = '_'; |
| 45 | } | 45 | } |
| @@ -393,7 +393,7 @@ mp_range_parsed mp_parse_range_string(const char *input) { | |||
| 393 | 393 | ||
| 394 | mp_range_parsed result = { | 394 | mp_range_parsed result = { |
| 395 | .range = mp_range_init(), | 395 | .range = mp_range_init(), |
| 396 | .error = MP_PARSING_SUCCES, | 396 | .error = MP_PARSING_SUCCESS, |
| 397 | }; | 397 | }; |
| 398 | 398 | ||
| 399 | if (input[0] == '@') { | 399 | if (input[0] == '@') { |
| @@ -436,7 +436,7 @@ mp_range_parsed mp_parse_range_string(const char *input) { | |||
| 436 | result.range.start_infinity = false; | 436 | result.range.start_infinity = false; |
| 437 | perfdata_value_parser_wrapper parsed_pd = parse_pd_value(input); | 437 | perfdata_value_parser_wrapper parsed_pd = parse_pd_value(input); |
| 438 | 438 | ||
| 439 | if (parsed_pd.error != MP_PARSING_SUCCES) { | 439 | if (parsed_pd.error != MP_PARSING_SUCCESS) { |
| 440 | result.error = parsed_pd.error; | 440 | result.error = parsed_pd.error; |
| 441 | free(working_copy); | 441 | free(working_copy); |
| 442 | return result; | 442 | return result; |
| @@ -457,7 +457,7 @@ mp_range_parsed mp_parse_range_string(const char *input) { | |||
| 457 | } else { | 457 | } else { |
| 458 | perfdata_value_parser_wrapper parsed_pd = parse_pd_value(input); | 458 | perfdata_value_parser_wrapper parsed_pd = parse_pd_value(input); |
| 459 | 459 | ||
| 460 | if (parsed_pd.error != MP_PARSING_SUCCES) { | 460 | if (parsed_pd.error != MP_PARSING_SUCCESS) { |
| 461 | result.error = parsed_pd.error; | 461 | result.error = parsed_pd.error; |
| 462 | return result; | 462 | return result; |
| 463 | } | 463 | } |
| @@ -470,7 +470,7 @@ mp_range_parsed mp_parse_range_string(const char *input) { | |||
| 470 | 470 | ||
| 471 | double_parser_wrapper parse_double(const char *input) { | 471 | double_parser_wrapper parse_double(const char *input) { |
| 472 | double_parser_wrapper result = { | 472 | double_parser_wrapper result = { |
| 473 | .error = MP_PARSING_SUCCES, | 473 | .error = MP_PARSING_SUCCESS, |
| 474 | }; | 474 | }; |
| 475 | 475 | ||
| 476 | if (input == NULL) { | 476 | if (input == NULL) { |
| @@ -501,7 +501,7 @@ double_parser_wrapper parse_double(const char *input) { | |||
| 501 | 501 | ||
| 502 | integer_parser_wrapper parse_integer(const char *input) { | 502 | integer_parser_wrapper parse_integer(const char *input) { |
| 503 | integer_parser_wrapper result = { | 503 | integer_parser_wrapper result = { |
| 504 | .error = MP_PARSING_SUCCES, | 504 | .error = MP_PARSING_SUCCESS, |
| 505 | }; | 505 | }; |
| 506 | 506 | ||
| 507 | if (input == NULL) { | 507 | if (input == NULL) { |
| @@ -548,7 +548,7 @@ perfdata_value_parser_wrapper parse_pd_value(const char *input) { | |||
| 548 | // try integer first | 548 | // try integer first |
| 549 | integer_parser_wrapper tmp_int = parse_integer(input); | 549 | integer_parser_wrapper tmp_int = parse_integer(input); |
| 550 | 550 | ||
| 551 | if (tmp_int.error == MP_PARSING_SUCCES) { | 551 | if (tmp_int.error == MP_PARSING_SUCCESS) { |
| 552 | perfdata_value_parser_wrapper result = { | 552 | perfdata_value_parser_wrapper result = { |
| 553 | .error = tmp_int.error, | 553 | .error = tmp_int.error, |
| 554 | .value = tmp_int.value, | 554 | .value = tmp_int.value, |
| @@ -558,7 +558,7 @@ perfdata_value_parser_wrapper parse_pd_value(const char *input) { | |||
| 558 | 558 | ||
| 559 | double_parser_wrapper tmp_double = parse_double(input); | 559 | double_parser_wrapper tmp_double = parse_double(input); |
| 560 | perfdata_value_parser_wrapper result = {}; | 560 | perfdata_value_parser_wrapper result = {}; |
| 561 | if (tmp_double.error == MP_PARSING_SUCCES) { | 561 | if (tmp_double.error == MP_PARSING_SUCCESS) { |
| 562 | result.error = tmp_double.error; | 562 | result.error = tmp_double.error; |
| 563 | result.value = tmp_double.value; | 563 | result.value = tmp_double.value; |
| 564 | } else { | 564 | } else { |
diff --git a/lib/perfdata.h b/lib/perfdata.h index e51ef5fd..d7e5670a 100644 --- a/lib/perfdata.h +++ b/lib/perfdata.h | |||
| @@ -111,7 +111,8 @@ mp_range mp_range_set_end(mp_range, mp_perfdata_value); | |||
| 111 | */ | 111 | */ |
| 112 | 112 | ||
| 113 | typedef enum { | 113 | typedef enum { |
| 114 | MP_PARSING_SUCCES = 0, | 114 | MP_PARSING_SUCCESS = 0, |
| 115 | MP_PARSING_SUCCES = MP_PARSING_SUCCESS, | ||
| 115 | MP_PARSING_FAILURE, | 116 | MP_PARSING_FAILURE, |
| 116 | MP_RANGE_PARSING_FAILURE, | 117 | MP_RANGE_PARSING_FAILURE, |
| 117 | MP_RANGE_PARSING_UNDERFLOW, | 118 | MP_RANGE_PARSING_UNDERFLOW, |
diff --git a/lib/states.h b/lib/states.h index 4a170caa..43926f0c 100644 --- a/lib/states.h +++ b/lib/states.h | |||
| @@ -45,7 +45,7 @@ static inline mp_state_enum max_state(mp_state_enum a, mp_state_enum b) { | |||
| 45 | * STATE_OK < STATE_DEPENDENT < STATE_UNKNOWN < STATE_WARNING < STATE_CRITICAL | 45 | * STATE_OK < STATE_DEPENDENT < STATE_UNKNOWN < STATE_WARNING < STATE_CRITICAL |
| 46 | * | 46 | * |
| 47 | * The main difference between max_state_alt and max_state it that it doesn't | 47 | * The main difference between max_state_alt and max_state it that it doesn't |
| 48 | * allow setting a default to UNKNOWN. It will instead prioritixe any valid | 48 | * allow setting a default to UNKNOWN. It will instead prioritize any valid |
| 49 | * non-OK state. | 49 | * non-OK state. |
| 50 | ****************************************************************************/ | 50 | ****************************************************************************/ |
| 51 | 51 | ||
diff --git a/lib/utils_cmd.c b/lib/utils_cmd.c index 42c81793..23d42168 100644 --- a/lib/utils_cmd.c +++ b/lib/utils_cmd.c | |||
| @@ -489,14 +489,14 @@ cmd_run_result cmd_run2(const char *cmd_string, int flags) { | |||
| 489 | cmd_run_result result = { | 489 | cmd_run_result result = { |
| 490 | .cmd_error_code = 0, | 490 | .cmd_error_code = 0, |
| 491 | .error_code = 0, | 491 | .error_code = 0, |
| 492 | .stderr = | 492 | .err = |
| 493 | { | 493 | { |
| 494 | .buf = NULL, | 494 | .buf = NULL, |
| 495 | .buflen = 0, | 495 | .buflen = 0, |
| 496 | .line = NULL, | 496 | .line = NULL, |
| 497 | .lines = 0, | 497 | .lines = 0, |
| 498 | }, | 498 | }, |
| 499 | .stdout = | 499 | .out = |
| 500 | { | 500 | { |
| 501 | .buf = NULL, | 501 | .buf = NULL, |
| 502 | .buflen = 0, | 502 | .buflen = 0, |
| @@ -581,14 +581,14 @@ cmd_run_result cmd_run_array2(char *const *cmd, int flags) { | |||
| 581 | cmd_run_result result = { | 581 | cmd_run_result result = { |
| 582 | .cmd_error_code = 0, | 582 | .cmd_error_code = 0, |
| 583 | .error_code = 0, | 583 | .error_code = 0, |
| 584 | .stderr = | 584 | .err = |
| 585 | { | 585 | { |
| 586 | .buf = NULL, | 586 | .buf = NULL, |
| 587 | .buflen = 0, | 587 | .buflen = 0, |
| 588 | .line = NULL, | 588 | .line = NULL, |
| 589 | .lines = 0, | 589 | .lines = 0, |
| 590 | }, | 590 | }, |
| 591 | .stdout = | 591 | .out = |
| 592 | { | 592 | { |
| 593 | .buf = NULL, | 593 | .buf = NULL, |
| 594 | .buflen = 0, | 594 | .buflen = 0, |
| @@ -610,9 +610,9 @@ cmd_run_result cmd_run_array2(char *const *cmd, int flags) { | |||
| 610 | int pfd_err[2] = {cmd_open_result.stderr_pipe_fd[0], cmd_open_result.stderr_pipe_fd[1]}; | 610 | int pfd_err[2] = {cmd_open_result.stderr_pipe_fd[0], cmd_open_result.stderr_pipe_fd[1]}; |
| 611 | 611 | ||
| 612 | int_cmd_fetch_output2 tmp_stdout = _cmd_fetch_output2(pfd_out[0], flags); | 612 | int_cmd_fetch_output2 tmp_stdout = _cmd_fetch_output2(pfd_out[0], flags); |
| 613 | result.stdout = tmp_stdout.output_container; | 613 | result.out = tmp_stdout.output_container; |
| 614 | int_cmd_fetch_output2 tmp_stderr = _cmd_fetch_output2(pfd_err[0], flags); | 614 | int_cmd_fetch_output2 tmp_stderr = _cmd_fetch_output2(pfd_err[0], flags); |
| 615 | result.stderr = tmp_stderr.output_container; | 615 | result.err = tmp_stderr.output_container; |
| 616 | 616 | ||
| 617 | result.cmd_error_code = _cmd_close(file_descriptor); | 617 | result.cmd_error_code = _cmd_close(file_descriptor); |
| 618 | return result; | 618 | return result; |
diff --git a/lib/utils_cmd.h b/lib/utils_cmd.h index d3a8f14f..04a624b8 100644 --- a/lib/utils_cmd.h +++ b/lib/utils_cmd.h | |||
| @@ -24,8 +24,8 @@ int cmd_file_read(const char *, output *, int); | |||
| 24 | typedef struct { | 24 | typedef struct { |
| 25 | int error_code; | 25 | int error_code; |
| 26 | int cmd_error_code; | 26 | int cmd_error_code; |
| 27 | output stdout; | 27 | output out; |
| 28 | output stderr; | 28 | output err; |
| 29 | } cmd_run_result; | 29 | } cmd_run_result; |
| 30 | cmd_run_result cmd_run2(const char *cmd, int flags); | 30 | cmd_run_result cmd_run2(const char *cmd, int flags); |
| 31 | cmd_run_result cmd_run_array2(char * const *cmd, int flags); | 31 | cmd_run_result cmd_run_array2(char * const *cmd, int flags); |
