Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

locale gubbins produces unavoidable noise #15501

Open
p5pRT opened this issue Aug 8, 2016 · 4 comments
Open

locale gubbins produces unavoidable noise #15501

p5pRT opened this issue Aug 8, 2016 · 4 comments

Comments

@p5pRT
Copy link

@p5pRT p5pRT commented Aug 8, 2016

Migrated from rt.perl.org#128874 (status was 'open')

Searchable as RT128874$

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Aug 8, 2016

From zefram@fysh.org

Created by zefram@fysh.org

$ LANG=wibble perl -e 'print "not using locale\n"'
perl​: warning​: Setting locale failed.
perl​: warning​: Please check that your locale settings​:
  LANGUAGE = (unset),
  LC_ALL = (unset),
  LANG = "wibble"
  are supported and installed on your system.
perl​: warning​: Falling back to the standard locale ("C").
not using locale

The hefty warning about failing to set locale occurs during
initialisation, before a program written in Perl gets control.
The overall effect is that a program that does not use locale has its
stderr output marred by noise that is irrelevant and which it can't avoid.
Even if a program does want to use the environmental locale, it has no
chance to handle the error in its preferred way. As far as I can see,
there is no way for the program to prevent the failing setlocale attempt,
muffle the warning, or even to detect that this has happened.

perl should not be saying anything on the program's stderr, other than
warnings about the program, over which the program has some control.
Griping about the environment settings is damaging the program's visible
behaviour, making it effectively impossible to write a non-locale program
in Perl. And remember, locale is an opt-in system.

Depending on how important this implicit setlocale call is, perl should
either keep quiet about the failure, or treat the failure as a hard error
that prevents running the program. The automatic message about locale
setting should not precede or otherwise mix with actual program output.

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.24.0:

Configured by zefram at Mon May  9 19:42:55 BST 2016.

Summary of my perl5 (revision 5 version 24 subversion 0) configuration:
   
  Platform:
    osname=linux, osvers=3.16.0-4-amd64, archname=x86_64-linux-thread-multi
    uname='linux barba.rous.org 3.16.0-4-amd64 #1 smp debian 3.16.7-ckt11-1+deb8u6 (2015-11-09) x86_64 gnulinux '
    config_args='-des -Dprefix=/home/zefram/usr/perl/perl_install/perl-5.24.0-i64-f52 -Duselargefiles -Dusethreads -Uafs -Ud_csh -Uusesfio -Uusenm -Duseshrplib -Dusedevel -Uversiononly -Ui_db'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2',
    optimize='-O2',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion='', gccversion='4.9.2', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
    libs=-lpthread -lnsl -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.19.so, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.19'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/home/zefram/usr/perl/perl_install/perl-5.24.0-i64-f52/lib/5.24.0/x86_64-linux-thread-multi/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'



@INC for perl 5.24.0:
    /home/zefram/usr/perl/perl_install/perl-5.24.0-i64-f52/lib/site_perl/5.24.0/x86_64-linux-thread-multi
    /home/zefram/usr/perl/perl_install/perl-5.24.0-i64-f52/lib/site_perl/5.24.0
    /home/zefram/usr/perl/perl_install/perl-5.24.0-i64-f52/lib/5.24.0/x86_64-linux-thread-multi
    /home/zefram/usr/perl/perl_install/perl-5.24.0-i64-f52/lib/5.24.0
    .


Environment for perl 5.24.0:
    HOME=/home/zefram
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/zefram/usr/perl/perl_install/perl-5.24.0-i64-f52/bin:/home/zefram/usr/perl/util:/home/zefram/pub/x86_64-unknown-linux-gnu/bin:/home/zefram/pub/common/bin:/usr/bin:/bin:/usr/local/bin:/usr/games
    PERL_BADLANG (unset)
    SHELL=/usr/bin/zsh

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Aug 8, 2016

From @khwilliamson

On 08/08/2016 10​:49 AM, Zefram (via RT) wrote​:

