Code

Fix translations when extra-opts aren't enabled
[nagiosplug.git] / plugins / check_disk.c
index 2f8afa6c90e62bc0d982330611020d620ca9112e..633aa5fce071160bef77930e557cc9661579475e 100644 (file)
@@ -5,8 +5,6 @@
 * License: GPL
 * Copyright (c) 1999-2008 Nagios Plugins Development Team
 * 
-* Last Modified: $Date$
-* 
 * Description:
 * 
 * This file contains the check_disk plugin
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
-* $Id$
 * 
 *****************************************************************************/
 
 const char *progname = "check_disk";
 const char *program_name = "check_disk";  /* Required for coreutils libs */
-const char *revision = "$Revision$";
 const char *copyright = "1999-2008";
 const char *email = "nagiosplug-devel@lists.sourceforge.net";
 
@@ -118,9 +114,6 @@ enum
  #pragma alloca
 #endif
 
-/* Linked list of mounted filesystems. */
-static struct mount_entry *mount_list;
-
 int process_arguments (int, char **);
 void print_path (const char *mypath);
 void set_all_thresholds (struct parameter_list *path);
@@ -201,7 +194,7 @@ main (int argc, char **argv)
   /* If a list of paths has not been selected, find entire
      mount list and create list of paths
    */
-  if (path_selected == FALSE) { 
+  if (path_selected == FALSE) {
     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);
@@ -296,8 +289,8 @@ main (int argc, char **argv)
       /* Skip excluded fstypes */
       } else if (fs_exclude_list && np_find_name (fs_exclude_list, me->me_type)) {
         continue;
-      /* Skip excluded fs's */  
-      } else if (dp_exclude_list && 
+      /* Skip excluded fs's */
+      } else if (dp_exclude_list &&
                (np_find_name (dp_exclude_list, me->me_devname) ||
                 np_find_name (dp_exclude_list, me->me_mountdir))) {
         continue;
@@ -330,7 +323,7 @@ main (int argc, char **argv)
       dfree_inodes_percent = 100 - dused_inodes_percent;
 
       if (verbose >= 3) {
-        printf ("For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%llu mult=%llu\n", 
+        printf ("For %s, used_pct=%g free_pct=%g used_units=%g free_units=%g total_units=%g used_inodes_pct=%g free_inodes_pct=%g fsp.fsu_blocksize=%llu mult=%llu\n",
           me->me_mountdir, dused_pct, dfree_pct, dused_units, dfree_units, dtotal_units, dused_inodes_percent, dfree_inodes_percent, fsp.fsu_blocksize, mult);
       }
 
@@ -433,7 +426,7 @@ double calculate_percent(uintmax_t value, uintmax_t total) {
   double pct = -1;
   /* I don't understand the below, but it is taken from coreutils' df */
   /* Seems to be calculating pct, in the best possible way */
-  if (value <= TYPE_MAXIMUM(uintmax_t) / 100 
+  if (value <= TYPE_MAXIMUM(uintmax_t) / 100
     && total != 0) {
     uintmax_t u100 = value * 100;
     pct = u100 / total + (u100 % total != 0);
@@ -549,7 +542,7 @@ process_arguments (int argc, char **argv)
       }
       break;
 
-    /* Awful mistake where the range values do not make sense. Normally, 
+    /* Awful mistake where the range values do not make sense. Normally,
        you alert if the value is within the range, but since we are using
        freespace, we have to alert if outside the range. Thus we artifically
        force @ at the beginning of the range, so that it is backwards compatible
@@ -623,10 +616,10 @@ process_arguments (int argc, char **argv)
     case 'L':
       stat_remote_fs = 1;
     case 'l':
-      show_local_fs = 1;      
+      show_local_fs = 1;
       break;
     case 'p':                 /* select path */
-      if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent || 
+      if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent ||
              crit_freespace_percent || warn_usedspace_units || crit_usedspace_units ||
              warn_usedspace_percent || crit_usedspace_percent || warn_usedinodes_percent ||
              crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent )) {
@@ -639,8 +632,15 @@ process_arguments (int argc, char **argv)
       }
       se->group = group;
       set_all_thresholds(se);
-      np_set_best_match(se, mount_list, exact_match);
+
+      /* With autofs, it is required to stat() the path before re-populating the mount_list */
       stat_path(se);
+      /* NB: We can't free the old mount_list "just like that": both list pointers and struct
+       * pointers are copied around. One of the reason it wasn't done yet is that other parts
+       * of check_disk need the same kind of cleanup so it'd better be done as a whole */
+      mount_list = read_file_system_list (0);
+      np_set_best_match(se, mount_list, exact_match);
+
       path_selected = TRUE;
       break;
     case 'x':                 /* exclude path or partition */
@@ -661,19 +661,19 @@ process_arguments (int argc, char **argv)
       break;
     case 'E':
       if (path_selected)
-        die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting pathes\n"));
+        die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set -E before selecting paths\n"));
       exact_match = TRUE;
       break;
     case 'g':
       if (path_selected)
-        die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before selecting pathes \n"));
+        die (STATE_UNKNOWN, "DISK %s: %s", _("UNKNOWN"), _("Must set group value before selecting paths\n"));
       group = optarg;
       break;
     case 'I':
       cflags |= REG_ICASE;
     case 'i':
       if (!path_selected)
-        die (STATE_UNKNOWN, "DISK %s: %s\n", _("UNKNOWN"), _("Pathes need to be selected before using -i/-I. Use -A to select all pathes explicitly"));
+        die (STATE_UNKNOWN, "DISK %s: %s\n", _("UNKNOWN"), _("Paths need to be selected before using -i/-I. Use -A to select all paths explicitly"));
       err = regcomp(&re, optarg, cflags);
       if (err != 0) {
         regerror (err, &re, errbuf, MAX_INPUT_BUFFER);
@@ -713,7 +713,7 @@ process_arguments (int argc, char **argv)
     case 'R':
       cflags |= REG_ICASE;
     case 'r':
-      if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent || 
+      if (! (warn_freespace_units || crit_freespace_units || warn_freespace_percent ||
              crit_freespace_percent || warn_usedspace_units || crit_usedspace_units ||
              warn_usedspace_percent || crit_usedspace_percent || warn_usedinodes_percent ||
              crit_usedinodes_percent || warn_freeinodes_percent || crit_freeinodes_percent )) {
@@ -757,10 +757,9 @@ process_arguments (int argc, char **argv)
     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))) 
+           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;
            path->group = group;
@@ -784,7 +783,7 @@ process_arguments (int argc, char **argv)
       group = NULL;
       break;
     case 'V':                 /* version */
-      print_revision (progname, revision);
+      print_revision (progname, NP_VERSION);
       exit (STATE_OK);
     case 'h':                 /* help */
       print_help ();
@@ -819,7 +818,7 @@ process_arguments (int argc, char **argv)
 
 
 void
-print_path (const char *mypath) 
+print_path (const char *mypath)
 {
   if (mypath == NULL)
     printf ("\n");
@@ -829,7 +828,7 @@ print_path (const char *mypath)
 
 
 void
-set_all_thresholds (struct parameter_list *path) 
+set_all_thresholds (struct parameter_list *path)
 {
     if (path->freespace_units != NULL) free(path->freespace_units);
     set_thresholds(&path->freespace_units, warn_freespace_units, crit_freespace_units);
@@ -893,7 +892,7 @@ INPUT ERROR: C_DF (%lu) should be less than W_DF (%lu) and both should be greate
 void
 print_help (void)
 {
-  print_revision (progname, revision);
+  print_revision (progname, NP_VERSION);
 
   printf ("Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>\n");
   printf (COPYRIGHT, copyright, email);
@@ -905,8 +904,8 @@ print_help (void)
 
   print_usage ();
 
-  printf (_(UT_HELP_VRSN));
-  printf (_(UT_EXTRA_OPTS));
+  printf (UT_HELP_VRSN);
+  printf (UT_EXTRA_OPTS);
 
   printf (" %s\n", "-w, --warning=INTEGER");
   printf ("    %s\n", _("Exit with WARNING status if less than INTEGER units of disk are free"));
@@ -931,7 +930,7 @@ print_help (void)
   printf (" %s\n", "-e, --errors-only");
   printf ("    %s\n", _("Display only devices/mountpoints with errors"));
   printf (" %s\n", "-g, --group=NAME");
-  printf ("    %s\n", _("Group pathes. Thresholds apply to (free-)space of all partitions together"));
+  printf ("    %s\n", _("Group paths. Thresholds apply to (free-)space of all partitions together"));
   printf (" %s\n", "-k, --kilobytes");
   printf ("    %s\n", _("Same as '--units kB'"));
   printf (" %s\n", "-l, --local");
@@ -944,7 +943,7 @@ print_help (void)
   printf (" %s\n", "-m, --megabytes");
   printf ("    %s\n", _("Same as '--units MB'"));
   printf (" %s\n", "-A, --all");
-  printf ("    %s\n", _("Explicitly select all pathes. This is equivalent to -R '.*'"));
+  printf ("    %s\n", _("Explicitly select all paths. This is equivalent to -R '.*'"));
   printf (" %s\n", "-R, --eregi-path=PATH, --eregi-partition=PARTITION");
   printf ("    %s\n", _("Case insensitive regular expression for path/partition (may be repeated)"));
   printf (" %s\n", "-r, --ereg-path=PATH, --ereg-partition=PARTITION");
@@ -953,17 +952,17 @@ print_help (void)
   printf ("    %s\n", _("Regular expression to ignore selected path/partition (case insensitive) (may be repeated)"));
   printf (" %s\n", "-i, --ignore-ereg-path=PATH, --ignore-ereg-partition=PARTITION");
   printf ("    %s\n", _("Regular expression to ignore selected path or partition (may be repeated)"));
-  printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
+  printf (UT_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
   printf (" %s\n", "-u, --units=STRING");
   printf ("    %s\n", _("Choose bytes, kB, MB, GB, TB (default: MB)"));
-  printf (_(UT_VERBOSE));
+  printf (UT_VERBOSE);
   printf (" %s\n", "-X, --exclude-type=TYPE");
   printf ("    %s\n", _("Ignore all filesystems of indicated type (may be repeated)"));
 
 #ifdef NP_EXTRA_OPTS
   printf ("\n");
   printf ("%s\n", _("Notes:"));
-  printf (_(UT_EXTRA_OPTS_NOTES));
+  printf (UT_EXTRA_OPTS_NOTES);
 #endif
 
   printf ("\n");
@@ -976,7 +975,7 @@ print_help (void)
   printf (" %s\n", "check_disk -w 100M -c 50M -C -w 1000M -c 500M -p /foo -C -w 5% -c 3% -p /bar");
   printf ("    %s\n", _("Checks /foo for 1000M/500M and /bar for 5/3%. All remaining volumes use 100M/50M"));
 
-  printf (_(UT_SUPPORT));
+  printf (UT_SUPPORT);
 }