summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-03-30 23:30:51 +0200
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2025-03-30 23:30:51 +0200
commita4cf2e79f75dce3828be21726f10c755f652f710 (patch)
treee6b72e1453a026917e67030334de16c407ccbb1d
parentc4fd34ed7966a197e596f3e766f58423fe9c5ddc (diff)
downloadmonitoring-plugins-a4cf2e79f75dce3828be21726f10c755f652f710.tar.gz
Remove cool, comfy c23 functionality for some dirty old hacks
-rw-r--r--plugins/check_disk.c42
-rw-r--r--plugins/check_disk.d/utils_disk.c2
-rw-r--r--plugins/check_disk.d/utils_disk.h38
3 files changed, 50 insertions, 32 deletions
diff --git a/plugins/check_disk.c b/plugins/check_disk.c
index ddb9ee49..ac3933a6 100644
--- a/plugins/check_disk.c
+++ b/plugins/check_disk.c
@@ -96,6 +96,22 @@ static void print_help(void);
96 96
97static int verbose = 0; 97static int verbose = 0;
98 98
99// This would not be necessary in C23!!
100const byte_unit Bytes_Factor = 1;
101const byte_unit KibiBytes_factor = 1024;
102const byte_unit MebiBytes_factor = 1048576;
103const byte_unit GibiBytes_factor = 1073741824;
104const byte_unit TebiBytes_factor = 1099511627776;
105const byte_unit PebiBytes_factor = 1125899906842624;
106const byte_unit ExbiBytes_factor = 1152921504606846976;
107const byte_unit KiloBytes_factor = 1000;
108const byte_unit MegaBytes_factor = 1000000;
109const byte_unit GigaBytes_factor = 1000000000;
110const byte_unit TeraBytes_factor = 1000000000000;
111const byte_unit PetaBytes_factor = 1000000000000000;
112const byte_unit ExaBytes_factor = 1000000000000000000;
113
114
99int main(int argc, char **argv) { 115int main(int argc, char **argv) {
100 setlocale(LC_ALL, ""); 116 setlocale(LC_ALL, "");
101 bindtextdomain(PACKAGE, LOCALEDIR); 117 bindtextdomain(PACKAGE, LOCALEDIR);
@@ -409,7 +425,7 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
409 425
410 bool path_selected = false; 426 bool path_selected = false;
411 char *group = NULL; 427 char *group = NULL;
412 byte_unit unit = MebiBytes; 428 byte_unit unit = MebiBytes_factor;
413 429
414 result.config.mount_list = read_file_system_list(false); 430 result.config.mount_list = read_file_system_list(false);
415 431
@@ -494,25 +510,25 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
494 break; 510 break;
495 case 'u': 511 case 'u':
496 if (!strcasecmp(optarg, "bytes")) { 512 if (!strcasecmp(optarg, "bytes")) {
497 unit = Bytes; 513 unit = Bytes_Factor;
498 } else if (!strcmp(optarg, "KiB")) { 514 } else if (!strcmp(optarg, "KiB")) {
499 unit = KibiBytes; 515 unit = KibiBytes_factor;
500 } else if (!strcmp(optarg, "kB")) { 516 } else if (!strcmp(optarg, "kB")) {
501 unit = KiloBytes; 517 unit = KiloBytes_factor;
502 } else if (!strcmp(optarg, "MiB")) { 518 } else if (!strcmp(optarg, "MiB")) {
503 unit = MebiBytes; 519 unit = MebiBytes_factor;
504 } else if (!strcmp(optarg, "MB")) { 520 } else if (!strcmp(optarg, "MB")) {
505 unit = MegaBytes; 521 unit = MegaBytes_factor;
506 } else if (!strcmp(optarg, "GiB")) { 522 } else if (!strcmp(optarg, "GiB")) {
507 unit = GibiBytes; 523 unit = MegaBytes_factor;
508 } else if (!strcmp(optarg, "GB")) { 524 } else if (!strcmp(optarg, "GB")) {
509 unit = GigaBytes; 525 unit = MegaBytes_factor;
510 } else if (!strcmp(optarg, "TiB")) { 526 } else if (!strcmp(optarg, "TiB")) {
511 unit = TebiBytes; 527 unit = MegaBytes_factor;
512 } else if (!strcmp(optarg, "TB")) { 528 } else if (!strcmp(optarg, "TB")) {
513 unit = TeraBytes; 529 unit = MegaBytes_factor;
514 } else if (!strcmp(optarg, "PiB")) { 530 } else if (!strcmp(optarg, "PiB")) {
515 unit = PebiBytes; 531 unit = MegaBytes_factor;
516 } else if (!strcmp(optarg, "PB")) { 532 } else if (!strcmp(optarg, "PB")) {
517 unit = PetaBytes; 533 unit = PetaBytes;
518 } else { 534 } else {
@@ -520,10 +536,10 @@ check_disk_config_wrapper process_arguments(int argc, char **argv) {
520 } 536 }
521 break; 537 break;
522 case 'k': 538 case 'k':
523 unit = KibiBytes; 539 unit = KibiBytes_factor;
524 break; 540 break;
525 case 'm': 541 case 'm':
526 unit = MebiBytes; 542 unit = MebiBytes_factor;
527 break; 543 break;
528 case display_unit_index: 544 case display_unit_index:
529 if (!strcasecmp(optarg, "bytes")) { 545 if (!strcasecmp(optarg, "bytes")) {
diff --git a/plugins/check_disk.d/utils_disk.c b/plugins/check_disk.d/utils_disk.c
index 3986a8a8..a78b4eae 100644
--- a/plugins/check_disk.d/utils_disk.c
+++ b/plugins/check_disk.d/utils_disk.c
@@ -180,7 +180,7 @@ check_disk_config check_disk_config_init() {
180 return tmp; 180 return tmp;
181} 181}
182 182
183char *get_unit_string(byte_unit unit) { 183char *get_unit_string(byte_unit_enum unit) {
184 switch (unit) { 184 switch (unit) {
185 case Bytes: 185 case Bytes:
186 return "Bytes"; 186 return "Bytes";
diff --git a/plugins/check_disk.d/utils_disk.h b/plugins/check_disk.d/utils_disk.h
index a66453ea..1f574695 100644
--- a/plugins/check_disk.d/utils_disk.h
+++ b/plugins/check_disk.d/utils_disk.h
@@ -8,22 +8,24 @@
8#include "regex.h" 8#include "regex.h"
9#include <stdint.h> 9#include <stdint.h>
10 10
11typedef enum : unsigned long { 11typedef unsigned long long byte_unit;
12 Humanized = 0, 12
13 Bytes = 1, 13typedef enum {
14 KibiBytes = 1024, 14 Humanized,
15 MebiBytes = 1024 * KibiBytes, 15 Bytes,
16 GibiBytes = 1024 * MebiBytes, 16 KibiBytes,
17 TebiBytes = 1024 * GibiBytes, 17 MebiBytes,
18 PebiBytes = 1024 * TebiBytes, 18 GibiBytes,
19 ExbiBytes = 1024 * PebiBytes, 19 TebiBytes,
20 KiloBytes = 1000, 20 PebiBytes,
21 MegaBytes = 1000 * KiloBytes, 21 ExbiBytes,
22 GigaBytes = 1000 * MegaBytes, 22 KiloBytes,
23 TeraBytes = 1000 * GigaBytes, 23 MegaBytes,
24 PetaBytes = 1000 * TeraBytes, 24 GigaBytes,
25 ExaBytes = 1000 * PetaBytes 25 TeraBytes,
26} byte_unit; 26 PetaBytes,
27 ExaBytes,
28} byte_unit_enum;
27 29
28typedef struct name_list string_list; 30typedef struct name_list string_list;
29struct name_list { 31struct name_list {
@@ -120,7 +122,7 @@ typedef struct {
120 struct mount_entry *mount_list; 122 struct mount_entry *mount_list;
121 struct name_list *seen; 123 struct name_list *seen;
122 124
123 byte_unit display_unit; 125 byte_unit_enum display_unit;
124 // byte_unit unit; 126 // byte_unit unit;
125 127
126 bool output_format_is_set; 128 bool output_format_is_set;
@@ -149,7 +151,7 @@ measurement_unit create_measurement_unit_from_filesystem(parameter_list_elem fil
149int search_parameter_list(parameter_list_elem *list, const char *name); 151int search_parameter_list(parameter_list_elem *list, const char *name);
150bool np_regex_match_mount_entry(struct mount_entry *, regex_t *); 152bool np_regex_match_mount_entry(struct mount_entry *, regex_t *);
151 153
152char *get_unit_string(byte_unit); 154char *get_unit_string(byte_unit_enum);
153check_disk_config check_disk_config_init(); 155check_disk_config check_disk_config_init();
154 156
155char *humanize_byte_value(uintmax_t value, bool use_si_units); 157char *humanize_byte_value(uintmax_t value, bool use_si_units);