Просмотр исходного кода

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 лет назад
Родитель
Сommit
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-??-??
 2.3.2 2020-??-??
 	FIXES
 	FIXES
 	check_http: Fix host:port syntax when using -H (Isaac White)
 	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
 2.3.1 2019-12-09
 	FIXES
 	FIXES

+ 6 - 4
plugins/check_disk.c

@@ -786,16 +786,16 @@ process_arguments (int argc, char **argv)
         mult = (uintmax_t)1;
         mult = (uintmax_t)1;
         units = strdup ("B");
         units = strdup ("B");
       } else if (! strcmp (optarg, "kB")) {
       } else if (! strcmp (optarg, "kB")) {
-        mult = (uintmax_t)1000;
+        mult = (uintmax_t)1024;
         units = strdup ("kB");
         units = strdup ("kB");
       } else if (! strcmp (optarg, "MB")) {
       } else if (! strcmp (optarg, "MB")) {
-        mult = (uintmax_t)1000 * 1000;
+        mult = (uintmax_t)1024 * 1024;
         units = strdup ("MB");
         units = strdup ("MB");
       } else if (! strcmp (optarg, "GB")) {
       } else if (! strcmp (optarg, "GB")) {
-        mult = (uintmax_t)1000 * 1000 * 1000;
+        mult = (uintmax_t)1024 * 1024 * 1024;
         units = strdup ("GB");
         units = strdup ("GB");
       } else if (! strcmp (optarg, "TB")) {
       } else if (! strcmp (optarg, "TB")) {
-        mult = (uintmax_t)1000 * 1000 * 1000 * 1000;
+        mult = (uintmax_t)1024 * 1024 * 1024 * 1024;
         units = strdup ("TB");
         units = strdup ("TB");
       } else if (! strcmp (optarg, "KiB")) {
       } else if (! strcmp (optarg, "KiB")) {
         mult = (uintmax_t)1024;
         mult = (uintmax_t)1024;
@@ -1202,6 +1202,8 @@ print_help (void)
   printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
   printf (UT_PLUG_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
   printf (" %s\n", "-u, --units=STRING");
   printf (" %s\n", "-u, --units=STRING");
   printf ("    %s\n", _("Choose bytes, kB, MB, GB, TB, KiB, MiB, GiB, TiB (default: MiB)"));
   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 (UT_VERBOSE);
   printf (" %s\n", "-X, --exclude-type=TYPE");
   printf (" %s\n", "-X, --exclude-type=TYPE");
   printf ("    %s\n", _("Ignore all filesystems of indicated type (may be repeated)"));
   printf ("    %s\n", _("Ignore all filesystems of indicated type (may be repeated)"));