#875989 console-setup: generated cached_setup_keyboard.sh references /tmp/ file

#875989#5
Date:
2017-09-17 00:15:12 UTC
From:
To:
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

#875989#10
Date:
2017-09-17 05:32:32 UTC
From:
To:
Hi,

GSR <gsr.bugs@infernal-iceberg.com> (2017-09-17):

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.

#875989#15
Date:
2017-09-17 06:00:17 UTC
From:
To:
Quoting Cyril Brulebois (kibi@debian.org):
updated translations, at least theoretically.

I just made the git push which I apparently forgot to do (still
happens from time to time, grrr).

#875989#20
Date:
2017-09-17 20:28:32 UTC
From:
To:
Hi,
kibi@debian.org (2017-09-17 at 0732.32 +0200):
[...]

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

#875989#25
Date:
2017-10-18 20:55:06 UTC
From:
To:
Hi,
kibi@debian.org (2017-09-17 at 0732.32 +0200):

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
#875989#30
Date:
2017-11-28 06:23:20 UTC
From:
To:
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
#875989#35
Date:
2018-01-12 17:38:18 UTC
From:
To:
tags 875989 + patch
thanks

Christian PERRIER <bubulle@debian.org> writes:

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.

#875989#42
Date:
2018-08-13 21:08:07 UTC
From:
To:
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

#875989#47
Date:
2019-01-20 09:12:57 UTC
From:
To:
bash-5.0 fixed the nanosecond timestamp compare bug.  So, in the case of
/bin/sh == /bin/bash, this will be fixed.

#875989#52
Date:
2021-11-12 14:53:01 UTC
From:
To:
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