--- nagios-plugins-HEAD-200702101300/plugins/check_disk.c	2007-02-06 22:03:20.000000000 +0100
+++ nagios-plugins-HEAD-200702101300-clearfix/plugins/check_disk.c	2007-02-10 21:20:39.528580000 +0100
@@ -121,6 +121,7 @@
 
 int process_arguments (int, char **);
 void print_path (const char *mypath);
+void set_all_thresholds (struct parameter_list *path);
 int validate_arguments (uintmax_t, uintmax_t, double, double, double, double, char *);
 void print_help (void);
 void print_usage (void);
@@ -148,6 +149,7 @@
 char *crit_usedinodes_percent = NULL;
 char *warn_freeinodes_percent = NULL;
 char *crit_freeinodes_percent = NULL;
+bool path_selected = false;
 
 
 int
@@ -190,33 +192,34 @@
   /* If a list of paths has not been selected, find entire
      mount list and create list of paths
    */
-  if (! path_select_list) {
+  if (path_selected == false) { 
     for (me = mount_list; me; me = me->me_next) {
-      path = np_add_parameter(&path_select_list, me->me_mountdir);
+      if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) {
+        path = np_add_parameter(&path_select_list, me->me_mountdir);
+      }
       path->best_match = me;
-      set_thresholds(&path->freespace_units, warn_freespace_units, crit_freespace_units);
-      set_thresholds(&path->freespace_percent, warn_freespace_percent, crit_freespace_percent);
-      set_thresholds(&path->usedspace_units, warn_usedspace_units, crit_usedspace_units);
-      set_thresholds(&path->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent);
-      set_thresholds(&path->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent);
-      set_thresholds(&path->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent);
+      set_all_thresholds(path);
     }
-  } else {
-    np_set_best_match(path_select_list, mount_list, exact_match);
+  }
+  np_set_best_match(path_select_list, mount_list, exact_match);
 
-    /* Error if no match found for specified paths */
-    temp_list = path_select_list;
-    while (temp_list) {
-      if (! temp_list->best_match) {
-        die (STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), temp_list->name);
-      }
-      temp_list = temp_list->name_next;
+  /* Error if no match found for specified paths */
+  temp_list = path_select_list;
+  while (temp_list) {
+    if (! temp_list->best_match) {
+      die (STATE_CRITICAL, _("DISK %s: %s not found\n"), _("CRITICAL"), temp_list->name);
     }
+    temp_list = temp_list->name_next;
   }
+  
 
   /* Process for every path in list */
   for (path = path_select_list; path; path=path->name_next) {
 
+    if (verbose > 3 && path->freespace_percent->warning != NULL && path->freespace_percent->critical != NULL)
+      printf("Thresholds(pct) for %s warn: %f crit %f\n",path->name, path->freespace_percent->warning->end,
+                                                         path->freespace_percent->critical->end);
+
     /* reset disk result */
     disk_result = STATE_UNKNOWN;
 
@@ -548,13 +551,14 @@
              crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent )) {
         die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set a threshold value before using -p\n"));
       }
-      se = np_add_parameter(&path_select_list, optarg);
-      set_thresholds(&se->freespace_units, warn_freespace_units, crit_freespace_units);
-      set_thresholds(&se->freespace_percent, warn_freespace_percent, crit_freespace_percent);
-      set_thresholds(&se->usedspace_units, warn_usedspace_units, crit_usedspace_units);
-      set_thresholds(&se->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent);
-      set_thresholds(&se->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent);
-      set_thresholds(&se->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent);
+
+      /* add parameter if not found. overwrite thresholds if path has already been added  */
+      if (! (se = np_find_parameter(path_select_list, optarg))) {
+          se = np_add_parameter(&path_select_list, optarg);
+      }
+
+      set_all_thresholds(se);
+      path_selected = true;
       break;
     case 'x':                 /* exclude path or partition */
       np_add_name(&dp_exclude_list, optarg);
@@ -578,6 +582,17 @@
       display_mntp = TRUE;
       break;
     case 'C':
