[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SCM] Debian package checker branch, master, updated. 2.5.4-158-gca350d8



The following commit has been merged in the master branch:
commit ca350d8b6458dce7b7ad8316264cfc17e1e3e7b9
Author: Niels Thykier <niels@thykier.net>
Date:   Thu Feb 9 20:54:45 2012 +0100

    Util: Make clean_env optionally set LC_ALL
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/checks/manpages b/checks/manpages
index 47f44f2..3224eb6 100644
--- a/checks/manpages
+++ b/checks/manpages
@@ -218,7 +218,6 @@ foreach my $file (@{$info->sorted_index}) {
                 fail("cannot run lexgrog: $!");
             } elsif ($pid == 0) {
                 clean_env;
-                $ENV{LC_ALL} = 'en_US.UTF-8';
                 exec "lexgrog \Q$path\E 2>&1"
                     or fail("cannot run lexgrog: $!");
             }
@@ -250,7 +249,6 @@ foreach my $file (@{$info->sorted_index}) {
             fail("cannot run man -E UTF-8 -l: $!");
         } elsif ($pid == 0) {
             clean_env;
-            $ENV{LC_ALL} = 'en_US.UTF-8';
             $ENV{MANWIDTH} = 80;
             exec "($cmd >/dev/null) 2>&1"
                 or fail("cannot run man -E UTF-8 -l: $!");
diff --git a/lib/Util.pm b/lib/Util.pm
index ea7beea..f1fe76d 100644
--- a/lib/Util.pm
+++ b/lib/Util.pm
@@ -272,7 +272,7 @@ sub system_env {
     if (not defined $pid) {
         return -1;
     } elsif ($pid == 0) {
-        clean_env();
+        clean_env(1);
         exec @_ or die("exec of $_[0] failed: $!\n");
     } else {
         waitpid $pid, 0;
@@ -281,13 +281,32 @@ sub system_env {
 }
 
 # Destructively clean %ENV - removes all variables from %ENV except
-# those listed as arguments.  If called without arguments a default
-# whitelist (including PATH and LOCPATH) will be used) instead.
+# a selected few whitelisted variables (including PATH and LOCPATH)
+#
+# Based on LOCPATH (and /usr/lib/locale), this function will set
+# LC_ALL to C.UTF-8 or en_US.UTF-8.  If neither LOCPATH nor
+# /usr/lib/locale has any of those locales, then LC_ALL will be
+# cleared.  It is possible to skip the LC_ALL check by passing a
+# truth value as first argument.
 sub clean_env {
-    my @whitelist = @_;
-    @whitelist = qw(PATH INTLTOOL_EXTRACT LOCPATH) unless @whitelist;
+    my ($no_lcall) = @_;
+    my @whitelist = qw(PATH INTLTOOL_EXTRACT LOCPATH);
+    my @locales = qw(C.UTF-8 en_US.UTF-8);
     my %newenv = map { exists $ENV{$_} ? ($_ => $ENV{$_}) : () } (@whitelist, @_);
     %ENV = %newenv;
+    return if $no_lcall;
+    foreach my $locpath ($ENV{LOCPATH}, '/usr/lib/locale') {
+        if ($locpath && -d $ENV{LOCPATH}) {
+            $locpath = $ENV{LOCPATH};
+            foreach my $loc (@locales) {
+                if ( -d "$locpath/$loc" ) {
+                    $ENV{LC_ALL} = $loc;
+                    return;
+                }
+            }
+        }
+    }
+    fail ("clean_env: could not find needed locale");
 }
 
 # Translate permission strings like `-rwxrwxrwx' into an octal number.

-- 
Debian package checker


Reply to: