diff options
author | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-10-15 16:21:31 (GMT) |
---|---|---|
committer | RincewindsHat <12514511+RincewindsHat@users.noreply.github.com> | 2023-10-15 16:21:31 (GMT) |
commit | ddbabaa3b659bed9dcf5c5a2bfc430fb816277c7 (patch) | |
tree | 0d0980d41f95385cc0137ec86e7a1cea0065e04c | |
parent | 4b9d90f31c700298185aa4c7b20fe1c5e8bf19c2 (diff) | |
download | monitoring-plugins-ddbabaa3b659bed9dcf5c5a2bfc430fb816277c7.tar.gz |
Replace all old school booleans in lib witch C99 onesrefs/pull/1937/head
-rw-r--r-- | lib/extra_opts.c | 9 | ||||
-rw-r--r-- | lib/parse_ini.c | 7 | ||||
-rw-r--r-- | lib/tests/test_disk.c | 20 | ||||
-rw-r--r-- | lib/tests/test_utils.c | 76 | ||||
-rw-r--r-- | lib/utils_base.c | 51 | ||||
-rw-r--r-- | lib/utils_base.h | 4 | ||||
-rw-r--r-- | lib/utils_disk.c | 43 | ||||
-rw-r--r-- | lib/utils_disk.h | 10 |
8 files changed, 104 insertions, 116 deletions
diff --git a/lib/extra_opts.c b/lib/extra_opts.c index 89b1056..b9843eb 100644 --- a/lib/extra_opts.c +++ b/lib/extra_opts.c | |||
@@ -26,15 +26,14 @@ | |||
26 | #include "extra_opts.h" | 26 | #include "extra_opts.h" |
27 | 27 | ||
28 | /* FIXME: copied from utils.h; we should move a bunch of libs! */ | 28 | /* FIXME: copied from utils.h; we should move a bunch of libs! */ |
29 | int | 29 | bool is_option2 (char *str) |
30 | is_option2 (char *str) | ||
31 | { | 30 | { |
32 | if (!str) | 31 | if (!str) |
33 | return FALSE; | 32 | return false; |
34 | else if (strspn (str, "-") == 1 || strspn (str, "-") == 2) | 33 | else if (strspn (str, "-") == 1 || strspn (str, "-") == 2) |
35 | return TRUE; | 34 | return true; |
36 | else | 35 | else |
37 | return FALSE; | 36 | return false; |
38 | } | 37 | } |
39 | 38 | ||
40 | /* this is the externally visible function used by plugins */ | 39 | /* this is the externally visible function used by plugins */ |
diff --git a/lib/parse_ini.c b/lib/parse_ini.c index 57e6094..0cc864a 100644 --- a/lib/parse_ini.c +++ b/lib/parse_ini.c | |||
@@ -131,7 +131,7 @@ np_get_defaults(const char *locator, const char *default_section) | |||
131 | if (inifile == NULL) | 131 | if (inifile == NULL) |
132 | die(STATE_UNKNOWN, _("Can't read config file: %s\n"), | 132 | die(STATE_UNKNOWN, _("Can't read config file: %s\n"), |
133 | strerror(errno)); | 133 | strerror(errno)); |
134 | if (read_defaults(inifile, i.stanza, &defaults) == FALSE) | 134 | if (!read_defaults(inifile, i.stanza, &defaults)) |
135 | die(STATE_UNKNOWN, | 135 | die(STATE_UNKNOWN, |
136 | _("Invalid section '%s' in config file '%s'\n"), i.stanza, | 136 | _("Invalid section '%s' in config file '%s'\n"), i.stanza, |
137 | i.file); | 137 | i.file); |
@@ -157,7 +157,8 @@ np_get_defaults(const char *locator, const char *default_section) | |||
157 | static int | 157 | static int |
158 | read_defaults(FILE *f, const char *stanza, np_arg_list **opts) | 158 | read_defaults(FILE *f, const char *stanza, np_arg_list **opts) |
159 | { | 159 | { |
160 | int c, status = FALSE; | 160 | int c = 0; |
161 | bool status = false; | ||
161 | size_t i, stanza_len; | 162 | size_t i, stanza_len; |
162 | enum { NOSTANZA, WRONGSTANZA, RIGHTSTANZA } stanzastate = NOSTANZA; | 163 | enum { NOSTANZA, WRONGSTANZA, RIGHTSTANZA } stanzastate = NOSTANZA; |
163 | 164 | ||
@@ -219,7 +220,7 @@ read_defaults(FILE *f, const char *stanza, np_arg_list **opts) | |||
219 | die(STATE_UNKNOWN, "%s\n", | 220 | die(STATE_UNKNOWN, "%s\n", |
220 | _("Config file error")); | 221 | _("Config file error")); |
221 | } | 222 | } |
222 | status = TRUE; | 223 | status = true; |
223 | break; | 224 | break; |
224 | } | 225 | } |
225 | break; | 226 | break; |
diff --git a/lib/tests/test_disk.c b/lib/tests/test_disk.c index 269d20b..e283fe2 100644 --- a/lib/tests/test_disk.c +++ b/lib/tests/test_disk.c | |||
@@ -44,19 +44,19 @@ main (int argc, char **argv) | |||
44 | 44 | ||
45 | plan_tests(33); | 45 | plan_tests(33); |
46 | 46 | ||
47 | ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list"); | 47 | ok( np_find_name(exclude_filesystem, "/var/log") == false, "/var/log not in list"); |
48 | np_add_name(&exclude_filesystem, "/var/log"); | 48 | np_add_name(&exclude_filesystem, "/var/log"); |
49 | ok( np_find_name(exclude_filesystem, "/var/log") == TRUE, "is in list now"); | 49 | ok( np_find_name(exclude_filesystem, "/var/log") == true, "is in list now"); |
50 | ok( np_find_name(exclude_filesystem, "/home") == FALSE, "/home not in list"); | 50 | ok( np_find_name(exclude_filesystem, "/home") == false, "/home not in list"); |
51 | np_add_name(&exclude_filesystem, "/home"); | 51 | np_add_name(&exclude_filesystem, "/home"); |
52 | ok( np_find_name(exclude_filesystem, "/home") == TRUE, "is in list now"); | 52 | ok( np_find_name(exclude_filesystem, "/home") == true, "is in list now"); |
53 | ok( np_find_name(exclude_filesystem, "/var/log") == TRUE, "/var/log still in list"); | 53 | ok( np_find_name(exclude_filesystem, "/var/log") == true, "/var/log still in list"); |
54 | 54 | ||
55 | ok( np_find_name(exclude_fstype, "iso9660") == FALSE, "iso9660 not in list"); | 55 | ok( np_find_name(exclude_fstype, "iso9660") == false, "iso9660 not in list"); |
56 | np_add_name(&exclude_fstype, "iso9660"); | 56 | np_add_name(&exclude_fstype, "iso9660"); |
57 | ok( np_find_name(exclude_fstype, "iso9660") == TRUE, "is in list now"); | 57 | ok( np_find_name(exclude_fstype, "iso9660") == true, "is in list now"); |
58 | 58 | ||
59 | ok( np_find_name(exclude_filesystem, "iso9660") == FALSE, "Make sure no clashing in variables"); | 59 | ok( np_find_name(exclude_filesystem, "iso9660") == false, "Make sure no clashing in variables"); |
60 | 60 | ||
61 | /* | 61 | /* |
62 | for (temp_name = exclude_filesystem; temp_name; temp_name = temp_name->next) { | 62 | for (temp_name = exclude_filesystem; temp_name; temp_name = temp_name->next) { |
@@ -120,7 +120,7 @@ main (int argc, char **argv) | |||
120 | np_add_parameter(&paths, "/home/tonvoon"); | 120 | np_add_parameter(&paths, "/home/tonvoon"); |
121 | np_add_parameter(&paths, "/dev/c2t0d0s0"); | 121 | np_add_parameter(&paths, "/dev/c2t0d0s0"); |
122 | 122 | ||
123 | np_set_best_match(paths, dummy_mount_list, FALSE); | 123 | np_set_best_match(paths, dummy_mount_list, false); |
124 | for (p = paths; p; p = p->name_next) { | 124 | for (p = paths; p; p = p->name_next) { |
125 | struct mount_entry *temp_me; | 125 | struct mount_entry *temp_me; |
126 | temp_me = p->best_match; | 126 | temp_me = p->best_match; |
@@ -144,7 +144,7 @@ main (int argc, char **argv) | |||
144 | np_add_parameter(&paths, "/home/tonvoon"); | 144 | np_add_parameter(&paths, "/home/tonvoon"); |
145 | np_add_parameter(&paths, "/home"); | 145 | np_add_parameter(&paths, "/home"); |
146 | 146 | ||
147 | np_set_best_match(paths, dummy_mount_list, TRUE); | 147 | np_set_best_match(paths, dummy_mount_list, true); |
148 | for (p = paths; p; p = p->name_next) { | 148 | for (p = paths; p; p = p->name_next) { |
149 | if (! strcmp(p->name, "/home/groups")) { | 149 | if (! strcmp(p->name, "/home/groups")) { |
150 | ok( ! p->best_match , "/home/groups correctly not found"); | 150 | ok( ! p->best_match , "/home/groups correctly not found"); |
diff --git a/lib/tests/test_utils.c b/lib/tests/test_utils.c index a109e3f..01afacd 100644 --- a/lib/tests/test_utils.c +++ b/lib/tests/test_utils.c | |||
@@ -62,99 +62,99 @@ main (int argc, char **argv) | |||
62 | range = parse_range_string("6"); | 62 | range = parse_range_string("6"); |
63 | ok( range != NULL, "'6' is valid range"); | 63 | ok( range != NULL, "'6' is valid range"); |
64 | ok( range->start == 0, "Start correct"); | 64 | ok( range->start == 0, "Start correct"); |
65 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | 65 | ok( range->start_infinity == false, "Not using negative infinity"); |
66 | ok( range->end == 6, "End correct"); | 66 | ok( range->end == 6, "End correct"); |
67 | ok( range->end_infinity == FALSE, "Not using infinity"); | 67 | ok( range->end_infinity == false, "Not using infinity"); |
68 | free(range); | 68 | free(range); |
69 | 69 | ||
70 | range = parse_range_string("1:12%%"); | 70 | range = parse_range_string("1:12%%"); |
71 | ok( range != NULL, "'1:12%%' is valid - percentages are ignored"); | 71 | ok( range != NULL, "'1:12%%' is valid - percentages are ignored"); |
72 | ok( range->start == 1, "Start correct"); | 72 | ok( range->start == 1, "Start correct"); |
73 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | 73 | ok( range->start_infinity == false, "Not using negative infinity"); |
74 | ok( range->end == 12, "End correct"); | 74 | ok( range->end == 12, "End correct"); |
75 | ok( range->end_infinity == FALSE, "Not using infinity"); | 75 | ok( range->end_infinity == false, "Not using infinity"); |
76 | free(range); | 76 | free(range); |
77 | 77 | ||
78 | range = parse_range_string("-7:23"); | 78 | range = parse_range_string("-7:23"); |
79 | ok( range != NULL, "'-7:23' is valid range"); | 79 | ok( range != NULL, "'-7:23' is valid range"); |
80 | ok( range->start == -7, "Start correct"); | 80 | ok( range->start == -7, "Start correct"); |
81 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | 81 | ok( range->start_infinity == false, "Not using negative infinity"); |
82 | ok( range->end == 23, "End correct"); | 82 | ok( range->end == 23, "End correct"); |
83 | ok( range->end_infinity == FALSE, "Not using infinity"); | 83 | ok( range->end_infinity == false, "Not using infinity"); |
84 | free(range); | 84 | free(range); |
85 | 85 | ||
86 | range = parse_range_string(":5.75"); | 86 | range = parse_range_string(":5.75"); |
87 | ok( range != NULL, "':5.75' is valid range"); | 87 | ok( range != NULL, "':5.75' is valid range"); |
88 | ok( range->start == 0, "Start correct"); | 88 | ok( range->start == 0, "Start correct"); |
89 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | 89 | ok( range->start_infinity == false, "Not using negative infinity"); |
90 | ok( range->end == 5.75, "End correct"); | 90 | ok( range->end == 5.75, "End correct"); |
91 | ok( range->end_infinity == FALSE, "Not using infinity"); | 91 | ok( range->end_infinity == false, "Not using infinity"); |
92 | free(range); | 92 | free(range); |
93 | 93 | ||
94 | range = parse_range_string("~:-95.99"); | 94 | range = parse_range_string("~:-95.99"); |
95 | ok( range != NULL, "~:-95.99' is valid range"); | 95 | ok( range != NULL, "~:-95.99' is valid range"); |
96 | ok( range->start_infinity == TRUE, "Using negative infinity"); | 96 | ok( range->start_infinity == true, "Using negative infinity"); |
97 | ok( range->end == -95.99, "End correct (with rounding errors)"); | 97 | ok( range->end == -95.99, "End correct (with rounding errors)"); |
98 | ok( range->end_infinity == FALSE, "Not using infinity"); | 98 | ok( range->end_infinity == false, "Not using infinity"); |
99 | free(range); | 99 | free(range); |
100 | 100 | ||
101 | range = parse_range_string("12345678901234567890:"); | 101 | range = parse_range_string("12345678901234567890:"); |
102 | temp = atof("12345678901234567890"); /* Can't just use this because number too large */ | 102 | temp = atof("12345678901234567890"); /* Can't just use this because number too large */ |
103 | ok( range != NULL, "'12345678901234567890:' is valid range"); | 103 | ok( range != NULL, "'12345678901234567890:' is valid range"); |
104 | ok( range->start == temp, "Start correct"); | 104 | ok( range->start == temp, "Start correct"); |
105 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | 105 | ok( range->start_infinity == false, "Not using negative infinity"); |
106 | ok( range->end_infinity == TRUE, "Using infinity"); | 106 | ok( range->end_infinity == true, "Using infinity"); |
107 | /* Cannot do a "-1" on temp, as it appears to be same value */ | 107 | /* Cannot do a "-1" on temp, as it appears to be same value */ |
108 | ok( check_range(temp/1.1, range) == TRUE, "12345678901234567890/1.1 - alert"); | 108 | ok( check_range(temp/1.1, range) == true, "12345678901234567890/1.1 - alert"); |
109 | ok( check_range(temp, range) == FALSE, "12345678901234567890 - no alert"); | 109 | ok( check_range(temp, range) == false, "12345678901234567890 - no alert"); |
110 | ok( check_range(temp*2, range) == FALSE, "12345678901234567890*2 - no alert"); | 110 | ok( check_range(temp*2, range) == false, "12345678901234567890*2 - no alert"); |
111 | free(range); | 111 | free(range); |
112 | 112 | ||
113 | range = parse_range_string("~:0"); | 113 | range = parse_range_string("~:0"); |
114 | ok( range != NULL, "'~:0' is valid range"); | 114 | ok( range != NULL, "'~:0' is valid range"); |
115 | ok( range->start_infinity == TRUE, "Using negative infinity"); | 115 | ok( range->start_infinity == true, "Using negative infinity"); |
116 | ok( range->end == 0, "End correct"); | 116 | ok( range->end == 0, "End correct"); |
117 | ok( range->end_infinity == FALSE, "Not using infinity"); | 117 | ok( range->end_infinity == false, "Not using infinity"); |
118 | ok( range->alert_on == OUTSIDE, "Will alert on outside of this range"); | 118 | ok( range->alert_on == OUTSIDE, "Will alert on outside of this range"); |
119 | ok( check_range(0.5, range) == TRUE, "0.5 - alert"); | 119 | ok( check_range(0.5, range) == true, "0.5 - alert"); |
120 | ok( check_range(-10, range) == FALSE, "-10 - no alert"); | 120 | ok( check_range(-10, range) == false, "-10 - no alert"); |
121 | ok( check_range(0, range) == FALSE, "0 - no alert"); | 121 | ok( check_range(0, range) == false, "0 - no alert"); |
122 | free(range); | 122 | free(range); |
123 | 123 | ||
124 | range = parse_range_string("@0:657.8210567"); | 124 | range = parse_range_string("@0:657.8210567"); |
125 | ok( range != 0, "@0:657.8210567' is a valid range"); | 125 | ok( range != 0, "@0:657.8210567' is a valid range"); |
126 | ok( range->start == 0, "Start correct"); | 126 | ok( range->start == 0, "Start correct"); |
127 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | 127 | ok( range->start_infinity == false, "Not using negative infinity"); |
128 | ok( range->end == 657.8210567, "End correct"); | 128 | ok( range->end == 657.8210567, "End correct"); |
129 | ok( range->end_infinity == FALSE, "Not using infinity"); | 129 | ok( range->end_infinity == false, "Not using infinity"); |
130 | ok( range->alert_on == INSIDE, "Will alert on inside of this range" ); | 130 | ok( range->alert_on == INSIDE, "Will alert on inside of this range" ); |
131 | ok( check_range(32.88, range) == TRUE, "32.88 - alert"); | 131 | ok( check_range(32.88, range) == true, "32.88 - alert"); |
132 | ok( check_range(-2, range) == FALSE, "-2 - no alert"); | 132 | ok( check_range(-2, range) == false, "-2 - no alert"); |
133 | ok( check_range(657.8210567, range) == TRUE, "657.8210567 - alert"); | 133 | ok( check_range(657.8210567, range) == true, "657.8210567 - alert"); |
134 | ok( check_range(0, range) == TRUE, "0 - alert"); | 134 | ok( check_range(0, range) == true, "0 - alert"); |
135 | free(range); | 135 | free(range); |
136 | 136 | ||
137 | range = parse_range_string("@1:1"); | 137 | range = parse_range_string("@1:1"); |
138 | ok( range != NULL, "'@1:1' is a valid range"); | 138 | ok( range != NULL, "'@1:1' is a valid range"); |
139 | ok( range->start == 1, "Start correct"); | 139 | ok( range->start == 1, "Start correct"); |
140 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | 140 | ok( range->start_infinity == false, "Not using negative infinity"); |
141 | ok( range->end == 1, "End correct"); | 141 | ok( range->end == 1, "End correct"); |
142 | ok( range->end_infinity == FALSE, "Not using infinity"); | 142 | ok( range->end_infinity == false, "Not using infinity"); |
143 | ok( range->alert_on == INSIDE, "Will alert on inside of this range" ); | 143 | ok( range->alert_on == INSIDE, "Will alert on inside of this range" ); |
144 | ok( check_range(0.5, range) == FALSE, "0.5 - no alert"); | 144 | ok( check_range(0.5, range) == false, "0.5 - no alert"); |
145 | ok( check_range(1, range) == TRUE, "1 - alert"); | 145 | ok( check_range(1, range) == true, "1 - alert"); |
146 | ok( check_range(5.2, range) == FALSE, "5.2 - no alert"); | 146 | ok( check_range(5.2, range) == false, "5.2 - no alert"); |
147 | free(range); | 147 | free(range); |
148 | 148 | ||
149 | range = parse_range_string("1:1"); | 149 | range = parse_range_string("1:1"); |
150 | ok( range != NULL, "'1:1' is a valid range"); | 150 | ok( range != NULL, "'1:1' is a valid range"); |
151 | ok( range->start == 1, "Start correct"); | 151 | ok( range->start == 1, "Start correct"); |
152 | ok( range->start_infinity == FALSE, "Not using negative infinity"); | 152 | ok( range->start_infinity == false, "Not using negative infinity"); |
153 | ok( range->end == 1, "End correct"); | 153 | ok( range->end == 1, "End correct"); |
154 | ok( range->end_infinity == FALSE, "Not using infinity"); | 154 | ok( range->end_infinity == false, "Not using infinity"); |
155 | ok( check_range(0.5, range) == TRUE, "0.5 - alert"); | 155 | ok( check_range(0.5, range) == true, "0.5 - alert"); |
156 | ok( check_range(1, range) == FALSE, "1 - no alert"); | 156 | ok( check_range(1, range) == false, "1 - no alert"); |
157 | ok( check_range(5.2, range) == TRUE, "5.2 - alert"); | 157 | ok( check_range(5.2, range) == true, "5.2 - alert"); |
158 | free(range); | 158 | free(range); |
159 | 159 | ||
160 | range = parse_range_string("2:1"); | 160 | range = parse_range_string("2:1"); |
@@ -459,7 +459,7 @@ main (int argc, char **argv) | |||
459 | 459 | ||
460 | ok(this_monitoring_plugin==NULL, "Free'd this_monitoring_plugin"); | 460 | ok(this_monitoring_plugin==NULL, "Free'd this_monitoring_plugin"); |
461 | 461 | ||
462 | ok(mp_suid() == FALSE, "Test aren't suid"); | 462 | ok(mp_suid() == false, "Test aren't suid"); |
463 | 463 | ||
464 | /* base states with random case */ | 464 | /* base states with random case */ |
465 | char *states[] = { | 465 | char *states[] = { |
diff --git a/lib/utils_base.c b/lib/utils_base.c index eabcd7e..3c7221c 100644 --- a/lib/utils_base.c +++ b/lib/utils_base.c | |||
@@ -40,7 +40,7 @@ monitoring_plugin *this_monitoring_plugin=NULL; | |||
40 | unsigned int timeout_state = STATE_CRITICAL; | 40 | unsigned int timeout_state = STATE_CRITICAL; |
41 | unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT; | 41 | unsigned int timeout_interval = DEFAULT_SOCKET_TIMEOUT; |
42 | 42 | ||
43 | int _np_state_read_file(FILE *); | 43 | bool _np_state_read_file(FILE *); |
44 | 44 | ||
45 | void np_init( char *plugin_name, int argc, char **argv ) { | 45 | void np_init( char *plugin_name, int argc, char **argv ) { |
46 | if (this_monitoring_plugin==NULL) { | 46 | if (this_monitoring_plugin==NULL) { |
@@ -105,12 +105,12 @@ die (int result, const char *fmt, ...) | |||
105 | 105 | ||
106 | void set_range_start (range *this, double value) { | 106 | void set_range_start (range *this, double value) { |
107 | this->start = value; | 107 | this->start = value; |
108 | this->start_infinity = FALSE; | 108 | this->start_infinity = false; |
109 | } | 109 | } |
110 | 110 | ||
111 | void set_range_end (range *this, double value) { | 111 | void set_range_end (range *this, double value) { |
112 | this->end = value; | 112 | this->end = value; |
113 | this->end_infinity = FALSE; | 113 | this->end_infinity = false; |
114 | } | 114 | } |
115 | 115 | ||
116 | range | 116 | range |
@@ -124,9 +124,9 @@ range | |||
124 | 124 | ||
125 | /* Set defaults */ | 125 | /* Set defaults */ |
126 | temp_range->start = 0; | 126 | temp_range->start = 0; |
127 | temp_range->start_infinity = FALSE; | 127 | temp_range->start_infinity = false; |
128 | temp_range->end = 0; | 128 | temp_range->end = 0; |
129 | temp_range->end_infinity = TRUE; | 129 | temp_range->end_infinity = true; |
130 | temp_range->alert_on = OUTSIDE; | 130 | temp_range->alert_on = OUTSIDE; |
131 | temp_range->text = strdup(str); | 131 | temp_range->text = strdup(str); |
132 | 132 | ||
@@ -138,7 +138,7 @@ range | |||
138 | end_str = index(str, ':'); | 138 | end_str = index(str, ':'); |
139 | if (end_str != NULL) { | 139 | if (end_str != NULL) { |
140 | if (str[0] == '~') { | 140 | if (str[0] == '~') { |
141 | temp_range->start_infinity = TRUE; | 141 | temp_range->start_infinity = true; |
142 | } else { | 142 | } else { |
143 | start = strtod(str, NULL); /* Will stop at the ':' */ | 143 | start = strtod(str, NULL); /* Will stop at the ':' */ |
144 | set_range_start(temp_range, start); | 144 | set_range_start(temp_range, start); |
@@ -152,8 +152,8 @@ range | |||
152 | set_range_end(temp_range, end); | 152 | set_range_end(temp_range, end); |
153 | } | 153 | } |
154 | 154 | ||
155 | if (temp_range->start_infinity == TRUE || | 155 | if (temp_range->start_infinity == true || |
156 | temp_range->end_infinity == TRUE || | 156 | temp_range->end_infinity == true || |
157 | temp_range->start <= temp_range->end) { | 157 | temp_range->start <= temp_range->end) { |
158 | return temp_range; | 158 | return temp_range; |
159 | } | 159 | } |
@@ -223,31 +223,30 @@ void print_thresholds(const char *threshold_name, thresholds *my_threshold) { | |||
223 | printf("\n"); | 223 | printf("\n"); |
224 | } | 224 | } |
225 | 225 | ||
226 | /* Returns TRUE if alert should be raised based on the range */ | 226 | /* Returns true if alert should be raised based on the range */ |
227 | int | 227 | bool check_range(double value, range *my_range) |
228 | check_range(double value, range *my_range) | ||
229 | { | 228 | { |
230 | int no = FALSE; | 229 | bool no = false; |
231 | int yes = TRUE; | 230 | bool yes = true; |
232 | 231 | ||
233 | if (my_range->alert_on == INSIDE) { | 232 | if (my_range->alert_on == INSIDE) { |
234 | no = TRUE; | 233 | no = true; |
235 | yes = FALSE; | 234 | yes = false; |
236 | } | 235 | } |
237 | 236 | ||
238 | if (my_range->end_infinity == FALSE && my_range->start_infinity == FALSE) { | 237 | if (my_range->end_infinity == false && my_range->start_infinity == false) { |
239 | if ((my_range->start <= value) && (value <= my_range->end)) { | 238 | if ((my_range->start <= value) && (value <= my_range->end)) { |
240 | return no; | 239 | return no; |
241 | } else { | 240 | } else { |
242 | return yes; | 241 | return yes; |
243 | } | 242 | } |
244 | } else if (my_range->start_infinity == FALSE && my_range->end_infinity == TRUE) { | 243 | } else if (my_range->start_infinity == false && my_range->end_infinity == true) { |
245 | if (my_range->start <= value) { | 244 | if (my_range->start <= value) { |
246 | return no; | 245 | return no; |
247 | } else { | 246 | } else { |
248 | return yes; | 247 | return yes; |
249 | } | 248 | } |
250 | } else if (my_range->start_infinity == TRUE && my_range->end_infinity == FALSE) { | 249 | } else if (my_range->start_infinity == true && my_range->end_infinity == false) { |
251 | if (value <= my_range->end) { | 250 | if (value <= my_range->end) { |
252 | return no; | 251 | return no; |
253 | } else { | 252 | } else { |
@@ -263,12 +262,12 @@ int | |||
263 | get_status(double value, thresholds *my_thresholds) | 262 | get_status(double value, thresholds *my_thresholds) |
264 | { | 263 | { |
265 | if (my_thresholds->critical != NULL) { | 264 | if (my_thresholds->critical != NULL) { |
266 | if (check_range(value, my_thresholds->critical) == TRUE) { | 265 | if (check_range(value, my_thresholds->critical) == true) { |
267 | return STATE_CRITICAL; | 266 | return STATE_CRITICAL; |
268 | } | 267 | } |
269 | } | 268 | } |
270 | if (my_thresholds->warning != NULL) { | 269 | if (my_thresholds->warning != NULL) { |
271 | if (check_range(value, my_thresholds->warning) == TRUE) { | 270 | if (check_range(value, my_thresholds->warning) == true) { |
272 | return STATE_WARNING; | 271 | return STATE_WARNING; |
273 | } | 272 | } |
274 | } | 273 | } |
@@ -465,7 +464,7 @@ char* _np_state_calculate_location_prefix(){ | |||
465 | 464 | ||
466 | /* Do not allow passing MP_STATE_PATH in setuid plugins | 465 | /* Do not allow passing MP_STATE_PATH in setuid plugins |
467 | * for security reasons */ | 466 | * for security reasons */ |
468 | if (mp_suid() == FALSE) { | 467 | if (!mp_suid()) { |
469 | env_dir = getenv("MP_STATE_PATH"); | 468 | env_dir = getenv("MP_STATE_PATH"); |
470 | if(env_dir && env_dir[0] != '\0') | 469 | if(env_dir && env_dir[0] != '\0') |
471 | return env_dir; | 470 | return env_dir; |
@@ -541,7 +540,7 @@ void np_enable_state(char *keyname, int expected_data_version) { | |||
541 | state_data *np_state_read() { | 540 | state_data *np_state_read() { |
542 | state_data *this_state_data=NULL; | 541 | state_data *this_state_data=NULL; |
543 | FILE *statefile; | 542 | FILE *statefile; |
544 | int rc = FALSE; | 543 | bool rc = false; |
545 | 544 | ||
546 | if(this_monitoring_plugin==NULL) | 545 | if(this_monitoring_plugin==NULL) |
547 | die(STATE_UNKNOWN, _("This requires np_init to be called")); | 546 | die(STATE_UNKNOWN, _("This requires np_init to be called")); |
@@ -563,7 +562,7 @@ state_data *np_state_read() { | |||
563 | fclose(statefile); | 562 | fclose(statefile); |
564 | } | 563 | } |
565 | 564 | ||
566 | if(rc==FALSE) { | 565 | if(!rc) { |
567 | _cleanup_state_data(); | 566 | _cleanup_state_data(); |
568 | } | 567 | } |
569 | 568 | ||
@@ -573,8 +572,8 @@ state_data *np_state_read() { | |||
573 | /* | 572 | /* |
574 | * Read the state file | 573 | * Read the state file |
575 | */ | 574 | */ |
576 | int _np_state_read_file(FILE *f) { | 575 | bool _np_state_read_file(FILE *f) { |
577 | int status=FALSE; | 576 | bool status = false; |
578 | size_t pos; | 577 | size_t pos; |
579 | char *line; | 578 | char *line; |
580 | int i; | 579 | int i; |
@@ -628,7 +627,7 @@ int _np_state_read_file(FILE *f) { | |||
628 | if(this_monitoring_plugin->state->state_data->data==NULL) | 627 | if(this_monitoring_plugin->state->state_data->data==NULL) |
629 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); | 628 | die(STATE_UNKNOWN, _("Cannot execute strdup: %s"), strerror(errno)); |
630 | expected=STATE_DATA_END; | 629 | expected=STATE_DATA_END; |
631 | status=TRUE; | 630 | status=true; |
632 | break; | 631 | break; |
633 | case STATE_DATA_END: | 632 | case STATE_DATA_END: |
634 | ; | 633 | ; |
diff --git a/lib/utils_base.h b/lib/utils_base.h index 9abf595..80b8743 100644 --- a/lib/utils_base.h +++ b/lib/utils_base.h | |||
@@ -21,7 +21,7 @@ | |||
21 | 21 | ||
22 | typedef struct range_struct { | 22 | typedef struct range_struct { |
23 | double start; | 23 | double start; |
24 | int start_infinity; /* FALSE (default) or TRUE */ | 24 | bool start_infinity; |
25 | double end; | 25 | double end; |
26 | int end_infinity; | 26 | int end_infinity; |
27 | int alert_on; /* OUTSIDE (default) or INSIDE */ | 27 | int alert_on; /* OUTSIDE (default) or INSIDE */ |
@@ -61,7 +61,7 @@ range *parse_range_string (char *); | |||
61 | int _set_thresholds(thresholds **, char *, char *); | 61 | int _set_thresholds(thresholds **, char *, char *); |
62 | void set_thresholds(thresholds **, char *, char *); | 62 | void set_thresholds(thresholds **, char *, char *); |
63 | void print_thresholds(const char *, thresholds *); | 63 | void print_thresholds(const char *, thresholds *); |
64 | int check_range(double, range *); | 64 | bool check_range(double, range *); |
65 | int get_status(double, thresholds *); | 65 | int get_status(double, thresholds *); |
66 | 66 | ||
67 | /* Handle timeouts */ | 67 | /* Handle timeouts */ |
diff --git a/lib/utils_disk.c b/lib/utils_disk.c index 5e95aef..483be06 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c | |||
@@ -170,9 +170,7 @@ np_find_parameter(struct parameter_list *list, const char *name) | |||
170 | return NULL; | 170 | return NULL; |
171 | } | 171 | } |
172 | 172 | ||
173 | void | 173 | void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, bool exact) { |
174 | np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact) | ||
175 | { | ||
176 | struct parameter_list *d; | 174 | struct parameter_list *d; |
177 | for (d = desired; d; d= d->name_next) { | 175 | for (d = desired; d; d= d->name_next) { |
178 | if (! d->best_match) { | 176 | if (! d->best_match) { |
@@ -195,9 +193,9 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list | |||
195 | if (! best_match) { | 193 | if (! best_match) { |
196 | for (me = mount_list; me; me = me->me_next) { | 194 | for (me = mount_list; me; me = me->me_next) { |
197 | size_t len = strlen (me->me_mountdir); | 195 | size_t len = strlen (me->me_mountdir); |
198 | if ((exact == FALSE && (best_match_len <= len && len <= name_len && | 196 | if ((!exact && (best_match_len <= len && len <= name_len && |
199 | (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0))) | 197 | (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0))) |
200 | || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0)) | 198 | || (exact && strcmp(me->me_mountdir, d->name)==0)) |
201 | { | 199 | { |
202 | if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) { | 200 | if (get_fs_usage(me->me_mountdir, me->me_devname, &fsp) >= 0) { |
203 | best_match = me; | 201 | best_match = me; |
@@ -216,27 +214,23 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list | |||
216 | } | 214 | } |
217 | } | 215 | } |
218 | 216 | ||
219 | /* Returns TRUE if name is in list */ | 217 | /* Returns true if name is in list */ |
220 | int | 218 | bool np_find_name (struct name_list *list, const char *name) { |
221 | np_find_name (struct name_list *list, const char *name) | ||
222 | { | ||
223 | const struct name_list *n; | 219 | const struct name_list *n; |
224 | 220 | ||
225 | if (list == NULL || name == NULL) { | 221 | if (list == NULL || name == NULL) { |
226 | return FALSE; | 222 | return false; |
227 | } | 223 | } |
228 | for (n = list; n; n = n->next) { | 224 | for (n = list; n; n = n->next) { |
229 | if (!strcmp(name, n->name)) { | 225 | if (!strcmp(name, n->name)) { |
230 | return TRUE; | 226 | return true; |
231 | } | 227 | } |
232 | } | 228 | } |
233 | return FALSE; | 229 | return false; |
234 | } | 230 | } |
235 | 231 | ||
236 | /* Returns TRUE if name is in list */ | 232 | /* Returns true if name is in list */ |
237 | bool | 233 | bool np_find_regmatch (struct regex_list *list, const char *name) { |
238 | np_find_regmatch (struct regex_list *list, const char *name) | ||
239 | { | ||
240 | int len; | 234 | int len; |
241 | regmatch_t m; | 235 | regmatch_t m; |
242 | 236 | ||
@@ -257,25 +251,20 @@ np_find_regmatch (struct regex_list *list, const char *name) | |||
257 | return false; | 251 | return false; |
258 | } | 252 | } |
259 | 253 | ||
260 | int | 254 | bool np_seen_name(struct name_list *list, const char *name) { |
261 | np_seen_name(struct name_list *list, const char *name) | ||
262 | { | ||
263 | const struct name_list *s; | 255 | const struct name_list *s; |
264 | for (s = list; s; s=s->next) { | 256 | for (s = list; s; s=s->next) { |
265 | if (!strcmp(s->name, name)) { | 257 | if (!strcmp(s->name, name)) { |
266 | return TRUE; | 258 | return true; |
267 | } | 259 | } |
268 | } | 260 | } |
269 | return FALSE; | 261 | return false; |
270 | } | 262 | } |
271 | 263 | ||
272 | int | 264 | bool np_regex_match_mount_entry (struct mount_entry* me, regex_t* re) { |
273 | np_regex_match_mount_entry (struct mount_entry* me, regex_t* re) | ||
274 | { | ||
275 | if (regexec(re, me->me_devname, (size_t) 0, NULL, 0) == 0 || | 265 | if (regexec(re, me->me_devname, (size_t) 0, NULL, 0) == 0 || |
276 | regexec(re, me->me_mountdir, (size_t) 0, NULL, 0) == 0 ) { | 266 | regexec(re, me->me_mountdir, (size_t) 0, NULL, 0) == 0 ) { |
277 | return TRUE; | 267 | return true; |
278 | } else { | ||
279 | return FALSE; | ||
280 | } | 268 | } |
269 | return false; | ||
281 | } | 270 | } |
diff --git a/lib/utils_disk.h b/lib/utils_disk.h index 6b83ac7..5b2caf2 100644 --- a/lib/utils_disk.h +++ b/lib/utils_disk.h | |||
@@ -39,14 +39,14 @@ struct parameter_list | |||
39 | }; | 39 | }; |
40 | 40 | ||
41 | void np_add_name (struct name_list **list, const char *name); | 41 | void np_add_name (struct name_list **list, const char *name); |
42 | int np_find_name (struct name_list *list, const char *name); | 42 | bool np_find_name (struct name_list *list, const char *name); |
43 | int np_seen_name (struct name_list *list, const char *name); | 43 | bool np_seen_name (struct name_list *list, const char *name); |
44 | int np_add_regex (struct regex_list **list, const char *regex, int cflags); | 44 | int np_add_regex (struct regex_list **list, const char *regex, int cflags); |
45 | bool np_find_regmatch (struct regex_list *list, const char *name); | 45 | bool np_find_regmatch (struct regex_list *list, const char *name); |
46 | struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); | 46 | struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); |
47 | struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name); | 47 | struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name); |
48 | struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev); | 48 | struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev); |
49 | 49 | ||
50 | int search_parameter_list (struct parameter_list *list, const char *name); | 50 | int search_parameter_list (struct parameter_list *list, const char *name); |
51 | void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact); | 51 | void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, bool exact); |
52 | int np_regex_match_mount_entry (struct mount_entry* me, regex_t* re); | 52 | bool np_regex_match_mount_entry (struct mount_entry* me, regex_t* re); |