瀏覽代碼

Resolves #518 - all calculations are now done with binary units (as it was in 2.2.x).

The code for unit calculation in check_disk.c looks a little silly now, but this preserves backward compatibility for the largest number of users. Anyone who started using the plugin before 2.3.x sees behavior unchanged, and anyone who chose binary units in 2.3.0+ keeps their new behavior.
madlohe 6 年之前
父節點
當前提交
bd4bb0fd52
共有 2 個文件被更改,包括 7 次插入4 次删除
  1. 1 0
      NEWS
  2. 6 4
      plugins/check_disk.c

+ 1 - 0
NEWS

@@ -3,6 +3,7 @@ This file documents the major additions and syntax changes between releases.
 2.3.2 2020-??-??
 	FIXES
 	check_http: Fix host:port syntax when using -H (Isaac White)
+	check_disk: Change unit calculations to always use binary units for backward compatibility (#518)
 
 2.3.1 2019-12-09
 	FIXES

+ 6 - 4
plugins/check_disk.c

@@ -786,16 +786,16 @@ process_arguments (int argc, char **argv)
         mult = (uintmax_t)1;
         units = strdup ("B");
       } else if (! strcmp (optarg, "kB")) {
-        mult = (uintmax_t)1000;
+        mult = (uintmax_t)1024;
         units = strdup ("kB");
       } else if (! strcmp (optarg, "MB")) {
-        mult = (uintmax_t)1000 * 1000;
+        mult = (uintmax_t)1024 * 1024;
         units = strdup ("MB");
       } else if (! strcmp (optarg, "GB")) {
-        mult = (uintmax_t)1000 * 1000 * 1000;
+        mult = (uintmax_t)1024 * 1024 * 1024;
         units = strdup ("GB");
       } else if (! strcmp (optarg, "TB")) {
-        mult = (uintmax_t)1000 * 1000 * 1000 * 1000;
+        mult = (uintmax_t)1024 * 1024 * 1024 * 1024;
         units = strdup ("TB");
       } else if (! strcmp (optarg, "KiB")) {
         mult = (uintmax_t)1024;
@@ -1202,6 +1202,8 @@ print_help (void)
   printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
   printf (" %s\n", "-u, --units=STRING");
   printf ("    %s\n", _("Choose bytes, kB, MB, GB, TB, KiB, MiB, GiB, TiB (default: MiB)"));
+  printf ("    %s\n", _("Note: kB/MB/GB/TB are still calculated as their respective binary"));
+  printf ("    %s\n", _("units due to backward compatibility issues."));
   printf (UT_VERBOSE);
   printf (" %s\n", "-X, --exclude-type=TYPE");
   printf ("    %s\n", _("Ignore all filesystems of indicated type (may be repeated)"));