summaryrefslogtreecommitdiffstats
path: root/lib/utils_disk.c
diff options
context:
space:
mode:
authorLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2023-10-13 19:09:29 +0200
committerLorenz Kästle <12514511+RincewindsHat@users.noreply.github.com>2023-10-13 19:09:29 +0200
commitb6d3acf5e3f685d6048905d4bef84ebfbb9f4815 (patch)
tree8a4f5e2f2f28976f80ba9b5e68dd19ba917e35f4 /lib/utils_disk.c
parent41ebe4b6d9c36205577a336ae6f81567a0321267 (diff)
parentbf70f5f847e3407af572d1768cca747af270b993 (diff)
downloadmonitoring-plugins-b6d3acf5e3f685d6048905d4bef84ebfbb9f4815.tar.gz
Merge branch 'master' into check_dhcp_rogue_detection
Diffstat (limited to 'lib/utils_disk.c')
-rw-r--r--lib/utils_disk.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/lib/utils_disk.c b/lib/utils_disk.c
index 582d3ea1..f5ac0b30 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)
@@ -40,6 +41,42 @@ np_add_name (struct name_list **list, const char *name)
40 *list = new_entry; 41 *list = new_entry;
41} 42}
42 43
44/* @brief Initialises a new regex at the begin of list via regcomp(3)
45 *
46 * @details if the regex fails to compile the error code of regcomp(3) is returned
47 * and list is not modified, otherwise list is modified to point to the new
48 * element
49 * @param list Pointer to a linked list of regex_list elements
50 * @param regex the string containing the regex which should be inserted into the list
51 * @param clags the cflags parameter for regcomp(3)
52 */
53int
54np_add_regex (struct regex_list **list, const char *regex, int cflags)
55{
56 struct regex_list *new_entry = (struct regex_list *) malloc (sizeof *new_entry);
57
58 if (new_entry == NULL) {
59 die(STATE_UNKNOWN, _("Cannot allocate memory: %s"),
60 strerror(errno));
61 }
62
63 int regcomp_result = regcomp(&new_entry->regex, regex, cflags);
64
65 if (!regcomp_result) {
66 // regcomp succeeded
67 new_entry->next = *list;
68 *list = new_entry;
69
70 return 0;
71 } else {
72 // regcomp failed
73 free(new_entry);
74
75 return regcomp_result;
76 }
77
78}
79
43/* Initialises a new parameter at the end of list */ 80/* Initialises a new parameter at the end of list */
44struct parameter_list * 81struct parameter_list *
45np_add_parameter(struct parameter_list **list, const char *name) 82np_add_parameter(struct parameter_list **list, const char *name)
@@ -196,6 +233,30 @@ np_find_name (struct name_list *list, const char *name)
196 return FALSE; 233 return FALSE;
197} 234}
198 235
236/* Returns TRUE if name is in list */
237bool
238np_find_regmatch (struct regex_list *list, const char *name)
239{
240 int len;
241 regmatch_t m;
242
243 if (name == NULL) {
244 return false;
245 }
246
247 len = strlen(name);
248
249 for (; list; list = list->next) {
250 /* Emulate a full match as if surrounded with ^( )$
251 by checking whether the match spans the whole name */
252 if (!regexec(&list->regex, name, 1, &m, 0) && m.rm_so == 0 && m.rm_eo == len) {
253 return true;
254 }
255 }
256
257 return false;
258}
259
199int 260int
200np_seen_name(struct name_list *list, const char *name) 261np_seen_name(struct name_list *list, const char *name)
201{ 262{