Bug 24525

Summary: LESSCHARSET set wrong by /etc/profile.d order
Product: Mageia Reporter: Arusekk K <arusekk>
Component: RPM PackagesAssignee: All Packagers <pkg-bugs>
Status: RESOLVED OLD QA Contact:
Severity: minor    
Priority: Normal CC: boulshet, freedom.unix, lists.jjorge, marja11, tmb
Version: 7   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Source RPM: initscripts-9.78-10.mga7 CVE:
Status comment:

Description Arusekk K 2019-03-18 11:37:26 CET
Description of problem:
Localized manpages, as well as everything else paged by less, gets wrong formatting when having UTF-8 content.

/etc/profile.d/20less.{,c}sh is sourced before /etc/profile.d/lang.{,c}sh

There are two possible solutions:
 * either prefix lang.{,c}sh (in initscripts) with a small number,
 * or prefix 20less.{,c}sh with a letter late enough in the alphabet.

I guess that the former is preferable, because there could be more packets out there, that could depend on locale variables set.

A workaround is to set LESSCHARSET to UTF-8 manually.

Version-Release number of selected component (if applicable):

less-550-1.mga7, initscripts-9.78-10.mga7

How reproducible:

Always

Steps to Reproduce:
1. echo $LESSCHARSET
2. It reads koi8-r instead of UTF-8
Comment 1 Marja Van Waes 2019-03-19 13:45:26 CET
(In reply to Arusekk K from comment #0)
> Description of problem:
> Localized manpages, as well as everything else paged by less, gets wrong
> formatting when having UTF-8 content.
> 
> /etc/profile.d/20less.{,c}sh is sourced before /etc/profile.d/lang.{,c}sh
> 
> There are two possible solutions:
>  * either prefix lang.{,c}sh (in initscripts) with a small number,
>  * or prefix 20less.{,c}sh with a letter late enough in the alphabet.
> 
> I guess that the former is preferable, because there could be more packets
> out there, that could depend on locale variables set.
> 

Assigning to our base system maintainers (there's no registered maintainer for less, anyway).

Source RPM: less-550-1.mga7.src.rpm => less-550-1.mga7, initscripts-9.78-10.mga7
Assignee: bugsquad => basesystem
CC: (none) => marja11

Comment 2 Arusekk K 2019-08-16 20:54:36 CEST
The bug had no attention lately, so I figured out what changed from mga6 (where there was no issues).

The patch applied to initscripts (initscripts-9.78-mgaconf.patch.xz) is lacking a rename, which happened back in mga6 (initscripts-9.55-mgaconf.patch.xz, accessible e.g. here: http://binrepo.mageia.org//ff9e8914b37e94dc4b2d1030e154c07a01828a2d ).

The diff for Makefile contained the following:

diff --git a/Makefile b/Makefile
index e8f473a..1248e67 100644
--- a/Makefile
+++ b/Makefile
@@ -23,8 +23,10 @@ install:
        install -m644  inittab $(ROOT)/etc
        install -m644  rwtab statetab networks $(ROOT)/etc
        install -m755  service $(ROOT)/usr/sbin
-       install -m644  lang.csh lang.sh $(ROOT)/etc/profile.d
-       install -m644  256term.csh 256term.sh $(ROOT)/etc/profile.d
+       install -m644  lang.csh $(ROOT)/etc/profile.d/10lang.csh
+       install -m644  lang.sh $(ROOT)/etc/profile.d/10lang.sh
+       install -m644  256term.csh $(ROOT)/etc/profile.d/10term256.csh
+       install -m644  256term.sh $(ROOT)/etc/profile.d/10term256.sh
        install -m644  debug.csh debug.sh $(ROOT)/etc/profile.d
        install -m755  sys-unconfig $(ROOT)/usr/sbin
        install -m644  service.8 sys-unconfig.8 $(ROOT)$(mandir)/man8

Adding that part back solves the problem entirely.
Comment 3 Arusekk K 2019-09-23 22:09:19 CEST
Fixed in revision 1444878, please update mga7 package.

Status: NEW => RESOLVED
Resolution: (none) => FIXED

Comment 4 Marja Van Waes 2019-09-24 07:08:00 CEST
(In reply to Arusekk K from comment #3)
> Fixed in revision 1444878, please update mga7 package.

Reopening for Mageia 7

Thanks, Zézinho, for fixing this in Cauldron :-)

CC: (none) => lists.jjorge
Resolution: FIXED => (none)
Version: Cauldron => 7
Status: RESOLVED => REOPENED
Source RPM: less-550-1.mga7, initscripts-9.78-10.mga7 => initscripts-9.78-10.mga7

Comment 5 José Jorge 2019-09-24 07:56:26 CEST
initscripts-9.78-10.1.mga7 pushed to testing.

Assignee: basesystem => lists.jjorge

Comment 6 Arusekk K 2019-09-29 09:49:59 CEST
initscripts-9.78-10.1.mga7 resolves the issue for Mageia 7
Comment 7 Arusekk K 2019-09-29 11:38:32 CEST
Advisory:
========================

Unicode text (e.g. localized manpages) is displayed scattered by `less`.
Possibly more issues connected to complex localization.

Update initscripts and reload environment variables (or just reboot) to fix the issue.

========================

Packages in 7/core/updates_testing:
========================
initscripts-9.78-10.1.mga7.x86_64.rpm

Source RPM:
========================
initscripts-9.78-10.1.mga7.src.rpm

Keywords: (none) => advisory

Comment 8 GG HH 2019-10-05 19:12:21 CEST
There are additional issues caused by this fix: several issue in boot scripts as 
lang.sh hardcoded in several scripts which were not updated while lang.sh was renamed as 10lang.sh

$ systemctl --state=failed --no-legend
ip6tables.service  loaded failed failed iptables Firewall for IPv6                    
msec.service       loaded failed failed LSB: Enables MSEC security policy on boot     
network.service    loaded failed failed LSB: Bring up/down networking                 
partmon.service    loaded failed failed LSB: Checks if a partition is close to full up
postfix.service    loaded failed failed LSB: Starts the postfix daemons               
resolvconf.service loaded failed failed LSB: Nameserver information manager   

$ rpm -q -f /etc/init.d/functions /etc/profile.d/*lang.sh
initscripts-9.78-11.mga8
initscripts-9.78-11.mga8

$ rpm -q --changelog initscripts |head -3
* lun. sept. 23 2019 zezinho <zezinho> 9.78-11.mga8
+ Revision: 1444878
- apply mga6 change to fix mga#24525

https://bugs.mageia.org/show_bug.cgi?id=24525

$ grep -r /lang.sh /etc/
/etc/rc.d/init.d/functions:    . /etc/profile.d/lang.sh 2>/dev/null
/etc/X11/xinit/XIM:if [ -f /etc/profile.d/lang.sh ];then
/etc/X11/xinit/XIM:. /etc/profile.d/lang.sh
/etc/X11/Xsession:if [ -f /etc/profile.d/lang.sh ]; then
/etc/X11/Xsession:. /etc/profile.d/lang.sh
/etc/profile.d/10lang.sh:# /etc/profile.d/lang.sh - set i18n stuff

Thanks

CC: (none) => boulshet

Comment 9 Thomas Backlund 2019-10-09 22:23:47 CEST
I have reverted the broken fix in cauldron and nuked it from Mga7 updates_testing until it's properly fixed.

Keywords: advisory => (none)
CC: (none) => tmb

Comment 10 diaphane d. 2019-12-14 03:21:19 CET
(In reply to Arusekk K from comment #0)

There is a third solution: don't set LESSCHARSET variable when locales are unknown (quick fix for less-XXX.mga7 package without change in initscripts package).
LESSCHARSET is required for few cases only, and absence of this variable is probably better than a wrong value.

$ LESSCHARSET= man less
"(...)
If neither LESSCHARSET nor LESSCHARDEF is set, but any of the strings "UTF-8", "UTF8", "utf-8" or "utf8" is found in the LC_ALL, LC_CTYPE or LANG environment variables, then the default character set is utf-8.

If that string is not found, but your system supports the setlocale interface, less will use setlocale to determine the character set. setlocale is controlled by setting the LANG or LC_CTYPE environment variables.

Finally, if the setlocale interface is also not available, the default character set is latin1.
(...)"


$ cat /etc/profile.d/20less.sh
CHARSET=$(locale charmap 2> /dev/null) 
case "$CHARSET" in 
       UTF-8) 
               export LESSCHARSET="${LESSCHARSET:-utf-8}" 
       ;; 
       * ) 
               export LESSCHARSET="${LESSCHARSET:-koi8-r}" 
       ;; 
esac
# Make a filter for less
export LESSOPEN="|/usr/bin/lesspipe.sh %s"
$ 


Currently /etc/profile.d/20less.{,c}sh default to Russian character set when something goes wrong.
We should replace the "case esac" part with something like that :
case "$CHARSET" in
       UTF-8) export LESSCHARSET="${LESSCHARSET:-utf-8}" ;;
       KOI8-R|KOI8-U) export LESSCHARSET="${LESSCHARSET:-koi8-r}" ;;
       *) ;;
esac


For information, 10lang.sh is hardcoded in scripts too.
# grep -r /10lang.sh /etc/
/etc/X11/xinit/fixkeyboard:[ -x /etc/profile.d/10lang.sh ] && . /etc/profile.d/10lang.sh
# rpm -qf /etc/X11/xinit/fixkeyboard
xinitrc-2.4.21-28.mga7

CC: (none) => freedom.unix

Manuel Hiebel 2021-03-04 22:10:11 CET

Assignee: lists.jjorge => pkg-bugs

Comment 11 Aurelien Oudelet 2021-07-06 13:14:08 CEST
Mageia 7 is EOL since July 1st 2021.
There will not have any further bugfix for this release.

You are encouraged to upgrade to Mageia 8 as soon as possible.

@reporter, if this bug still apply with Mageia 8, please let us know it.

@packager, if you work on the Mageia 7 version of your package, please check the Mageia 8 package if issue is also present. In this case, please fix the Mageia 8 version instead.

This bug report will be closed OLD if there is no further notice within 1st September 2021.
Comment 12 Marja Van Waes 2021-09-07 14:09:30 CEST
Hi bug reporter and hi assignee and others involved,

Please reopen this bug report if it is still valid for Mageia 8 or 9(cauldron), and change "Version:" in the upper left of this report accordingly.

This report is being closed as OLD because it was filed against Mageia 7, for which  support ended on June 30th 2021.

Thanks,
Marja

Status: REOPENED => RESOLVED
Resolution: (none) => OLD