# New Ticket Created by Zefram
# Please include the string​: [perl #128874]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=128874 >

This is a bug report for perl from zefram@​fysh.org,
generated with the help of perlbug 1.40 running under perl 5.24.0.

-----------------------------------------------------------------
[Please describe your issue here]

$ LANG=wibble perl -e 'print "not using locale\n"'
perl​: warning​: Setting locale failed.
perl​: warning​: Please check that your locale settings​:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "wibble"
are supported and installed on your system.
perl​: warning​: Falling back to the standard locale ("C").
not using locale

The hefty warning about failing to set locale occurs during
initialisation, before a program written in Perl gets control.
The overall effect is that a program that does not use locale has its
stderr output marred by noise that is irrelevant and which it can't avoid.
Even if a program does want to use the environmental locale, it has no
chance to handle the error in its preferred way. As far as I can see,
there is no way for the program to prevent the failing setlocale attempt,
muffle the warning, or even to detect that this has happened.

perl should not be saying anything on the program's stderr, other than
warnings about the program, over which the program has some control.
Griping about the environment settings is damaging the program's visible
behaviour, making it effectively impossible to write a non-locale program
in Perl. And remember, locale is an opt-in system.

Depending on how important this implicit setlocale call is, perl should
either keep quiet about the failure, or treat the failure as a hard error
that prevents running the program. The automatic message about locale
setting should not precede or otherwise mix with actual program output.

perl is written in C. Every C program has an underlying locale. Thus
locale is not an opt-in setting for C, and hence it isn't for perl
either. Programs written in pure Perl appear to run in a C locale, but
if they or any module they load uses a function in the POSIX module, or
uses the backtick operator or something like system(), the underlying
locale will be exposed. There is no way the perl interpreter can know
at startup if such an event will happen.

The locale must be initialized at startup for several reasons. I too
thought it could be delayed until needed, but discovered I was wrong. I
have forgotten all the reasons, but one is so that it will be there the
first time it's needed, by say the backtick. Another is that the
environment could be changed during execution, and we want the default
locale info to be that which was in effect at initialization.

The implementors of locale anticipated your issue, and so you can turn
off the warnings by having PERL_BADLANG=0 as an environment variable at
startup (documented in perllocale).

As a side note, my default shell will warn on a bad locale for any
command run, so it's not just perl that does this​:

$ LANG=wibble date
wibble​: unknown locale
Mon Aug 8 11​:29​:28 MDT 2016

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Aug 8, 2016

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Aug 8, 2016

From zefram@fysh.org

Karl Williamson wrote​:

perl is written in C. Every C program has an underlying locale. Thus locale
is not an opt-in setting for C, and hence it isn't for perl either.

By default the locale is "C", not environmentally determined. The "C"
locale is reliably available, and yields predictable, traditional
behaviour from all locale-dependent functions. Doing anything with the
user's locale, getting unpredictable behaviour from locale-dependent
functions, and risking errors for bad environment settings, are all
opt-in matters for C code. This is the opt-in to which I was referring.

                                          or uses the backtick operator

or something like system(), the underlying locale will be exposed.

Irrelevant to this bug. Calling out to a program that may use locale
is quite a different matter from having a direct locale dependence,
and plenty of programs don't call out to other programs at all.

                      but one is so that it will be there the first time

it's needed, by say the backtick.

The backtick itself doesn't need any locale processing. The external
program has its own locale, and its own reaction to environmental settings
(locale-related and otherwise). The parent process's locale is entirely
separate from that.

So so far I'm not seeing what perl needs to select the environmental
locale for, quite apart from why it would need to gripe about failing to
select it or why gripeworthy failure would then not be fatal to running
the program.

The implementors of locale anticipated your issue, and so you can turn off
the warnings by having PERL_BADLANG=0 as an environment variable at startup

That's not under control of the program. Doesn't address this problem.

As a side note, my default shell will warn on a bad locale for any command
run, so it's not just perl that does this​:

Others getting the same thing wrong isn't an excuse.

-zefram

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant