diff options
Diffstat (limited to 'plugins/check_disk.d')
-rw-r--r-- | plugins/check_disk.d/utils_disk.c | 35 | ||||
-rw-r--r-- | plugins/check_disk.d/utils_disk.h | 9 |
2 files changed, 29 insertions, 15 deletions
diff --git a/plugins/check_disk.d/utils_disk.c b/plugins/check_disk.d/utils_disk.c index eec1282b..0b89018d 100644 --- a/plugins/check_disk.d/utils_disk.c +++ b/plugins/check_disk.d/utils_disk.c | |||
@@ -126,7 +126,8 @@ bool np_find_regmatch(struct regex_list *list, const char *name) { | |||
126 | /* Emulate a full match as if surrounded with ^( )$ | 126 | /* Emulate a full match as if surrounded with ^( )$ |
127 | by checking whether the match spans the whole name */ | 127 | by checking whether the match spans the whole name */ |
128 | regmatch_t dummy_match; | 128 | regmatch_t dummy_match; |
129 | if (!regexec(&list->regex, name, 1, &dummy_match, 0) && dummy_match.rm_so == 0 && dummy_match.rm_eo == len) { | 129 | if (!regexec(&list->regex, name, 1, &dummy_match, 0) && dummy_match.rm_so == 0 && |
130 | dummy_match.rm_eo == len) { | ||
130 | return true; | 131 | return true; |
131 | } | 132 | } |
132 | } | 133 | } |
@@ -144,7 +145,8 @@ bool np_seen_name(struct name_list *list, const char *name) { | |||
144 | } | 145 | } |
145 | 146 | ||
146 | bool np_regex_match_mount_entry(struct mount_entry *me, regex_t *re) { | 147 | bool np_regex_match_mount_entry(struct mount_entry *me, regex_t *re) { |
147 | return ((regexec(re, me->me_devname, (size_t)0, NULL, 0) == 0) || (regexec(re, me->me_mountdir, (size_t)0, NULL, 0) == 0)); | 148 | return ((regexec(re, me->me_devname, (size_t)0, NULL, 0) == 0) || |
149 | (regexec(re, me->me_mountdir, (size_t)0, NULL, 0) == 0)); | ||
148 | } | 150 | } |
149 | 151 | ||
150 | check_disk_config check_disk_config_init() { | 152 | check_disk_config check_disk_config_init() { |
@@ -264,7 +266,8 @@ measurement_unit_list *add_measurement_list(measurement_unit_list *list, measure | |||
264 | return new; | 266 | return new; |
265 | } | 267 | } |
266 | 268 | ||
267 | measurement_unit add_filesystem_to_measurement_unit(measurement_unit unit, parameter_list_elem filesystem) { | 269 | measurement_unit add_filesystem_to_measurement_unit(measurement_unit unit, |
270 | parameter_list_elem filesystem) { | ||
268 | 271 | ||
269 | unit.free_bytes += filesystem.free_bytes; | 272 | unit.free_bytes += filesystem.free_bytes; |
270 | unit.used_bytes += filesystem.used_bytes; | 273 | unit.used_bytes += filesystem.used_bytes; |
@@ -277,7 +280,8 @@ measurement_unit add_filesystem_to_measurement_unit(measurement_unit unit, param | |||
277 | return unit; | 280 | return unit; |
278 | } | 281 | } |
279 | 282 | ||
280 | measurement_unit create_measurement_unit_from_filesystem(parameter_list_elem filesystem, bool display_mntp) { | 283 | measurement_unit create_measurement_unit_from_filesystem(parameter_list_elem filesystem, |
284 | bool display_mntp) { | ||
281 | measurement_unit result = measurement_unit_init(); | 285 | measurement_unit result = measurement_unit_init(); |
282 | if (!display_mntp) { | 286 | if (!display_mntp) { |
283 | result.name = strdup(filesystem.best_match->me_mountdir); | 287 | result.name = strdup(filesystem.best_match->me_mountdir); |
@@ -469,17 +473,20 @@ parameter_list_elem *mp_int_fs_list_get_next(parameter_list_elem *current) { | |||
469 | return current->next; | 473 | return current->next; |
470 | } | 474 | } |
471 | 475 | ||
472 | void mp_int_fs_list_set_best_match(filesystem_list list, struct mount_entry *mount_list, bool exact) { | 476 | void mp_int_fs_list_set_best_match(filesystem_list list, struct mount_entry *mount_list, |
477 | bool exact) { | ||
473 | for (parameter_list_elem *elem = list.first; elem; elem = mp_int_fs_list_get_next(elem)) { | 478 | for (parameter_list_elem *elem = list.first; elem; elem = mp_int_fs_list_get_next(elem)) { |
474 | if (!elem->best_match) { | 479 | if (!elem->best_match) { |
475 | size_t name_len = strlen(elem->name); | 480 | size_t name_len = strlen(elem->name); |
476 | struct mount_entry *best_match = NULL; | 481 | struct mount_entry *best_match = NULL; |
477 | 482 | ||
478 | /* set best match if path name exactly matches a mounted device name */ | 483 | /* set best match if path name exactly matches a mounted device name */ |
479 | for (struct mount_entry *mount_entry = mount_list; mount_entry; mount_entry = mount_entry->me_next) { | 484 | for (struct mount_entry *mount_entry = mount_list; mount_entry; |
485 | mount_entry = mount_entry->me_next) { | ||
480 | if (strcmp(mount_entry->me_devname, elem->name) == 0) { | 486 | if (strcmp(mount_entry->me_devname, elem->name) == 0) { |
481 | struct fs_usage fsp; | 487 | struct fs_usage fsp; |
482 | if (get_fs_usage(mount_entry->me_mountdir, mount_entry->me_devname, &fsp) >= 0) { | 488 | if (get_fs_usage(mount_entry->me_mountdir, mount_entry->me_devname, &fsp) >= |
489 | 0) { | ||
483 | best_match = mount_entry; | 490 | best_match = mount_entry; |
484 | } | 491 | } |
485 | } | 492 | } |
@@ -488,15 +495,18 @@ void mp_int_fs_list_set_best_match(filesystem_list list, struct mount_entry *mou | |||
488 | /* set best match by directory name if no match was found by devname */ | 495 | /* set best match by directory name if no match was found by devname */ |
489 | if (!best_match) { | 496 | if (!best_match) { |
490 | size_t best_match_len = 0; | 497 | size_t best_match_len = 0; |
491 | for (struct mount_entry *mount_entry = mount_list; mount_entry; mount_entry = mount_entry->me_next) { | 498 | for (struct mount_entry *mount_entry = mount_list; mount_entry; |
499 | mount_entry = mount_entry->me_next) { | ||
492 | size_t len = strlen(mount_entry->me_mountdir); | 500 | size_t len = strlen(mount_entry->me_mountdir); |
493 | 501 | ||
494 | if ((!exact && (best_match_len <= len && len <= name_len && | 502 | if ((!exact && |
495 | (len == 1 || strncmp(mount_entry->me_mountdir, elem->name, len) == 0))) || | 503 | (best_match_len <= len && len <= name_len && |
504 | (len == 1 || strncmp(mount_entry->me_mountdir, elem->name, len) == 0))) || | ||
496 | (exact && strcmp(mount_entry->me_mountdir, elem->name) == 0)) { | 505 | (exact && strcmp(mount_entry->me_mountdir, elem->name) == 0)) { |
497 | struct fs_usage fsp; | 506 | struct fs_usage fsp; |
498 | 507 | ||
499 | if (get_fs_usage(mount_entry->me_mountdir, mount_entry->me_devname, &fsp) >= 0) { | 508 | if (get_fs_usage(mount_entry->me_mountdir, mount_entry->me_devname, &fsp) >= |
509 | 0) { | ||
500 | best_match = mount_entry; | 510 | best_match = mount_entry; |
501 | best_match_len = len; | 511 | best_match_len = len; |
502 | } | 512 | } |
@@ -507,7 +517,8 @@ void mp_int_fs_list_set_best_match(filesystem_list list, struct mount_entry *mou | |||
507 | if (best_match) { | 517 | if (best_match) { |
508 | elem->best_match = best_match; | 518 | elem->best_match = best_match; |
509 | } else { | 519 | } else { |
510 | elem->best_match = NULL; /* Not sure why this is needed as it should be null on initialisation */ | 520 | elem->best_match = |
521 | NULL; /* Not sure why this is needed as it should be null on initialisation */ | ||
511 | } | 522 | } |
512 | 523 | ||
513 | // No filesystem without a mount_entry! | 524 | // No filesystem without a mount_entry! |
diff --git a/plugins/check_disk.d/utils_disk.h b/plugins/check_disk.d/utils_disk.h index 6831d1fd..c96d4296 100644 --- a/plugins/check_disk.d/utils_disk.h +++ b/plugins/check_disk.d/utils_disk.h | |||
@@ -141,12 +141,15 @@ parameter_list_elem *mp_int_fs_list_append(filesystem_list *list, const char *na | |||
141 | parameter_list_elem *mp_int_fs_list_find(filesystem_list list, const char *name); | 141 | parameter_list_elem *mp_int_fs_list_find(filesystem_list list, const char *name); |
142 | parameter_list_elem *mp_int_fs_list_del(filesystem_list *list, parameter_list_elem *item); | 142 | parameter_list_elem *mp_int_fs_list_del(filesystem_list *list, parameter_list_elem *item); |
143 | parameter_list_elem *mp_int_fs_list_get_next(parameter_list_elem *current); | 143 | parameter_list_elem *mp_int_fs_list_get_next(parameter_list_elem *current); |
144 | void mp_int_fs_list_set_best_match(filesystem_list list, struct mount_entry *mount_list, bool exact); | 144 | void mp_int_fs_list_set_best_match(filesystem_list list, struct mount_entry *mount_list, |
145 | bool exact); | ||
145 | 146 | ||
146 | measurement_unit measurement_unit_init(); | 147 | measurement_unit measurement_unit_init(); |
147 | measurement_unit_list *add_measurement_list(measurement_unit_list *list, measurement_unit elem); | 148 | measurement_unit_list *add_measurement_list(measurement_unit_list *list, measurement_unit elem); |
148 | measurement_unit add_filesystem_to_measurement_unit(measurement_unit unit, parameter_list_elem filesystem); | 149 | measurement_unit add_filesystem_to_measurement_unit(measurement_unit unit, |
149 | measurement_unit create_measurement_unit_from_filesystem(parameter_list_elem filesystem, bool display_mntp); | 150 | parameter_list_elem filesystem); |
151 | measurement_unit create_measurement_unit_from_filesystem(parameter_list_elem filesystem, | ||
152 | bool display_mntp); | ||
150 | 153 | ||
151 | int search_parameter_list(parameter_list_elem *list, const char *name); | 154 | int search_parameter_list(parameter_list_elem *list, const char *name); |
152 | bool np_regex_match_mount_entry(struct mount_entry *, regex_t *); | 155 | bool np_regex_match_mount_entry(struct mount_entry *, regex_t *); |