Bug#1021515: tex-common: user locale settings can cause postinst to fail

2022-10-10 Thread Norbert Preining
>if LANG=C LC_ALL=C $FMTUTIL "$@" > $tempfile 2>&1 ; then 

That is indeed better, thanks. Committed.

Norbert

--
PREINING Norbert  https://www.preining.info
Mercari Inc. + IFMGA Guide + TU Wien + TeX Live
GPG: 0x860CDC13   fp: F7D8 A928 26E3 16A1 9FA0 ACF0 6CAC A448 860C DC13



Bug#1021515: tex-common: user locale settings can cause postinst to fail

2022-10-10 Thread Stuart Prescott
Hi Norbert

On Monday, 10 October 2022 17:44:56 AEDT Norbert Preining wrote:
> @@ -76,11 +76,14 @@ dhit_build_format ()
>  tempfile=$(mktemp -p /tmp fmtutil.)
>  # save LANG
>  LANGSAVE=$LANG
> +LCALLSAVE=$LCALLSAVE
>  LANG=C
> +LC_ALL=C
>  printf "Building format(s) $*.\n\tThis may take some time... "
>  if $FMTUTIL "$@" > $tempfile 2>&1 ; then
>  rm -f $tempfile
>  LANG=$LANGSAVE
> +LC_ALL=$LCALLSAVE
>  echo "done."
>  else
>  exec >&2

almost -- LC_ALL needs to be exported too, otherwise it won't get passed to 
the child process unless it already happens to be exported, and it isn't 
exported in my environment. LANG should probably also be exported.

Alternatively, the temporary environment setting could go into the "if" 
statement with no need for the saving, exporting, and undoing steps. The 
environment modification is only needed for the fmutil call, not the other 
steps:

   tempfile=$(mktemp -p /tmp fmtutil.)
   printf "Building format(s) $*.\n\tThis may take some time... " 
   if LANG=C LC_ALL=C $FMTUTIL "$@" > $tempfile 2>&1 ; then 
   rm -f $tempfile 
   echo "done." 
   else
[... etc ...]


regards
Stuart

-- 
Stuart Prescotthttp://www.nanonanonano.net/   stu...@nanonanonano.net
Debian Developer   http://www.debian.org/ stu...@debian.org
GPG fingerprint90E2 D2C1 AD14 6A1B 7EBB 891D BBC1 7EBB 1396 F2F7



Bug#1021515: tex-common: user locale settings can cause postinst to fail

2022-10-10 Thread Norbert Preining
Hi Stuart,

thanks for testing ... indeed LC_ALL .. so something like this?
@@ -76,11 +76,14 @@ dhit_build_format ()
 tempfile=$(mktemp -p /tmp fmtutil.)
 # save LANG
 LANGSAVE=$LANG
+LCALLSAVE=$LCALLSAVE
 LANG=C
+LC_ALL=C
 printf "Building format(s) $*.\n\tThis may take some time... "
 if $FMTUTIL "$@" > $tempfile 2>&1 ; then
 rm -f $tempfile
 LANG=$LANGSAVE
+LC_ALL=$LCALLSAVE
 echo "done."
 else
 exec >&2

should do the trick I guess.

Will put it into git, and Hilmar will probably upload it at some point.

Regards

Norbert

On Mon, 10 Oct 2022, Stuart Prescott wrote:
> Setting LC_ALL=C seems to be an adequate workaround as that overrides all 
> LC_* 
> environment variables in one step.

--
PREINING Norbert  https://www.preining.info
Mercari Inc. + IFMGA Guide + TU Wien + TeX Live
GPG: 0x860CDC13   fp: F7D8 A928 26E3 16A1 9FA0 ACF0 6CAC A448 860C DC13



Bug#1021515: tex-common: user locale settings can cause postinst to fail

2022-10-10 Thread Stuart Prescott
Hi Norbert,

On Monday, 10 October 2022 16:23:25 AEDT Norbert Preining wrote:
> What happens if you only feed LANG=C? Does it break?

LANG=C seems to make no difference to solving the problem (it's already 
protected in the code as you say), likewise LANGUAGE=C makes no difference. 
The only other LC_* item I have in my environment is LC_TIME and setting that 
to LC_TIME=C solves the issue. 

> I am just wondering what other locale vars are necessary, back then
> we thought (and it worked bakc then) that LANG is enough.

