[monitoring-plugins] lib/utils_cmd: Rename stdout, stderr in ...
Alvar Penning
git at monitoring-plugins.org
Wed Dec 17 17:20:13 CET 2025
Module: monitoring-plugins
Branch: master
Commit: 6ce11bc44f5fe2344083a94175a1667ca02e016c
Author: Alvar Penning <post at 0x21.biz>
Date: Thu Dec 11 10:53:07 2025 +0100
URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=6ce11bc4
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
---
lib/utils_cmd.c | 12 ++++++------
lib/utils_cmd.h | 4 ++--
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) {
cmd_run_result result = {
.cmd_error_code = 0,
.error_code = 0,
- .stderr =
+ .err =
{
.buf = NULL,
.buflen = 0,
.line = NULL,
.lines = 0,
},
- .stdout =
+ .out =
{
.buf = NULL,
.buflen = 0,
@@ -581,14 +581,14 @@ cmd_run_result cmd_run_array2(char *const *cmd, int flags) {
cmd_run_result result = {
.cmd_error_code = 0,
.error_code = 0,
- .stderr =
+ .err =
{
.buf = NULL,
.buflen = 0,
.line = NULL,
.lines = 0,
},
- .stdout =
+ .out =
{
.buf = NULL,
.buflen = 0,
@@ -610,9 +610,9 @@ cmd_run_result cmd_run_array2(char *const *cmd, int flags) {
int pfd_err[2] = {cmd_open_result.stderr_pipe_fd[0], cmd_open_result.stderr_pipe_fd[1]};
int_cmd_fetch_output2 tmp_stdout = _cmd_fetch_output2(pfd_out[0], flags);
- result.stdout = tmp_stdout.output_container;
+ result.out = tmp_stdout.output_container;
int_cmd_fetch_output2 tmp_stderr = _cmd_fetch_output2(pfd_err[0], flags);
- result.stderr = tmp_stderr.output_container;
+ result.err = tmp_stderr.output_container;
result.cmd_error_code = _cmd_close(file_descriptor);
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);
typedef struct {
int error_code;
int cmd_error_code;
- output stdout;
- output stderr;
+ output out;
+ output err;
} cmd_run_result;
cmd_run_result cmd_run2(const char *cmd, int flags);
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) {
if (child_result.cmd_error_code == 255 && config.unknown_timeout) {
mp_subcheck sc_ssh_execution = mp_subcheck_init();
xasprintf(&sc_ssh_execution.output, "SSH connection failed: %s",
- child_result.stderr.lines > 0 ? child_result.stderr.line[0]
+ child_result.err.lines > 0 ? child_result.err.line[0]
: "(no error output)");
sc_ssh_execution = mp_set_subcheck_state(sc_ssh_execution, STATE_UNKNOWN);
@@ -107,34 +107,34 @@ int main(int argc, char **argv) {
}
if (verbose) {
- for (size_t i = 0; i < child_result.stdout.lines; i++) {
- printf("stdout: %s\n", child_result.stdout.line[i]);
+ for (size_t i = 0; i < child_result.out.lines; i++) {
+ printf("stdout: %s\n", child_result.out.line[i]);
}
- for (size_t i = 0; i < child_result.stderr.lines; i++) {
- printf("stderr: %s\n", child_result.stderr.line[i]);
+ for (size_t i = 0; i < child_result.err.lines; i++) {
+ printf("stderr: %s\n", child_result.err.line[i]);
}
}
size_t skip_stdout = 0;
if (config.skip_stdout) { /* --skip-stdout specified without argument */
- skip_stdout = child_result.stdout.lines;
+ skip_stdout = child_result.out.lines;
} else {
skip_stdout = config.stdout_lines_to_ignore;
}
size_t skip_stderr = 0;
if (config.skip_stderr) { /* --skip-stderr specified without argument */
- skip_stderr = child_result.stderr.lines;
+ skip_stderr = child_result.err.lines;
} else {
skip_stderr = config.sterr_lines_to_ignore;
}
/* Allow UNKNOWN or WARNING state for (non-skipped) output found on stderr */
- if (child_result.stderr.lines > skip_stderr &&
+ if (child_result.err.lines > skip_stderr &&
(config.unknown_on_stderr || config.warn_on_stderr)) {
mp_subcheck sc_stderr = mp_subcheck_init();
xasprintf(&sc_stderr.output, "remote command execution failed: %s",
- child_result.stderr.line[skip_stderr]);
+ child_result.err.line[skip_stderr]);
if (config.unknown_on_stderr) {
sc_stderr = mp_set_subcheck_state(sc_stderr, STATE_UNKNOWN);
@@ -154,10 +154,10 @@ int main(int argc, char **argv) {
mp_subcheck sc_active_check = mp_subcheck_init();
xasprintf(&sc_active_check.output, "command stdout:");
- if (child_result.stdout.lines > skip_stdout) {
- for (size_t i = skip_stdout; i < child_result.stdout.lines; i++) {
+ if (child_result.out.lines > skip_stdout) {
+ for (size_t i = skip_stdout; i < child_result.out.lines; i++) {
xasprintf(&sc_active_check.output, "%s\n%s", sc_active_check.output,
- child_result.stdout.line[i]);
+ child_result.out.line[i]);
}
} else {
xasprintf(&sc_active_check.output, "remote command '%s' returned status %d",
@@ -209,10 +209,10 @@ int main(int argc, char **argv) {
char *status_text;
int cresult;
mp_subcheck sc_parse_passive = mp_subcheck_init();
- for (size_t i = skip_stdout; i < child_result.stdout.lines; i++) {
- status_text = child_result.stdout.line[i++];
- if (i == child_result.stdout.lines ||
- strstr(child_result.stdout.line[i], "STATUS CODE: ") == NULL) {
+ for (size_t i = skip_stdout; i < child_result.out.lines; i++) {
+ status_text = child_result.out.line[i++];
+ if (i == child_result.out.lines ||
+ strstr(child_result.out.line[i], "STATUS CODE: ") == NULL) {
sc_parse_passive = mp_set_subcheck_state(sc_parse_passive, STATE_UNKNOWN);
xasprintf(&sc_parse_passive.output, "failed to parse output");
@@ -221,7 +221,7 @@ int main(int argc, char **argv) {
}
if (config.service[commands] && status_text &&
- sscanf(child_result.stdout.line[i], "STATUS CODE: %d", &cresult) == 1) {
+ sscanf(child_result.out.line[i], "STATUS CODE: %d", &cresult) == 1) {
fprintf(output_file, "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n", (int)local_time,
config.host_shortname, config.service[commands++], cresult, status_text);
}
More information about the Commits
mailing list