diff options
author | Matthias Eble <psychotrahe@users.sourceforge.net> | 2007-09-22 17:40:35 +0000 |
---|---|---|
committer | Matthias Eble <psychotrahe@users.sourceforge.net> | 2007-09-22 17:40:35 +0000 |
commit | d23b17e6567d8eb983956b36b31a383f3cc639d2 (patch) | |
tree | 19ba67a6555bb609875f819af5c4b9c479101820 /lib | |
parent | 520f297fa931d391f81af672b5b0e34db71b8c73 (diff) | |
download | monitoring-plugins-d23b17e6567d8eb983956b36b31a383f3cc639d2.tar.gz |
Added -i/-I to ignore pathes/partitions based on regular expressions
Added check_disk -A selecting all filesystems
-E option must now be passed before -p or -r/-R
Passing -E after -p or -r results in UNKNOWN state
Fixed bug when mixing case sensitive and insensitive regexes
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1786 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'lib')
-rw-r--r-- | lib/tests/test_disk.c | 45 | ||||
-rw-r--r-- | lib/utils_disk.c | 21 | ||||
-rw-r--r-- | lib/utils_disk.h | 2 |
3 files changed, 66 insertions, 2 deletions
diff --git a/lib/tests/test_disk.c b/lib/tests/test_disk.c index ac9db005..fcde4f85 100644 --- a/lib/tests/test_disk.c +++ b/lib/tests/test_disk.c @@ -36,14 +36,15 @@ main (int argc, char **argv) struct name_list *dummy_mountlist = NULL; struct name_list *temp_name; struct parameter_list *paths = NULL; - struct parameter_list *p; + struct parameter_list *p, *prev, *last; struct mount_entry *dummy_mount_list; struct mount_entry *me; struct mount_entry **mtail = &dummy_mount_list; int cflags = REG_NOSUB | REG_EXTENDED; + int found = 0, count = 0; - plan_tests(29); + plan_tests(33); ok( np_find_name(exclude_filesystem, "/var/log") == FALSE, "/var/log not in list"); np_add_name(&exclude_filesystem, "/var/log"); @@ -160,6 +161,46 @@ main (int argc, char **argv) } } + /* test deleting first element in paths */ + paths = np_del_parameter(paths, NULL); + for (p = paths; p; p = p->name_next) { + if (! strcmp(p->name, "/home/groups")) + found = 1; + } + ok(found == 0, "first element successfully deleted"); + found = 0; + + p=paths; + while (p) { + if (! strcmp(p->name, "/tmp")) + p = np_del_parameter(p, prev); + else { + prev = p; + p = p->name_next; + } + } + + for (p = paths; p; p = p->name_next) { + if (! strcmp(p->name, "/tmp")) + found = 1; + if (p->name_next) + prev = p; + else + last = p; + } + ok(found == 0, "/tmp element successfully deleted"); + + p = np_del_parameter(last, prev); + for (p = paths; p; p = p->name_next) { + if (! strcmp(p->name, "/home")) + found = 1; + last = p; + count++; + } + ok(found == 0, "last (/home) element successfully deleted"); + ok(count == 2, "two elements remaining"); + + return exit_status(); } diff --git a/lib/utils_disk.c b/lib/utils_disk.c index 96f5a306..3f9c8a9a 100644 --- a/lib/utils_disk.c +++ b/lib/utils_disk.c @@ -74,6 +74,26 @@ np_add_parameter(struct parameter_list **list, const char *name) return new_path; } +/* Delete a given parameter from list and return pointer to next element*/ +struct parameter_list * +np_del_parameter(struct parameter_list *item, struct parameter_list *prev) +{ + struct parameter_list *next; + if (item->name_next) + next = item->name_next; + else + next = NULL; + + + free(item); + if (prev) + prev->name_next = next; + + return next; + +} + + /* returns a pointer to the struct found in the list */ struct parameter_list * np_find_parameter(struct parameter_list *list, const char *name) @@ -166,3 +186,4 @@ np_regex_match_mount_entry (struct mount_entry* me, regex_t* re) return false; } } + diff --git a/lib/utils_disk.h b/lib/utils_disk.h index 6263339f..f99b9050 100644 --- a/lib/utils_disk.h +++ b/lib/utils_disk.h @@ -31,6 +31,8 @@ int np_find_name (struct name_list *list, const char *name); int np_seen_name (struct name_list *list, const char *name); struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name); +struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev); + int search_parameter_list (struct parameter_list *list, const char *name); void np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact); int np_regex_match_mount_entry (struct mount_entry* me, regex_t* re); |