Discussion:
Bug#875989: console-setup: generated cached_setup_keyboard.sh references /tmp/ file
(too old to reply)
GSR
2017-09-17 00:50:01 UTC
Permalink
Package: console-setup
Version: 1.167
Severity: normal

Updated from 166 to 167 and when verifying changes in /etc/ noticed
there was only one change, in console-setup/cached_setup_keyboard.sh:

---8<---
-loadkeys '/etc/console-setup/cached_UTF-8_del.kmap.gz' > '/dev/null'
+loadkeys '/tmp/tmpkbd.31u83e' > '/dev/null'
--->8---

File in /tmp/, named tmpkbd and with (random) extension that looks
like one from mktemp? And before it was a file in /etc/ with
understable name? Suspicious.

Running the script by hand returns the obvious "cannot open file
/tmp/tmpkbd.31u83e" while calling the other version of loadkeys
invocation works fine.

Prediction is that in next boot it will complain too and require
manually calling with the proper kmap file.

Also while tracking the calls for boot sequence, found that usage line
for /etc/init.d/keyboard-setup.sh and console-setup.sh forgot the .sh
extension (two mount*.sh forgot the extension too, but that would be
for another report). Most scripts properly report their name with .sh
and one even just uses $0 so it reacts automatically to however it was
called. Minor cosmetic details.

Thanks,
GSR


-- System Information:
Debian Release: buster/sid
APT prefers unstable
APT policy: (500, 'unstable'), (500, 'testing'), (1, 'experimental')
Architecture: amd64 (x86_64)

