LINUX.ORG.RU

Ошибка в работе X-сервера при деавторизации пользователя в tty

 , ,


0

1

Я использую Debian 12 (bookworm). Я не использую display manager, а вместо этого выполняю вход в систему в виртуальной консоли, после чего при необходимости запуска X-сервера использую команду startx. Впрочем, проблема возникает и на другом устройстве, где я использую display manager.

Проблема заключается в том, что если я выполнил вход ещё в одной виртуальной консоли (даже от имени другого пользователя), то при выходе из профиля в этой консоли происходит какой-то сбой, в результате чего при попытке переключиться на консоль, на которой запущен X-сервера, система перестаёт отвечать на ввод. При этом если вход/выход в другой виртуальной консоли был выполнен для root, этой проблемы не наблюдается.

Чтобы избежать проблемы с невозможностью управления системой приходится после выхода из профиля снова логиниться (например, от имени пользователя, под которым запущен X-сервер), прибивать процесс X-сервера с помощью kill и только после этого переключаться на консоль, в которой был запущен X-сервер.

Вот фрагмент логов Xserver:

502 [   664.825] (II) systemd-logind: got resume for 226:0
503 [   664.840] (II) AIGLX: Resuming AIGLX clients after VT switch
504 [   664.840] (II) intel(0): switch to mode 1024x600@60.0 on LVDS1 using pipe 1, position (0, 0
504 ), rotation normal, reflection none
505 [   664.907] (II) event4  - not using input device '/dev/input/event4'.
506 [   664.907] [dix] couldn't enable device 9
507 [   664.910] (II) event9  - not using input device '/dev/input/event9'.
508 [   664.911] [dix] couldn't enable device 10
509 [   664.917] (II) event0  - not using input device '/dev/input/event0'.
510 [   664.917] [dix] couldn't enable device 12
511 [   664.917] (--) synaptics: ETPS/2 Elantech Touchpad: touchpad found
512 [   664.917] (EE) ETPS/2 Elantech Touchpad: Read error 19
513 [   664.921] (II) systemd-logind: got resume for 13:71
514 [   664.923] (II) event7  - not using input device '/dev/input/event7'.
515 [   664.923] [dix] couldn't enable device 11
516 [   664.923] (II) systemd-logind: got resume for 13:70
517 [   664.929] (II) event6  - not using input device '/dev/input/event6'.
518 [   664.929] [dix] couldn't enable device 6
519 [   664.929] (II) systemd-logind: got resume for 13:65
520 [   664.935] (II) event1  - not using input device '/dev/input/event1'.
521 [   664.935] [dix] couldn't enable device 7
522 [   664.935] (II) systemd-logind: got resume for 13:69
523 [   664.937] (II) event5  - not using input device '/dev/input/event5'.
524 [   664.937] [dix] couldn't enable device 8

В чём может быть проблема?



Последнее исправление: nightnok (всего исправлений: 1)
Ответ на: комментарий от yars068

вывод cat /etc/os-release

PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

Ошибся при написании вопроса, уже поправил.

nightnok
() автор топика

В чём может быть проблема?

Точно не знаю, но моя рабочая гипотеза - какой-то демон (systemd, elogind) меняет права доступа к устройствам ввода при входе в виртуальную консоль. При повторном входе права выставляются для другого пользователя и первый пользователь их теряет.

LamerOk ★★★★★
()
Ответ на: комментарий от LamerOk

права выставляются для другого пользователя и первый пользователь их теряет

Хорошее предположение, но увы, проблема сохраняется даже если в обеих консолях вход выполнен от имени одного и того же пользователя. Собственно, именно в таком виде я на эту проблему изначально и наткнулся.

nightnok
() автор топика
Ответ на: комментарий от yars068

startx - скрипт в /usr/bin:

/usr/bin/startx: POSIX shell script, ASCII text executable

Содержимое /usr/bin/startx (убрал избыточные переводы строки):

#!/bin/sh