LC_TIME seems to fix it - details below - I'm not sure if it's just because 
LC_TIME is special to fmutil in some way or if other LC_* would also break it.

Setting LC_ALL=C seems to be an adequate workaround as that overrides all LC_* 
environment variables in one step.

To help, a reproducer below.

cheers
Stuart


# current locale-relevant environment:
LANG=en_AU.UTF-8
LANGUAGE=en_AU:en
LC_TIME=en_GB.UTF-8

# full locale
$ locale
LANG=en_AU.UTF-8
LANGUAGE=en_AU:en
LC_CTYPE="en_AU.UTF-8"
LC_NUMERIC="en_AU.UTF-8"
LC_TIME=en_GB.UTF-8
LC_COLLATE="en_AU.UTF-8"
LC_MONETARY="en_AU.UTF-8"
LC_MESSAGES="en_AU.UTF-8"
LC_PAPER="en_AU.UTF-8"
LC_NAME="en_AU.UTF-8"
LC_ADDRESS="en_AU.UTF-8"
LC_TELEPHONE="en_AU.UTF-8"
LC_MEASUREMENT="en_AU.UTF-8"
LC_IDENTIFICATION="en_AU.UTF-8"
LC_ALL=


$ sudo env http_proxy=http://localhost:3142/ debootstrap --arch=amd64 --
variant=minbase bookworm /srv/chroots/tmp/bookworm http://deb.debian.org/
debian

$ cat /etc/schroot/chroot.d/bookworm-1021515 
[bookworm-1021515]
description=Debian bookworm (testing)
type=directory
directory=/srv/chroots/tmp/bookworm
users=stuart
root-users=stuart
profile=desktop

# I'm letting schroot preserve the environment (-p) here, that's deliberate
# to provoke the bug. Perl also bleats about this icky configuration but it's
# non-fatal.

$ schroot -c bookworm-1021515 -p -q -u root -- apt install --no-install-
recommends texlive-base
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
[...]
Do you want to continue? [Y/n] 
[...]
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = "en_AU:en",
LC_ALL = (unset),
LC_TIME = "en_GB.UTF-8",
LANG = "en_AU.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
debconf: delaying package configuration, since apt-utils is not installed
[...]
Setting up texlive-base (2022.20220722-1) ...
mktexlsr: Updating /var/lib/texmf/ls-R-TEXLIVEDIST... 
mktexlsr: Updating /var/lib/texmf/ls-R-TEXMFMAIN... 
mktexlsr: Updating /var/lib/texmf/ls-R... 
mktexlsr: Done.
tl-paper: setting paper size for dvips to a4: /var/lib/texmf/dvips/config/
config-paper.ps
tl-paper: setting paper size for dvipdfmx to a4: /var/lib/texmf/dvipdfmx/
dvipdfmx-paper.cfg
tl-paper: setting paper size for xdvi to a4: /var/lib/texmf/xdvi/XDvi-paper
tl-paper: setting paper size for pdftex to a4: /var/lib/texmf/tex/generic/tex-
ini-files/pdftexconfig.tex
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based 
frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 
78.)
debconf: falling back to frontend: Readline
Processing triggers for tex-common (6.17) ...
debconf: unable to initialize frontend: Dialog
debconf: (No usable dialog-like program is installed, so the dialog based 
frontend cannot be used. at /usr/share/perl5/Debconf/FrontEnd/Dialog.pm line 
78.)
debconf: falling back to frontend: Readline
Running mktexlsr. This may take some time... done.
Running updmap-sys. This may take some time... done.
Running mktexlsr /var/lib/texmf ... done.
Building format(s) --all.
This may take some time... 
fmtutil failed. Output has been stored in
/tmp/fmtutil.jbVdJmwu
Please include this file if you report a bug.

dpkg: error processing package tex-common (--configure):
 installed tex-common package post-installation script subprocess returned 
error exit status 1
Errors were encountered while processing:
 tex-common
E: Sub-process /usr/bin/dpkg returned an error code (1)



# Poking at a few environment variables to see what the response would be
# follows. In turn, 
# - apt -f install  [fails]
# - LANG=C apt -f install   [fails]
# - LANGUAGE=C apt -f install   [fails]
# - LANG=C LANGUAGE=C apt -f install[fails]
# - LC_TIME=C apt -f install[works]
# - LC_ALL=C apt -f install [works]





