]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
sort,numfmt: with --debug, diagnose failure to set locale
authorPádraig Brady <P@draigBrady.com>
Tue, 22 Sep 2015 01:07:41 +0000 (02:07 +0100)
committerPádraig Brady <P@draigBrady.com>
Tue, 22 Sep 2015 01:30:30 +0000 (02:30 +0100)
* src/sort.c (main): With --debug, warn upon setlocale() failure,
which can happen due to incorrectly specified environment variables,
or due to memory exhaustion (simulated with ulimit -v), etc.
* tests/misc/sort-debug-warn.sh: Add a test case.
See also http://savannah.gnu.org/bugs/11004

src/numfmt.c
src/sort.c
tests/misc/sort-debug-warn.sh

index 24bf45b3778c61113cd63b0aca3dda96a221c970..109947e20253eecb17e2e9e739141b228e7637aa 100644 (file)
@@ -1429,10 +1429,11 @@ int
 main (int argc, char **argv)
 {
   int valid_numbers = 1;
+  bool locale_ok;
 
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
-  setlocale (LC_ALL, "");
+  locale_ok = setlocale (LC_ALL, "");
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
@@ -1558,6 +1559,9 @@ main (int argc, char **argv)
   if (format_str != NULL && grouping)
     error (EXIT_FAILURE, 0, _("--grouping cannot be combined with --format"));
 
+  if (debug && ! locale_ok)
+    error (0, 0, _("failed to set locale"));
+
   /* Warn about no-op.  */
   if (debug && scale_from == scale_none && scale_to == scale_none
       && !grouping && (padding_width == 0) && (format_str == NULL))
index 7ce059282a0ccaedb5f3f7a29d6cc9438fbdd8d0..9396f46dce3ced88e7464df5c6da9e9f19c47ee6 100644 (file)
@@ -4187,10 +4187,11 @@ main (int argc, char **argv)
   char *files_from = NULL;
   struct Tokens tok;
   char const *outfile = NULL;
+  bool locale_ok;
 
   initialize_main (&argc, &argv);
   set_program_name (argv[0]);
-  setlocale (LC_ALL, "");
+  locale_ok = setlocale (LC_ALL, "");
   bindtextdomain (PACKAGE, LOCALEDIR);
   textdomain (PACKAGE);
 
@@ -4664,7 +4665,10 @@ main (int argc, char **argv)
         error (0, 0, _("using %s sorting rules"),
                quote (setlocale (LC_COLLATE, NULL)));
       else
-        error (0, 0, _("using simple byte comparison"));
+        {
+          error (0, 0, "%s%s", locale_ok ? "" : _("failed to set locale; "),
+                 _("using simple byte comparison"));
+        }
       key_warnings (&gkey, gkey_only);
     }
 
index 19015664adb5e28a86a4f9b5e23466d3bed1a8e4..b25365f50d2d2f14a2bed99c501ec6071fa029a7 100755 (executable)
@@ -51,6 +51,7 @@ sort: option '-i' is ignored
 sort: using simple byte comparison
 sort: using simple byte comparison
 sort: using simple byte comparison
+sort: failed to set locale; using simple byte comparison
 EOF
 
 sort -s -k2,1 --debug /dev/null 2>>out
@@ -70,6 +71,7 @@ sort -i -k1,1d --debug /dev/null 2>>out
 sort -r --debug /dev/null 2>>out #no warning
 sort -rM --debug /dev/null 2>>out #no warning
 sort -rM -k1,1 --debug /dev/null 2>>out #no warning
+LC_ALL=missing sort --debug /dev/null 2>>out
 
 compare exp out || fail=1