summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAlexander A. Klimov <alexander.klimov@icinga.com>2023-08-23 16:26:12 (GMT)
committerAlexander A. Klimov <alexander.klimov@icinga.com>2023-09-28 11:20:24 (GMT)
commit1f694195b4a6beef30bbbbffa5835a993be97a9c (patch)
tree0a9add089b64d64a4a802e9ae2c371450ac6257b /lib
parentd31a696cadb0bba0914d76aad0eb48c6e7962b8e (diff)
downloadmonitoring-plugins-1f694195b4a6beef30bbbbffa5835a993be97a9c.tar.gz
Introduce np_find_regmatch()
Diffstat (limited to 'lib')
-rw-r--r--lib/utils_disk.c25
-rw-r--r--lib/utils_disk.h1
2 files changed, 26 insertions, 0 deletions
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index ce02fdf..34401e2 100644
--- a/lib/utils_disk.c
+++ b/lib/utils_disk.c
@@ -29,6 +29,7 @@
29#include "common.h" 29#include "common.h"
30#include "utils_disk.h" 30#include "utils_disk.h"
31#include "gl/fsusage.h" 31#include "gl/fsusage.h"
32#include <string.h>
32 33
33void 34void
34np_add_name (struct name_list **list, const char *name) 35np_add_name (struct name_list **list, const char *name)
@@ -207,6 +208,30 @@ np_find_name (struct name_list *list, const char *name)
207 return FALSE; 208 return FALSE;
208} 209}
209 210
211/* Returns TRUE if name is in list */
212bool
213np_find_regmatch (struct regex_list *list, const char *name)
214{
215 int len;
216 regmatch_t m;
217
218 if (name == NULL) {
219 return false;
220 }
221
222 len = strlen(name);
223
224 for (; list; list = list->next) {
225 /* Emulate a full match as if surrounded with ^( )$
226 by checking whether the match spans the whole name */
227 if (!regexec(&list->regex, name, 1, &m, 0) && m.rm_so == 0 && m.rm_eo == len) {
228 return true;
229 }
230 }
231
232 return false;
233}
234
210int 235int
211np_seen_name(struct name_list *list, const char *name) 236np_seen_name(struct name_list *list, const char *name)
212{ 237{
diff --git a/lib/utils_disk.h b/lib/utils_disk.h
index bda088f..6b83ac7 100644
--- a/lib/utils_disk.h
+++ b/lib/utils_disk.h
@@ -42,6 +42,7 @@ void np_add_name (struct name_list **list, const char *name);
42int np_find_name (struct name_list *list, const char *name); 42int np_find_name (struct name_list *list, const char *name);
43int np_seen_name (struct name_list *list, const char *name); 43int np_seen_name (struct name_list *list, const char *name);
44int np_add_regex (struct regex_list **list, const char *regex, int cflags); 44int np_add_regex (struct regex_list **list, const char *regex, int cflags);
45bool np_find_regmatch (struct regex_list *list, const char *name);
45struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name); 46struct parameter_list *np_add_parameter(struct parameter_list **list, const char *name);
46struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name); 47struct parameter_list *np_find_parameter(struct parameter_list *list, const char *name);
47struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev); 48struct parameter_list *np_del_parameter(struct parameter_list *item, struct parameter_list *prev);