diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2023-10-15 19:01:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-15 19:01:25 +0200 |
commit | fff1014d1323980d5e969f31a5a17132482422ac (patch) | |
tree | 0d0980d41f95385cc0137ec86e7a1cea0065e04c /lib/utils_disk.c | |
parent | b1801c10846283176622db21974fe5003602630d (diff) | |
parent | ddbabaa3b659bed9dcf5c5a2bfc430fb816277c7 (diff) | |
download | monitoring-plugins-fff1014.tar.gz |
Merge pull request #1937 from RincewindsHat/replace_booleans_in_lib
Replace old school booleans in lib
Diffstat (limited to 'lib/utils_disk.c')
-rw-r--r-- | lib/utils_disk.c | 66 |
1 files changed, 27 insertions, 39 deletions
diff --git a/lib/utils_disk.c b/lib/utils_disk.c index f5ac0b30..483be06d 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c | |||
@@ -1,29 +1,29 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Library for check_disk | 3 | * Library for check_disk |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 1999-2007 Monitoring Plugins Development Team | 6 | * Copyright (c) 1999-2007 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
10 | * This file contains utilities for check_disk. These are tested by libtap | 10 | * This file contains utilities for check_disk. These are tested by libtap |
11 | * | 11 | * |
12 | * | 12 | * |
13 | * This program is free software: you can redistribute it and/or modify | 13 | * This program is free software: you can redistribute it and/or modify |
14 | * it under the terms of the GNU General Public License as published by | 14 | * it under the terms of the GNU General Public License as published by |
15 | * the Free Software Foundation, either version 3 of the License, or | 15 | * the Free Software Foundation, either version 3 of the License, or |
16 | * (at your option) any later version. | 16 | * (at your option) any later version. |
17 | * | 17 | * |
18 | * This program is distributed in the hope that it will be useful, | 18 | * This program is distributed in the hope that it will be useful, |
19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
21 | * GNU General Public License for more details. | 21 | * GNU General Public License for more details. |
22 | * | 22 | * |
23 | * You should have received a copy of the GNU General Public License | 23 | * You should have received a copy of the GNU General Public License |
24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
25 | * | 25 | * |
26 | * | 26 | * |
27 | *****************************************************************************/ | 27 | *****************************************************************************/ |
28 | 28 | ||
29 | #include "common.h" | 29 | #include "common.h" |
@@ -98,7 +98,7 @@ np_add_parameter(struct parameter_list **list, const char *name) | |||
98 | new_path->freeinodes_percent = NULL; | 98 | new_path->freeinodes_percent = NULL; |
99 | new_path->group = NULL; | 99 | new_path->group = NULL; |
100 | new_path->dfree_pct = -1; | 100 | new_path->dfree_pct = -1; |
101 | new_path->dused_pct = -1; | 101 | new_path->dused_pct = -1; |
102 | new_path->total = 0; | 102 | new_path->total = 0; |
103 | new_path->available = 0; | 103 | new_path->available = 0; |
104 | new_path->available_to_root = 0; | 104 | new_path->available_to_root = 0; |
@@ -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,26 +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 | } |
282 | |||