[Pkg-kbd-devel] Bug#771161: kbd: setterm doesn't do its job when called from the kbd init script with systemd

Andreas Trottmann ftc-debbugs at intellect.uals.com
Thu Nov 27 09:02:37 UTC 2014


Package: kbd
Version: 1.15.5-2
Severity: normal

Dear Maintainer,

As reported in bug #750631, settings such as BLANK_TIME, BLANK_DPMS
and POWERDOWN_TIME in /etc/kbd/config or /etc/kbd/config.d/* are not
being applied if systemd is the current init system.

Apparently when /etc/init.d/kbd is run under systemd, there are at
least two differences from other init systems:

 - the environment variable TERM is not defined
 - standard output is not /dev/tty1

For setterm to do its job, TERM needs to be known and standard output
needs to be a terminal (to which setterm wants to apply its settings).

I have worked around the issue by modifying /etc/init.d/kbd to call setterm
like this:

        TERM=linux setterm > /dev/tty1 $setterm_args 

as seen in the modified conffile attached to this e-mail.

On a Linux system, this apparently does what I expect it to do; even
if I explicitly state /dev/tty1, the settings are valid for all of the
virtual terminals.


I don't know whether this workaround is fit to be applied in the kbd
package, or if it should be "safeguarded" by a check for "running under
a Linux kernel" or "running under systemd", or if the right thing to do
would be something entirely different.


Kind regards,

Andreas Trottmann

-- System Information:
Debian Release: jessie/sid
  APT prefers testing-updates
  APT policy: (500, 'testing-updates'), (500, 'testing')
Architecture: amd64 (x86_64)

Kernel: Linux 3.16.0-4-amd64 (SMP w/12 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages kbd depends on:
ii  libc6     2.19-13
ii  lsb-base  4.1+Debian13+nmu1

Versions of packages kbd recommends:
ii  console-setup  1.114

kbd suggests no packages.

-- Configuration Files:
/etc/init.d/kbd changed:
PKG=kbd
if [ -r /etc/$PKG/config ]; then
    . /etc/$PKG/config
fi
if [ -d /etc/$PKG/config.d ]; then
    for i in `run-parts --list /etc/$PKG/config.d `; do
       . $i
    done
fi
for vc in '' `set | grep "^.*_vc[0-9][0-9]*="  | sed 's/^.*\(_vc[0-9][0-9]*\)=.*/\1/'`
do
    eval [ '"'\${SCREEN_FONT$vc}'"' ] && eval CONSOLE_FONT$vc=\${CONSOLE_FONT$vc:-\${SCREEN_FONT$vc}}
    eval [ '"'\${SCREEN_FONT_MAP$vc}'"' ] && eval FONT_MAP$vc=\${FONT_MAP$vc:-\${SCREEN_FONT_MAP$vc}}
    eval [ '"'\${APP_CHARSET_MAP$vc}'"' ] && eval CONSOLE_MAP$vc=\${CONSOLE_MAP$vc:-\${APP_CHARSET_MAP$vc}}
done
.. /lib/lsb/init-functions
PATH=/sbin:/bin:/usr/sbin:/usr/bin
SETFONT_OPT="-v"
if which setupcon >/dev/null
then
    HAVE_SETUPCON=yes
fi
if [ -d /dev/vc ]; then
    DEVICE_PREFIX="/dev/vc/"
else
    DEVICE_PREFIX="/dev/tty"
fi
ENV_FILE=''
[ -r /etc/environment ] && ENV_FILE="/etc/environment"
[ -r /etc/default/locale ] && ENV_FILE="/etc/default/locale"
[ "$ENV_FILE" ] && CHARMAP=$(set -a && . "$ENV_FILE" && locale charmap)
if [ "$CHARMAP" = "UTF-8" -a -z "$CONSOLE_MAP" ]
then
    UNICODE_MODE=yes
