diff options
| author | Alvar Penning <post@0x21.biz> | 2025-12-11 10:53:07 +0100 |
|---|---|---|
| committer | Alvar Penning <post@0x21.biz> | 2025-12-11 21:05:49 +0100 |
| commit | 6ce11bc44f5fe2344083a94175a1667ca02e016c (patch) | |
| tree | 15af65d7c9023b1cded0ca0976915d3130d5e519 | |
| parent | b27bf07ebf518a719482c5c40372549f5a9a127a (diff) | |
| download | monitoring-plugins-6ce11bc44f5fe2344083a94175a1667ca02e016c.tar.gz | |
lib/utils_cmd: Rename stdout, stderr in cmd_run_result
On OpenBSD's "stdio.h", stdin, stdout, and stderr are not directly
FILE*, but #defines. Thus, naming the output struct fields stdout and
stderr resulted in compiler errors, after replacing the #define.
https://codeberg.org/OpenBSD/src/src/commit/a762189c5efbb2811f3c853bc0e5578fd5fb919d/include/stdio.h#L75-L77
| -rw-r--r-- | lib/utils_cmd.c | 12 | ||||
| -rw-r--r-- | lib/utils_cmd.h | 4 | ||||
| -rw-r--r-- | plugins/check_by_ssh.c | 34 |
3 files changed, 25 insertions, 25 deletions
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); |
diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c index df8907d9..7ffa0ded 100644 --- a/plugins/check_by_ssh.c +++ b/plugins/check_by_ssh.c | |||
| @@ -98,7 +98,7 @@ int main(int argc, char **argv) { | |||
| 98 | if (child_result.cmd_error_code == 255 && config.unknown_timeout) { | 98 | if (child_result.cmd_error_code == 255 && config.unknown_timeout) { |
| 99 | mp_subcheck sc_ssh_execution = mp_subcheck_init(); | 99 | mp_subcheck sc_ssh_execution = mp_subcheck_init(); |
| 100 | xasprintf(&sc_ssh_execution.output, "SSH connection failed: %s", | 100 | xasprintf(&sc_ssh_execution.output, "SSH connection failed: %s", |
| 101 | child_result.stderr.lines > 0 ? child_result.stderr.line[0] | 101 | child_result.err.lines > 0 ? child_result.err.line[0] |
| 102 | : "(no error output)"); | 102 | : "(no error output)"); |
| 103 | 103 | ||
| 104 | sc_ssh_execution = mp_set_subcheck_state(sc_ssh_execution, STATE_UNKNOWN); | 104 | sc_ssh_execution = mp_set_subcheck_state(sc_ssh_execution, STATE_UNKNOWN); |
| @@ -107,34 +107,34 @@ int main(int argc, char **argv) { | |||
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | if (verbose) { | 109 | if (verbose) { |
| 110 | for (size_t i = 0; i < child_result.stdout.lines; i++) { | 110 | for (size_t i = 0; i < child_result.out.lines; i++) { |
| 111 | printf("stdout: %s\n", child_result.stdout.line[i]); | 111 | printf("stdout: %s\n", child_result.out.line[i]); |
| 112 | } | 112 | } |
| 113 | for (size_t i = 0; i < child_result.stderr.lines; i++) { | 113 | for (size_t i = 0; i < child_result.err.lines; i++) { |
| 114 | printf("stderr: %s\n", child_result.stderr.line[i]); | 114 | printf("stderr: %s\n", child_result.err.line[i]); |
| 115 | } | 115 | } |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | size_t skip_stdout = 0; | 118 | size_t skip_stdout = 0; |
| 119 | if (config.skip_stdout) { /* --skip-stdout specified without argument */ | 119 | if (config.skip_stdout) { /* --skip-stdout specified without argument */ |
| 120 | skip_stdout = child_result.stdout.lines; | 120 | skip_stdout = child_result.out.lines; |
| 121 | } else { | 121 | } else { |
| 122 | skip_stdout = config.stdout_lines_to_ignore; | 122 | skip_stdout = config.stdout_lines_to_ignore; |
| 123 | } | 123 | } |
| 124 | 124 | ||
| 125 | size_t skip_stderr = 0; | 125 | size_t skip_stderr = 0; |
| 126 | if (config.skip_stderr) { /* --skip-stderr specified without argument */ | 126 | if (config.skip_stderr) { /* --skip-stderr specified without argument */ |
| 127 | skip_stderr = child_result.stderr.lines; | 127 | skip_stderr = child_result.err.lines; |
| 128 | } else { | 128 | } else { |
| 129 | skip_stderr = config.sterr_lines_to_ignore; | 129 | skip_stderr = config.sterr_lines_to_ignore; |
| 130 | } | 130 | } |
| 131 | 131 | ||
| 132 | /* Allow UNKNOWN or WARNING state for (non-skipped) output found on stderr */ | 132 | /* Allow UNKNOWN or WARNING state for (non-skipped) output found on stderr */ |
| 133 | if (child_result.stderr.lines > skip_stderr && | 133 | if (child_result.err.lines > skip_stderr && |
| 134 | (config.unknown_on_stderr || config.warn_on_stderr)) { | 134 | (config.unknown_on_stderr || config.warn_on_stderr)) { |
| 135 | mp_subcheck sc_stderr = mp_subcheck_init(); | 135 | mp_subcheck sc_stderr = mp_subcheck_init(); |
| 136 | xasprintf(&sc_stderr.output, "remote command execution failed: %s", | 136 | xasprintf(&sc_stderr.output, "remote command execution failed: %s", |
| 137 | child_result.stderr.line[skip_stderr]); | 137 | child_result.err.line[skip_stderr]); |
| 138 | 138 | ||
| 139 | if (config.unknown_on_stderr) { | 139 | if (config.unknown_on_stderr) { |
| 140 | sc_stderr = mp_set_subcheck_state(sc_stderr, STATE_UNKNOWN); | 140 | sc_stderr = mp_set_subcheck_state(sc_stderr, STATE_UNKNOWN); |
| @@ -154,10 +154,10 @@ int main(int argc, char **argv) { | |||
| 154 | mp_subcheck sc_active_check = mp_subcheck_init(); | 154 | mp_subcheck sc_active_check = mp_subcheck_init(); |
| 155 | xasprintf(&sc_active_check.output, "command stdout:"); | 155 | xasprintf(&sc_active_check.output, "command stdout:"); |
| 156 | 156 | ||
| 157 | if (child_result.stdout.lines > skip_stdout) { | 157 | if (child_result.out.lines > skip_stdout) { |
| 158 | for (size_t i = skip_stdout; i < child_result.stdout.lines; i++) { | 158 | for (size_t i = skip_stdout; i < child_result.out.lines; i++) { |
| 159 | xasprintf(&sc_active_check.output, "%s\n%s", sc_active_check.output, | 159 | xasprintf(&sc_active_check.output, "%s\n%s", sc_active_check.output, |
| 160 | child_result.stdout.line[i]); | 160 | child_result.out.line[i]); |
| 161 | } | 161 | } |
| 162 | } else { | 162 | } else { |
| 163 | xasprintf(&sc_active_check.output, "remote command '%s' returned status %d", | 163 | xasprintf(&sc_active_check.output, "remote command '%s' returned status %d", |
| @@ -209,10 +209,10 @@ int main(int argc, char **argv) { | |||
| 209 | char *status_text; | 209 | char *status_text; |
| 210 | int cresult; | 210 | int cresult; |
| 211 | mp_subcheck sc_parse_passive = mp_subcheck_init(); | 211 | mp_subcheck sc_parse_passive = mp_subcheck_init(); |
| 212 | for (size_t i = skip_stdout; i < child_result.stdout.lines; i++) { | 212 | for (size_t i = skip_stdout; i < child_result.out.lines; i++) { |
| 213 | status_text = child_result.stdout.line[i++]; | 213 | status_text = child_result.out.line[i++]; |
| 214 | if (i == child_result.stdout.lines || | 214 | if (i == child_result.out.lines || |
| 215 | strstr(child_result.stdout.line[i], "STATUS CODE: ") == NULL) { | 215 | strstr(child_result.out.line[i], "STATUS CODE: ") == NULL) { |
| 216 | 216 | ||
| 217 | sc_parse_passive = mp_set_subcheck_state(sc_parse_passive, STATE_UNKNOWN); | 217 | sc_parse_passive = mp_set_subcheck_state(sc_parse_passive, STATE_UNKNOWN); |
| 218 | xasprintf(&sc_parse_passive.output, "failed to parse output"); | 218 | xasprintf(&sc_parse_passive.output, "failed to parse output"); |
| @@ -221,7 +221,7 @@ int main(int argc, char **argv) { | |||
| 221 | } | 221 | } |
| 222 | 222 | ||
| 223 | if (config.service[commands] && status_text && | 223 | if (config.service[commands] && status_text && |
| 224 | sscanf(child_result.stdout.line[i], "STATUS CODE: %d", &cresult) == 1) { | 224 | sscanf(child_result.out.line[i], "STATUS CODE: %d", &cresult) == 1) { |
| 225 | fprintf(output_file, "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n", (int)local_time, | 225 | fprintf(output_file, "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n", (int)local_time, |
| 226 | config.host_shortname, config.service[commands++], cresult, status_text); | 226 | config.host_shortname, config.service[commands++], cresult, status_text); |
| 227 | } | 227 | } |
