[monitoring-plugins] Introduce np_find_regmatch()
Alexander A. Klimov
git at monitoring-plugins.org
Thu Oct 5 11:00:13 CEST 2023
Module: monitoring-plugins
Branch: master
Commit: 1f694195b4a6beef30bbbbffa5835a993be97a9c
Author: Alexander A. Klimov <alexander.klimov at icinga.com>
Date: Wed Aug 23 18:26:12 2023 +0200
URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=1f69419
Introduce np_find_regmatch()
---
lib/utils_disk.c | 25 +++++++++++++++++++++++++
lib/utils_disk.h | 1 +
2 files changed, 26 insertions(+)
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 @@
#include "common.h"
#include "utils_disk.h"
#include "gl/fsusage.h"
+#include <string.h>
void
np_add_name (struct name_list **list, const char *name)
@@ -207,6 +208,30 @@ np_find_name (struct name_list *list, const char *name)
return FALSE;
}
+/* Returns TRUE if name is in list */
+bool
+np_find_regmatch (struct regex_list *list, const char *name)
+{
+ int len;
+ regmatch_t m;
+
+ if (name == NULL) {
+ return false;
+ }
+
+ len = strlen(name);
+
+ for (; list; list = list->next) {
+ /* Emulate a full match as if surrounded with ^( )$
+ by checking whether the match spans the whole name */
+ if (!regexec(&list->regex, name, 1, &m, 0) && m.rm_so == 0 && m.rm_eo == len) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
int
np_seen_name(struct name_list *list, const char *name)
{
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);
int np_find_name (struct name_list *list, const char *name);
int np_seen_name (struct name_list *list, const char *name);
int np_add_regex (struct regex_list **list, const char *regex, int cflags);
+bool np_find_regmatch (struct regex_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);
More information about the Commits
mailing list