summaryrefslogtreecommitdiffstats
path: root/lib/output.c
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-07-06 23:38:59 +0200
committerGitHub <noreply@github.com>2025-07-06 23:38:59 +0200
commit55c0bb748ec04354a5d63e95b3703fcec2cbd588 (patch)
treed8d831de150b3f09ada49f7a367b6d290626aedb /lib/output.c
parente63acdb83d9edcc8c1e244fc34043b4876b74f16 (diff)
parentb191a8a05543b22bf8e3255d74d358dd42ef1a89 (diff)
downloadmonitoring-plugins-master.tar.gz
Merge pull request #2109 from RincewindsHat/refactor/check_loadHEADmastercoverity/master
Refactor/check load
Diffstat (limited to 'lib/output.c')
-rw-r--r--lib/output.c37
1 files changed, 34 insertions, 3 deletions
diff --git a/lib/output.c b/lib/output.c
index b398c2ad..34ff7dab 100644
--- a/lib/output.c
+++ b/lib/output.c
@@ -368,9 +368,39 @@ static inline char *fmt_subcheck_output(mp_output_format output_format, mp_subch
368 mp_subcheck_list *subchecks = NULL; 368 mp_subcheck_list *subchecks = NULL;
369 369
370 switch (output_format) { 370 switch (output_format) {
371 case MP_FORMAT_MULTI_LINE: 371 case MP_FORMAT_MULTI_LINE: {
372 asprintf(&result, "%s\\_[%s] - %s", generate_indentation_string(indentation), 372 char *tmp_string = NULL;
373 state_text(mp_compute_subcheck_state(check)), check.output); 373 if ((tmp_string = strchr(check.output, '\n')) != NULL) {
374 // This is a multiline string, put the correct indentation in before proceeding
375 char *intermediate_string = "";
376 bool have_residual_chars = false;
377
378 while (tmp_string != NULL) {
379 *tmp_string = '\0';
380 asprintf(&intermediate_string, "%s%s\n%s", intermediate_string,check.output, generate_indentation_string(indentation+1)); // one more indentation to make it look better
381
382 if (*(tmp_string + 1) != '\0') {
383 check.output = tmp_string + 1;
384 have_residual_chars = true;
385 } else {
386 // Null after the \n, so this is the end
387 have_residual_chars = false;
388 break;
389 }
390
391 tmp_string = strchr(check.output, '\n');
392 }
393
394 // add the rest (if any)
395 if (have_residual_chars) {
396 char *tmp = check.output;
397 xasprintf(&check.output, "%s\n%s%s", intermediate_string, generate_indentation_string(indentation+1), tmp);
398 } else {
399 check.output = intermediate_string;
400 }
401 }
402 asprintf(&result, "%s\\_[%s] - %s", generate_indentation_string(indentation), state_text(mp_compute_subcheck_state(check)),
403 check.output);
374 404
375 subchecks = check.subchecks; 405 subchecks = check.subchecks;
376 406
@@ -380,6 +410,7 @@ static inline char *fmt_subcheck_output(mp_output_format output_format, mp_subch
380 subchecks = subchecks->next; 410 subchecks = subchecks->next;
381 } 411 }
382 return result; 412 return result;
413 }
383 default: 414 default:
384 die(STATE_UNKNOWN, "Invalid format"); 415 die(STATE_UNKNOWN, "Invalid format");
385 } 416 }