#
# This is just a sample implementation of a slightly less primitive
# interface than xinit. It looks for user .xinitrc and .xserverrc
# files, then system xinitrc and xserverrc files, else lets xinit choose
# its default. The system xinitrc should probably do things like check
# for .Xresources files and merge them in, start up a window manager,
# and pop a clock and several xterms.
#
# Site administrators are STRONGLY urged to write nicer versions.
#

unset DBUS_SESSION_BUS_ADDRESS
unset SESSION_MANAGER
userclientrc=$HOME/.xinitrc
sysclientrc=/etc/X11/xinit/xinitrc

userserverrc=$HOME/.xserverrc
sysserverrc=/etc/X11/xinit/xserverrc
defaultclient=/usr/bin/xterm
defaultserver=/usr/bin/X
defaultclientargs=""
defaultserverargs=""
defaultdisplay=""
clientargs=""
serverargs=""
vtarg=""
enable_xauth=1

# Automatically determine an unused $DISPLAY
d=0
while true ; do
    [ -e "/tmp/.X$d-lock" -o -S "/tmp/.X11-unix/X$d" ] || break
    d=$(($d + 1))
done
defaultdisplay=":$d"
unset d

whoseargs="client"
while [ x"$1" != x ]; do
    case "$1" in
    # '' required to prevent cpp from treating "/*" as a C comment.
    /''*|\./''*)
 if [ "$whoseargs" = "client" ]; then
     if [ x"$client" = x ] && [ x"$clientargs" = x ]; then
  client="$1"
     else
  clientargs="$clientargs $1"
     fi
 else
     if [ x"$server" = x ] && [ x"$serverargs" = x ]; then
  server="$1"
     else
  serverargs="$serverargs $1"
     fi
 fi
 ;;
    --)
 whoseargs="server"
 ;;
    *)
 if [ "$whoseargs" = "client" ]; then
     clientargs="$clientargs $1"
 else
     # display must be the FIRST server argument
     if [ x"$serverargs" = x ] && \
   expr "$1" : ':[0-9][0-9]*$' > /dev/null 2>&1; then
  display="$1"
     else
  serverargs="$serverargs $1"
     fi
 fi
 ;;
    esac
    shift
done

# process client arguments
if [ x"$client" = x ]; then
    client=$defaultclient

    # For compatibility reasons, only use startxrc if there were no client command line arguments
    if [ x"$clientargs" = x ]; then
        if [ -f "$userclientrc" ]; then
            client=$userclientrc
        elif [ -f "$sysclientrc" ]; then
            client=$sysclientrc
        fi
    fi
fi

# if no client arguments, use defaults
if [ x"$clientargs" = x ]; then
    clientargs=$defaultclientargs
fi

# process server arguments
if [ x"$server" = x ]; then
    server=$defaultserver

    # When starting the defaultserver start X on the current tty to avoid
    # the startx session being seen as inactive:
    # "https://bugzilla.redhat.com/show_bug.cgi?id=806491"
    tty=$(tty)
    if expr "$tty" : '/dev/tty[0-9][0-9]*$' > /dev/null; then
        tty_num=$(echo "$tty" | grep -oE '[0-9]+$')
        vtarg="vt$tty_num -keeptty"
    fi

    # For compatibility reasons, only use xserverrc if there were no server command line arguments
    if [ x"$serverargs" = x -a x"$display" = x ]; then
 if [ -f "$userserverrc" ]; then
     server=$userserverrc
 elif [ -f "$sysserverrc" ]; then
     server=$sysserverrc
 fi
    fi
fi

# if no server arguments, use defaults
if [ x"$serverargs" = x ]; then
    serverargs=$defaultserverargs
fi

# if no vt is specified add vtarg (which may be empty)
have_vtarg="no"
for i in $serverargs; do
    if expr "$i" : 'vt[0-9][0-9]*$' > /dev/null; then
        have_vtarg="yes"
    fi
done
if [ "$have_vtarg" = "no" ]; then
    serverargs="$serverargs $vtarg"
fi