(bookworm-1021515)root@simurgh:/# apt -f install   
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
perl: 

Bug#1021515: tex-common: user locale settings can cause postinst to fail

2022-10-09 Thread Norbert Preining
Hi Stuart,

> The postinst for tex-common is sensitive to the locale settings from the

Hmm, interesting ...

> $ luahbtex -ini   -jobname=luahbtex -progname=luahbtex luatex.ini  Unable to read environment locale: exit now.

We do set LANG=C already before running fmtutil, so I am surprised that
there is still something bad happening.


> Feeding in some environment variables to see if I could convince it to

What happens if you only feed LANG=C? Does it break?

Looking at the code, maybe we forgot to export LANG since it might not
be defined by now. As of now the code runs:

LANGSAVE=$LANG
LANG=C
printf "Building format(s) $*.\n\tThis may take some time... "
if $FMTUTIL "$@" > $tempfile 2>&1 ; then

LANG normally is already marked as export, but maybe in your particular
case it was unset, and thus not marked as to be exported.

Can you also do an experiment by adding
export LANG
to /var/lib/dpkg/info/tex-common.postinst (AFAIR, not on Debian) after
setting it to LANG=C, and see if that helps.

> $ LANG=C LANGUAGE=C LC_CTYPE=C LC_NUMERIC=C LC_TIME=C LC_COLLATE=C 
> LC_MONETARY=C LC_MESSAGES=C LC_PAPER=C LC_NAME=C LC_ADDRESS=C luahbtex -ini   
> -jobname=luahbtex -progname=luahbtex luatex.ini  bash: warning: setlocale: LC_COLLATE: cannot change locale (en_AU.UTF-8)

That is indeed strange and I cannot reproduce it.

> Installing the 'locales' package and correctly configuring it to the
> locales that were in the environment was also enough.

It should not be necessary, and in fact will create problems later on.

> particular locale required. Adding some locale overrides to the postinst
> would be better, but it might mean that users do not get error messages
> displayed to them in their preferred language.

The locale variables are set for the fmtutil run only, and none of the
programs involved is localized, so there is no change.

I am just wondering what other locale vars are necessary, back then
we thought (and it worked bakc then) that LANG is enough.

Regards

Norbert

--
PREINING Norbert  https://www.preining.info
Mercari Inc. + IFMGA Guide + TU Wien + TeX Live
GPG: 0x860CDC13   fp: F7D8 A928 26E3 16A1 9FA0 ACF0 6CAC A448 860C DC13



Bug#1021515: tex-common: user locale settings can cause postinst to fail

2022-10-09 Thread Stuart Prescott
Package: tex-common
Version: 6.17
Severity: normal
X-Debbugs-Cc: stu...@debian.org

Dear Maintainer,

The postinst for tex-common is sensitive to the locale settings from the
environment and so can fail in strange ways. Users can end up with odd
locale settings in a chroot (as I did, where my login environment had
leaked into the chroot but the specified locale was not installed), when
connecting over ssh (the remote system's locale settings are applied to
the remote session), or through simple misconfiguration.

While the particularly odd locale seettings that I had in the chroot were
my fault, the postinst should be robust to such failures.

- 8< -
Setting up tex-common (6.17) ...
debconf: falling back to frontend: Readline
Running mktexlsr. This may take some time... done.
Running updmap-sys. This may take some time... done.
Running mktexlsr /var/lib/texmf ... done.
Building format(s) --all.
This may take some time...
fmtutil failed. Output has been stored in
/tmp/fmtutil.YvPIYmjZ
Please include this file if you report a bug.

dpkg: error processing package tex-common (--configure):
 installed tex-common package post-installation script subprocess returned 
error exit status 1
- 8< -

The log file mentioned ends with the following lines:
- 8< -
fmtutil [ERROR]: running `luahbtex -ini   -jobname=luahbtex -progname=luahbtex 
luatex.ini From a Debian perspective, tex-common depending on the locales package is
not a nice thing to do; it's also not sufficient to solve this bug, since
installing the locales package is not the same as configuring the
particular locale required. Adding some locale overrides to the postinst
would be better, but it might mean that users do not get error messages
displayed to them in their preferred language.

regards
Stuart