Code

Adding svn:keywords props
[nagiosplug.git] / lib / utils_disk.c
index fd768b20d09c7b356075f7e5f62e5b86a69941af..9324f5f32d35fd707ccb71158ee3c55543912ae1 100644 (file)
@@ -61,6 +61,7 @@ np_add_parameter(struct parameter_list **list, const char *name)
   new_path->usedspace_percent = NULL;
   new_path->usedinodes_percent = NULL;
   new_path->freeinodes_percent = NULL;
+  new_path->group = NULL;
 
   if (current == NULL) {
     *list = new_path;
@@ -73,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)
@@ -97,25 +118,26 @@ np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list
       size_t best_match_len = 0;
       struct mount_entry *best_match = NULL;
 
+      /* set best match if path name exactly matches a mounted device name */
       for (me = mount_list; me; me = me->me_next) {
-        size_t len = strlen (me->me_mountdir);
-        if ((exact == FALSE && (best_match_len <= len && len <= name_len && 
-          (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))
-      || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0))
-        {
+        if (strcmp(me->me_devname, d->name)==0)
           best_match = me;
-          best_match_len = len;
-        } else {
-          len = strlen (me->me_devname);
-          if ((exact == FALSE && (best_match_len <= len && len <= name_len &&
-            (len == 1 || strncmp (me->me_devname, d->name, len) == 0)))
-            || (exact == TRUE && strcmp(me->me_devname, d->name)==0))
+      }
+
+      /* set best match by directory name if no match was found by devname */
+      if (! best_match) {
+        for (me = mount_list; me; me = me->me_next) {
+          size_t len = strlen (me->me_mountdir);
+          if ((exact == FALSE && (best_match_len <= len && len <= name_len && 
+             (len == 1 || strncmp (me->me_mountdir, d->name, len) == 0)))
+             || (exact == TRUE && strcmp(me->me_mountdir, d->name)==0))
           {
             best_match = me;
             best_match_len = len;
           }
         }
       }
+
       if (best_match) {
         d->best_match = best_match;
       } else {
@@ -154,3 +176,14 @@ np_seen_name(struct name_list *list, const char *name)
   return FALSE;
 }
 
+int
+np_regex_match_mount_entry (struct mount_entry* me, regex_t* re) 
+{
+  if (regexec(re, me->me_devname, (size_t) 0, NULL, 0) == 0 ||
+      regexec(re, me->me_mountdir, (size_t) 0, NULL, 0) == 0 ) {
+    return TRUE;
+  } else {
+    return FALSE;
+  }
+}
+