# if no display, use default
if [ x"$display" = x ]; then
    display=$defaultdisplay
fi

if [ x"$enable_xauth" = x1 ] ; then
    if [ x"$XAUTHORITY" = x ]; then
        XAUTHORITY=$HOME/.Xauthority
        export XAUTHORITY
    fi

    removelist=

    # set up default Xauth info for this machine

    # check for GNU hostname
    if hostname --version > /dev/null 2>&1; then
        if [ -z "`hostname --version 2>&1 | grep GNU`" ]; then
            hostname=`hostname -f`
        fi
    fi

    if [ -z "$hostname" ]; then
        hostname=`hostname`
    fi

    authdisplay=${display:-:0}

    mcookie=`/usr/bin/mcookie`

    if test x"$mcookie" = x; then
        echo "Couldn't create cookie"
        exit 1
    fi
    dummy=0

    # create a file with auth information for the server. ':0' is a dummy.
    xserverauthfile=`mktemp --tmpdir serverauth.XXXXXXXXXX`
    trap "rm -f '$xserverauthfile'" HUP INT QUIT ILL TRAP KILL BUS TERM
    xauth -q -f "$xserverauthfile" << EOF
add :$dummy . $mcookie
EOF

    serverargs=${serverargs}" -auth "${xserverauthfile}

    # now add the same credentials to the client authority file
    # if '$displayname' already exists do not overwrite it as another
    # server may need it. Add them to the '$xserverauthfile' instead.
    for displayname in $authdisplay $hostname$authdisplay; do
        authcookie=`xauth list "$displayname" \
        | sed -n "s/.*$displayname[[:space:]*].*[[:space:]*]//p"` 2>/dev/null;
        if [ "z${authcookie}" = "z" ] ; then
            xauth -q << EOF
add $displayname . $mcookie
EOF
        removelist="$displayname $removelist"
        else
            dummy=$(($dummy+1));
            xauth -q -f "$xserverauthfile" << EOF
add :$dummy . $authcookie
EOF
        fi
    done
fi

xinit "$client" $clientargs -- "$server" $display $serverargs

retval=$?

if [ x"$enable_xauth" = x1 ] ; then
    if [ x"$removelist" != x ]; then
        xauth remove $removelist
    fi
    if [ x"$xserverauthfile" != x ]; then
        rm -f "$xserverauthfile"
    fi
fi

if command -v deallocvt > /dev/null 2>&1; then
    deallocvt
fi

exit $retval

Для полноты картины: в домашнем каталоге у меня есть .xinitrc, в котором у меня подключается файл ~/.Xresources (его использую для настройки xterm), запускается терминал и оконный менеджер:

[ -f .Xresources ] && xrdb -merge -I$HOME ~/.Xresources
xterm &
exec icewm

После запуска команды startx на шестой tty процесс X-сервера оказывается запущен командой

/usr/lib/xorg/Xorg -nolisten tcp :0 vt6 -keeptty -auth /tmp/serverauth.hO5YTouLUh
nightnok
() автор топика
9 ноября 2025 г.

Решение найдено! Проблема в том, что при завершении сеанса Bash в консоли выполняется содержимое файла ~/.bash_logout, в котором запускается clear_console. Именно clear_console и вызывает сбой X-сервера.

Такой файл отсутствовал в каталоге /root/, поэтому при выходе из root проблема не проявлялась. Однако, при создании пользователя такой файл появлялся в его домашнем каталоге, то есть, «источник» этого файла - /etc/skel/. А вот, собственно, содержимое /etc/skel/.bash_logout:

# ~/.bash_logout: executed by bash(1) when login shell exits.

# when leaving the console clear the screen to increase privacy

if [ "$SHLVL" = 1 ]; then
    [ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
fi

Решение: для каждого пользователя удалить ~/.bash_logout или закомментировать в нём вызов clear_console. Также это можно сделать с файлом /etc/skel/.bash_logout, чтобы он не появлялся в домашних каталогах создаваемых пользователей.

nightnok
() автор топика