fi
unicode_start_stop ()
{
    vc=$1
    if [ -n "$UNICODE_MODE" -a -z "`eval echo \\$CONSOLE_MAP_vc$vc`" ]; then
        action=unicode_start
    else
        action=unicode_stop
    fi
    if [ "${CONSOLE_FONT}" ]; then
        $action "${CONSOLE_FONT}" < ${DEVICE_PREFIX}$vc > ${DEVICE_PREFIX}$vc 2> /dev/null || true
    else
        $action < ${DEVICE_PREFIX}$vc > ${DEVICE_PREFIX}$vc 2> /dev/null || true
    fi
}
test_console () {
    local ok
    ok=0
    if which tty >/dev/null; then
        case "`tty`" in
	    /dev/tty[1-9]*|/dev/vc/[0-9]*|/dev/console|/dev/ttyv[0-9]*)
                return 0
                ;;
        esac
        ok=1
    fi
    if which kbd_mode >/dev/null; then
        mode="`(LC_ALL=C; export LC_ALL; kbd_mode) 2>&1`"
        mode=${mode#The keyboard is in }
        case "$mode" in
            Unicode*|default*|xlate*) return 0 ;;
        esac
        ok=1
    fi
    if which vidcontrol >/dev/null; then
        if vidcontrol -i adapter >&- 2>&-; then
            return 0
        fi
        ok=1
    fi
    return $ok
}
setup ()
{
    # be sure the main program is installed
    which setfont >/dev/null || return
    # drop out if we can't access the console
    test_console || return
    # start vcstime
    if [ "${DO_VCSTIME}" = "yes" ] && which vcstime >/dev/null; then
        [ "$VERBOSE" != "no" ] && log_action_begin_msg "Starting clock on text console"
        vcstime &
        [ "$VERBOSE" != "no" ] && log_action_end_msg 0
    fi
    if [ -d /etc/init ] && which initctl >/dev/null; then
	    # Upstart
	    LIST_CONSOLES=`cd /etc/init; find -name 'tty*.conf' -printf '%f ' | sed -e 's/[^0-9 ]//g'`
    elif [ -f /etc/systemd/logind.conf ] && which systemd >/dev/null; then
            # systemd
            N_CONSOLES=`sed -ne 's/#.*//; /NAutoVTs/ { s/[^0-9]//g; p }' /etc/systemd/logind.conf`
            if [ -z "$N_CONSOLES" ]; then
                N_CONSOLES=6
            fi
            LIST_CONSOLES=`seq 1 "$N_CONSOLES"`
    else
	    # traditional SysV init
	    LIST_CONSOLES=`sed -ne '/^[ \t]#/d; /tty[0-9]\+/ s/.*tty\([0-9]\+\).*/\1/ p' /etc/inittab`
    fi
    # Global default font+map
    if [ -z "${HAVE_SETUPCON}" -a "${CONSOLE_FONT}${CONSOLE_MAP}${FONT_MAP}" ]; then
        [ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting up general console font"
        sfm="${FONT_MAP}" && [ "$sfm" ] && sfm="-u $sfm"
        acm="${CONSOLE_MAP}" && [ "$acm" ] && acm="-m $acm"
    
        # Set for the first 6 VCs (as they are allocated in /etc/inittab)
        for vc in $LIST_CONSOLES
        do
            if ! ( unicode_start_stop $vc \
                   && setfont -C ${DEVICE_PREFIX}$vc ${SETFONT_OPT} $sfm ${CONSOLE_FONT} $acm )
            then
                [ "$VERBOSE" != "no" ] && log_action_end_msg 1
                break
            fi
        done
        [ "$VERBOSE" != "no" ] && log_action_end_msg 0
    fi
    # Default to Unicode mode for new VTs?
    if [ -f /sys/module/vt/parameters/default_utf8 ]; then
        if [ -n "$UNICODE_MODE" ]; then
            echo 1
        else
            echo 0
        fi > /sys/module/vt/parameters/default_utf8
    fi
    # Per-VC font+sfm
    PERVC_FONTS="`set | grep "^CONSOLE_FONT_vc[0-9]*="  | tr -d \' `"
    if [ -z "${HAVE_SETUPCON}" -a "${PERVC_FONTS}" ]; then
        [ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting up per-VC fonts"
        for font in ${PERVC_FONTS}
        do
            # extract VC and FONTNAME info from variable setting
            vc=`echo $font | cut -b16- | cut -d= -f1`
            eval font=\$CONSOLE_FONT_vc$vc
            # eventually find an associated SFM
            eval sfm=\${FONT_MAP_vc${vc}}
            [ "$sfm" ] && sfm="-u $sfm"
            if ! ( unicode_start_stop $vc \
                   && setfont -C ${DEVICE_PREFIX}$vc ${SETFONT_OPT} $sfm $font )
            then
                [ "$VERBOSE" != "no" ] && log_action_end_msg 1
                break
            fi
        done
        [ "$VERBOSE" != "no" ] && log_action_end_msg 0
    fi
    # Per-VC ACMs
    PERVC_ACMS="`set | grep "^CONSOLE_MAP_vc[0-9]*="  | tr -d \' `"
    if [ -z "${HAVE_SETUPCON}" -a "${PERVC_ACMS}" ]; then
        [ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting up per-VC ACM's"
        for acm in ${PERVC_ACMS}
          do
          # extract VC and ACM_FONTNAME info from variable setting
          vc=`echo $acm | cut -b15- | cut -d= -f1`
          eval acm=\$CONSOLE_MAP_vc$vc
          if ! setfont -C "${DEVICE_PREFIX}$vc" ${SETFONT_OPT} -m "$acm"; then
              [ "$VERBOSE" != "no" ] && log_action_end_msg 1
              break
          fi
        done
        [ "$VERBOSE" != "no" ] && log_action_end_msg 0
    fi
    
    # screensaver stuff
    setterm_args=""
    if [ "$BLANK_TIME" ]; then
        setterm_args="$setterm_args -blank $BLANK_TIME"
    fi
    if [ "$BLANK_DPMS" ]; then
        setterm_args="$setterm_args -powersave $BLANK_DPMS"
    fi
    if [ "$POWERDOWN_TIME" ]; then
        setterm_args="$setterm_args -powerdown $POWERDOWN_TIME"
    fi
    if [ "$setterm_args" ]; then
        TERM=linux setterm > /dev/tty1 $setterm_args 
    fi
    # Keyboard rate and delay
    KBDRATE_ARGS=""
    if [ -n "$KEYBOARD_RATE" ]; then
        KBDRATE_ARGS="-r $KEYBOARD_RATE"
    fi
    if [ -n "$KEYBOARD_DELAY" ]; then
        KBDRATE_ARGS="$KBDRATE_ARGS -d $KEYBOARD_DELAY"
    fi
    if [ -n "$KBDRATE_ARGS" ]; then
        [ "$VERBOSE" != "no" ] && log_action_begin_msg "Setting keyboard rate and delay"
        kbdrate -s $KBDRATE_ARGS
        [ "$VERBOSE" != "no" ] && log_action_end_msg 0
    fi
    # Inform gpm if present, of potential changes.
    if [ -f /var/run/gpm.pid ]; then
        kill -s WINCH `cat /var/run/gpm.pid` 2> /dev/null
    fi
    # Allow user to remap keys on the console
    if [ -z "${HAVE_SETUPCON}" -a -r /etc/$PKG/remap ]; then
        dumpkeys < ${DEVICE_PREFIX}1 | sed -f /etc/$PKG/remap | loadkeys --quiet
    fi
    # Set LEDS here
    if [ -n "$LEDS" ]; then
        for i in $LIST_CONSOLES
        do
            setleds -D $LEDS < $DEVICE_PREFIX$i
        done
    fi
}
case "$1" in
    start|reload|restart|force-reload)
        if [ -n "$HAVE_SETUPCON" ]
        then
                log_action_msg "Setting console screen modes"
        else
                log_action_msg "Setting console screen modes and fonts"
        fi
        setup
        ;;
    stop)
        ;;
    status)
        ;;
    *)
        setup
        ;;
esac
:


-- no debconf information



More information about the Pkg-kbd-devel mailing list