Kernel: Linux 4.11.0-2-amd64 (SMP w/8 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8), LANGUAGE=en_GB:en (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Init: sysvinit (via /sbin/init)

Versions of packages console-setup depends on:
ii console-setup-linux 1.167
ii debconf 1.5.62
ii keyboard-configuration 1.167
ii xkb-data 2.5.1-3

console-setup recommends no packages.

Versions of packages console-setup suggests:
ii locales 2.24-17
ii lsb-base 9.20170808

Versions of packages keyboard-configuration depends on:
ii debconf 1.5.62
ii liblocale-gettext-perl 1.07-3+b3

Versions of packages console-setup-linux depends on:
ii init-system-helpers 1.49
ii initscripts 2.88dsf-59.9
ii kbd 1.15.5-1
ii keyboard-configuration 1.167

console-setup-linux suggests no packages.

Versions of packages console-setup is related to:
pn console-common <none>
pn console-data <none>
pn console-tools <none>
pn gnome-control-center <none>
ii kbd 1.15.5-1

-- debconf information:
keyboard-configuration/store_defaults_in_debconf_db: true
* keyboard-configuration/altgr: Right Alt (AltGr)
console-setup/use_system_font:
* console-setup/fontface47: Fixed
keyboard-configuration/layoutcode: es
keyboard-configuration/xkb-keymap: es
console-setup/codesetcode: Lat15
keyboard-configuration/other:
keyboard-configuration/layout:
console-setup/framebuffer_only:
keyboard-configuration/unsupported_layout: true
console-setup/fontsize-text47: 8x16
console-setup/codeset47: # Latin1 and Latin5 - western Europe and Turkic languages
* console-setup/fontsize-fb47: 8x16
keyboard-configuration/toggle: No toggling
keyboard-configuration/switch: No temporary switch
* keyboard-configuration/compose: Menu key
keyboard-configuration/optionscode: lv3:ralt_switch,compose:menu,terminate:ctrl_alt_bksp
keyboard-configuration/modelcode: pc105
keyboard-configuration/variantcode:
keyboard-configuration/unsupported_config_options: true
console-setup/guess_font:
* keyboard-configuration/model: Generic 105-key (Intl) PC
debian-installer/console-setup-udeb/title:
* keyboard-configuration/variant: Spanish
console-setup/store_defaults_in_debconf_db: true
keyboard-configuration/unsupported_options: true
* keyboard-configuration/ctrl_alt_bksp: true
console-setup/charmap47: UTF-8
console-setup/fontsize: 8x16
keyboard-configuration/unsupported_config_layout: true
Cyril Brulebois
2017-09-17 05:40:02 UTC
Permalink
Hi,
Post by GSR
Package: console-setup
Version: 1.167
Severity: normal
Updated from 166 to 167 and when verifying changes in /etc/ noticed
---8<---
-loadkeys '/etc/console-setup/cached_UTF-8_del.kmap.gz' > '/dev/null'
+loadkeys '/tmp/tmpkbd.31u83e' > '/dev/null'
--->8---
File in /tmp/, named tmpkbd and with (random) extension that looks
like one from mktemp? And before it was a file in /etc/ with
understable name? Suspicious.
Running the script by hand returns the obvious "cannot open file
/tmp/tmpkbd.31u83e" while calling the other version of loadkeys
invocation works fine.
Prediction is that in next boot it will complain too and require
manually calling with the proper kmap file.
Also while tracking the calls for boot sequence, found that usage line
for /etc/init.d/keyboard-setup.sh and console-setup.sh forgot the .sh
extension (two mount*.sh forgot the extension too, but that would be
for another report). Most scripts properly report their name with .sh
and one even just uses $0 so it reacts automatically to however it was
called. Minor cosmetic details.
It seems there were no functional changes between both versions, only
translation updates plus an extra CHANGES file (which looks like the
last changelog entry). BTW, Christian, a git push seems to be missing.

If you want to check the behaviour, see $savekbdfile and $TMPFILE in the
setupcon script.


KiBi.
Christian PERRIER
2017-09-17 06:10:02 UTC
Permalink
Post by Cyril Brulebois
It seems there were no functional changes between both versions, only
translation updates plus an extra CHANGES file (which looks like the
last changelog entry). BTW, Christian, a git push seems to be missing.
I confirm: this last upload was just a rebuild to include a few
updated translations, at least theoretically.

I just made the git push which I apparently forgot to do (still
happens from time to time, grrr).
Göran Weinholt
2018-01-12 18:10:02 UTC
Permalink
tags 875989 + patch
thanks
Post by Christian PERRIER
Post by Cyril Brulebois
It seems there were no functional changes between both versions, only
translation updates plus an extra CHANGES file (which looks like the
last changelog entry). BTW, Christian, a git push seems to be missing.
I confirm: this last upload was just a rebuild to include a few
updated translations, at least theoretically.
I ran into this bug today when upgrading from console-setup 1.174 to
1.175. The analysis provided by OGAWA Hirofumi seems pretty accurate,
the timestamps are triggering the bug.

Here's one way to reproduce it:

industria:~# touch -d "2018-01-12 17:04:43.280045766 +0100" /etc/default/console-setup
industria:~# touch -d "2018-01-12 17:04:38.812013996 +0100" /etc/default/keyboard
industria:~# touch -d "2018-01-12 17:04:43.464047075 +0100" /etc/console-setup/cached_UTF-8_del.kmap.gz
industria:~# /bin/setupcon -k --print-commands-only
kbd_mode '-u' < '/dev/tty1'
kbd_mode '-u' < '/dev/tty2'
kbd_mode '-u' < '/dev/tty3'
kbd_mode '-u' < '/dev/tty4'
kbd_mode '-u' < '/dev/tty5'
kbd_mode '-u' < '/dev/tty6'
loadkeys '/tmp/tmpkbd.jJa1Rj' > '/dev/null'

Updating the timestamp on the cache file makes the problem go away:

industria:~# touch /etc/console-setup/cached_UTF-8_del.kmap.gz
industria:~# /bin/setupcon -k --print-commands-only
kbd_mode '-u' < '/dev/tty1'
kbd_mode '-u' < '/dev/tty2'
kbd_mode '-u' < '/dev/tty3'
kbd_mode '-u' < '/dev/tty4'
kbd_mode '-u' < '/dev/tty5'
kbd_mode '-u' < '/dev/tty6'
loadkeys '/etc/console-setup/cached_UTF-8_del.kmap.gz' > '/dev/null'

After applying the patch, setupcon is working as expected again.
--
Göran Weinholt <***@weinholt.se>
73 de SA6CJK
GSR
2017-09-17 21:10:02 UTC
Permalink
Hi,
Post by Cyril Brulebois
Post by GSR
Package: console-setup
Version: 1.167
Severity: normal
Updated from 166 to 167 and when verifying changes in /etc/ noticed
---8<---
-loadkeys '/etc/console-setup/cached_UTF-8_del.kmap.gz' > '/dev/null'
+loadkeys '/tmp/tmpkbd.31u83e' > '/dev/null'
--->8---
File in /tmp/, named tmpkbd and with (random) extension that looks
like one from mktemp? And before it was a file in /etc/ with
understable name? Suspicious.
[...]
Post by Cyril Brulebois
It seems there were no functional changes between both versions, only
translation updates plus an extra CHANGES file (which looks like the
last changelog entry). BTW, Christian, a git push seems to be missing.
The diff above is what etckeeper commited when upgrading
console-setup, console-setup-linux and keyboard-configuration, all
from 1.166 to 1.167. And there have been previous commits, so it
wasn't something pending from way past, it took place in the upgrade.

Also, as predicted, "cannot open file /tmp/tmpkbd.31u83e" appeared on
boot, yet mapping looked OK. Anyway, I invoked the other loadkeys by
hand to be sure.

After reading the man page, I decided to run "setupcon --save-only" by
hand... and now the file is back to sane value. Uh!? A bit flipped
during upgrade and naming choice got mangled?

GSR
GSR
2017-10-18 21:00:02 UTC
Permalink
Hi,
Post by Cyril Brulebois
It seems there were no functional changes between both versions, only
translation updates plus an extra CHANGES file (which looks like the
last changelog entry). BTW, Christian, a git push seems to be missing.
Updated 1.167 to 1.169 and it did it again. So "flipped bit that has
barely valid outcome without crashing" is now out of question, too
much concidence.

---8<---
-loadkeys '/etc/console-setup/cached_UTF-8_del.kmap.gz' > '/dev/null'
+loadkeys '/tmp/tmpkbd.V1Nv35' > '/dev/null'
--->8---

Running manually "setupcon --save-only" fixes it. :-?

---8<---
-loadkeys '/tmp/tmpkbd.V1Nv35' > '/dev/null'
+loadkeys '/etc/console-setup/cached_UTF-8_del.kmap.gz' > '/dev/null'
--->8---

Cheers,
GSR
OGAWA Hirofumi
2017-11-28 06:50:01 UTC
Permalink
Hi,

I got same issue with this bug, and checked the details of bug.

# stat /etc/console-setup/cached_ISO-8859-1_del.kmap.gz
File: /etc/console-setup/cached_ISO-8859-1_del.kmap.gz
Size: 4793 Blocks: 16 IO Block: 4096 regular file
Device: 801h/2049d Inode: 18350479 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-01-29 19:32:33.001665826 +0900
Modify: 2017-11-28 14:10:18.621974890 +0900
Change: 2017-11-28 14:10:18.621974890 +0900
Birth: -

# stat /etc/default/console-setup
File: /etc/default/console-setup
Size: 281 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 18350186 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-11-28 14:10:18.009968364 +0900
Modify: 2017-11-28 14:10:18.005968321 +0900
Change: 2017-11-28 14:10:18.005968321 +0900
Birth: -

Here is timestamps of some of affected files. Like above, FS is using
nanoseconds timestamp, and cached is newer than config file
(/etc/default/console-setup) as expected.

But the issue in bash,

# if [ /etc/default/console-setup -ot /etc/console-setup/cached_ISO-8859-1_del.kmap.gz ]; then echo yes; else echo no; fi
no

On debian, bash is not compiled with nanoseconds support (this seems be
the bug of bash). So, if same timestamp in seconds resolution, setupcon
confuses like the following log.

+ '[' -z '' -a -f /etc/console-setup/cached_ISO-8859-1_del.kmap.gz ']'
+ '[' /etc/default/keyboard -ot /etc/console-setup/cached_ISO-8859-1_del.kmap.gz -a /etc/default/console-setup -ot /etc/console-setup/cached_ISO-8859-1_del.kmap .gz ']'
+ '[' '' ']'
+ tempfile
++ mktemp /tmp/tmpkbd.XXXXXX
+ TMPFILE=/tmp/tmpkbd.kmP7z9
+ tempfiles=' /tmp/tmpkbd.kmP7z9'

So, my suggestion to fix this bug, choose the cached file if same
timestamp, not only older. With this patch, seems to be working as
expected in my case (if console-setup and cached_* was updated within
same second).

Thanks.

--- setupcon~ 2017-11-28 14:33:16.030927321 +0900
+++ setupcon 2017-11-28 15:05:46.735112236 +0900
@@ -1121,9 +1121,12 @@ if [ "$do_kbd" = linux ]; then
fi
fi

+# If timestamp is same, use cached
if \
- [ -z "$KMAP" -a -f "$cached" ] \
- && [ "$CONFIG" -ot "$cached" -a "$CONFIG2" -ot "$cached" ]
+ [ -z "$KMAP" ] \
+ && [ -f "$cached" ] \
+ && [ ! "$cached" -ot "$CONFIG" ] \
+ && [ ! "$cached" -ot "$CONFIG2" ]
then
KMAP="$cached"
fi
--
OGAWA Hirofumi <***@mail.parknet.co.jp>
Holger Mickler
2018-08-13 21:10:02 UTC
Permalink
Hi there,

the bug also exists in current stable release stretch (console-setup ver 1.164).

$ dpkg -l console-setup
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version
Architecture Description
+++-=========================================-=========================-=========================-========================================================================================
ii console-setup 1.164 all
console font and keymap setup program


It will be triggered by running "dpkg-reconfigure console-setup":


$ cat /etc/console-setup/cached_setup_keyboard.sh
#!/bin/sh

if [ -f /run/console-setup/keymap_loaded ]; then
rm /run/console-setup/keymap_loaded
exit 0
fi
kbd_mode '-u' < '/dev/tty1'
kbd_mode '-u' < '/dev/tty2'
kbd_mode '-u' < '/dev/tty3'
kbd_mode '-u' < '/dev/tty4'
kbd_mode '-u' < '/dev/tty5'
kbd_mode '-u' < '/dev/tty6'
loadkeys '/etc/console-setup/cached_UTF-8_del.kmap.gz' > '/dev/null'

$ dpkg-reconfigure console-setup

$ cat /etc/console-setup/cached_setup_keyboard.sh
#!/bin/sh

if [ -f /run/console-setup/keymap_loaded ]; then
rm /run/console-setup/keymap_loaded
exit 0
fi
kbd_mode '-u' < '/dev/tty1'
kbd_mode '-u' < '/dev/tty2'
kbd_mode '-u' < '/dev/tty3'
kbd_mode '-u' < '/dev/tty4'
kbd_mode '-u' < '/dev/tty5'
kbd_mode '-u' < '/dev/tty6'
loadkeys '/tmp/tmpkbd.mIOxhT' > '/dev/null'

$ setupcon --save-only

$ cat /etc/console-setup/cached_setup_keyboard.sh
#!/bin/sh

if [ -f /run/console-setup/keymap_loaded ]; then
rm /run/console-setup/keymap_loaded
exit 0
fi
kbd_mode '-u' < '/dev/tty1'
kbd_mode '-u' < '/dev/tty2'
kbd_mode '-u' < '/dev/tty3'
kbd_mode '-u' < '/dev/tty4'
kbd_mode '-u' < '/dev/tty5'
kbd_mode '-u' < '/dev/tty6'
loadkeys '/etc/console-setup/cached_UTF-8_del.kmap.gz' > '/dev/null'


Regards,
Holger
OGAWA Hirofumi
2019-01-20 09:40:01 UTC
Permalink
bash-5.0 fixed the nanosecond timestamp compare bug. So, in the case of
/bin/sh == /bin/bash, this will be fixed.
--
OGAWA Hirofumi <***@mail.parknet.co.jp>
Matthieu Weber
2021-11-12 15:10:03 UTC
Permalink
I'm running Bullseye, and the bug is still present, despite having bash
5.

$ cat /etc/debian_version
11.1

$ dpkg -l console-setup bash
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-============-============-=====================================
ii bash 5.1-2+b3 amd64 GNU Bourne Again SHell
ii console-setup 1.205 all console font and keymap setup program
--
Matthieu
Loading...