+       /* add all mount entries to path_select list if no partitions have been explicitly defined using -p */
+       if (path_selected == false) {
+         struct mount_entry *me;
+         struct parameter_list *path;
+         for (me = mount_list; me; me = me->me_next) {
+           if (! (path = np_find_parameter(path_select_list, me->me_mountdir))) 
+             path = np_add_parameter(&path_select_list, me->me_mountdir);
+           path->best_match = me;
+           set_all_thresholds(path);
+         }
+      }
       warn_freespace_units = NULL;
       crit_freespace_units = NULL;
       warn_usedspace_units = NULL;
@@ -590,6 +605,8 @@
       crit_usedinodes_percent = NULL;
       warn_freeinodes_percent = NULL;
       crit_freeinodes_percent = NULL;
+    
+      path_selected = false;
       break;
     case 'V':                 /* version */
       print_revision (progname, revision);
@@ -612,12 +629,7 @@
 
   if (argc > c && path == NULL) {
     se = np_add_parameter(&path_select_list, strdup(argv[c++]));
-    set_thresholds(&se->freespace_units, warn_freespace_units, crit_freespace_units);
-    set_thresholds(&se->freespace_percent, warn_freespace_percent, crit_freespace_percent);
-    set_thresholds(&se->usedspace_units, warn_usedspace_units, crit_usedspace_units);
-    set_thresholds(&se->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent);
-    set_thresholds(&se->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent);
-    set_thresholds(&se->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent);
+    set_all_thresholds(se);
   }
 
   if (units == NULL) {
@@ -665,6 +677,16 @@
 }
 
 
+void
+set_all_thresholds (struct parameter_list *path) 
+{
+    set_thresholds(&path->freespace_units, warn_freespace_units, crit_freespace_units);
+    set_thresholds(&path->freespace_percent, warn_freespace_percent, crit_freespace_percent);
+    set_thresholds(&path->usedspace_units, warn_usedspace_units, crit_usedspace_units);
+    set_thresholds(&path->usedspace_percent, warn_usedspace_percent, crit_usedspace_percent);
+    set_thresholds(&path->usedinodes_percent, warn_usedinodes_percent, crit_usedinodes_percent);
+    set_thresholds(&path->freeinodes_percent, warn_freeinodes_percent, crit_freeinodes_percent);
+}
 
 /* TODO: Remove?
 
--- nagios-plugins-HEAD-200702101300/lib/utils_disk.c	2006-12-20 20:25:59.000000000 +0100
+++ nagios-plugins-HEAD-200702101300-clearfix/lib/utils_disk.c	2007-02-10 21:20:39.528580000 +0100
@@ -73,39 +73,54 @@
   return new_path;
 }
 
+/* returns a pointer to the struct found in the list */
+struct parameter_list *
+np_find_parameter(struct parameter_list *list, const char *name)
+{
+  struct parameter_list *temp_list;
+  for (temp_list = list; temp_list; temp_list = temp_list->name_next) {
+    if (! strcmp(temp_list->name, name))
+        return temp_list;
+  }
+        
+  return NULL;
+}
+
 void
 np_set_best_match(struct parameter_list *desired, struct mount_entry *mount_list, int exact)
 {
   struct parameter_list *d;
   for (d = desired; d; d= d->name_next) {
-    struct mount_entry *me;
-    size_t name_len = strlen(d->name);
-    size_t best_match_len = 0;
-    struct mount_entry *best_match = NULL;
-
-    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;
-      } 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))
+    if (! d->best_match) {
+      struct mount_entry *me;
+      size_t name_len = strlen(d->name);
+      size_t best_match_len = 0;
+      struct mount_entry *best_match = NULL;
+
+      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;
+        } 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))
+          {
+            best_match = me;
+            best_match_len = len;
+          }
         }
       }
-    }
-    if (best_match) {
-      d->best_match = best_match;
-    } else {
-      d->best_match = NULL;	/* Not sure why this is needed as it should be null on initialisation */
+      if (best_match) {
+        d->best_match = best_match;
+      } else {
+        d->best_match = NULL;	/* Not sure why this is needed as it should be null on initialisation */
+      }
     }
   }
 }
--- nagios-plugins-HEAD-200702101300/lib/utils_disk.h	2006-12-20 20:25:59.000000000 +0100
+++ nagios-plugins-HEAD-200702101300-clearfix/lib/utils_disk.h	2007-02-10 21:20:39.532580250 +0100
@@ -28,5 +28,6 @@
 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);
 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);
