ef44dbe331
is empty or not [1] Add addition way to find the ttyv device from the Xorg.log [2] PR: 198697 [1] Submitted by: Pete Johanson <peter@peterjohanson.com> [1], dumbbell@ [1][2]
46 lines
983 B
Bash
46 lines
983 B
Bash
#!/bin/sh
|
|
|
|
FSTAT="/usr/bin/fstat"
|
|
GREP="/usr/bin/grep"
|
|
AWK="/usr/bin/awk"
|
|
SED="/usr/bin/sed"
|
|
CAT="/bin/cat"
|
|
|
|
dispnum=0
|
|
if [ x"$1" = x"--display" ]; then
|
|
if [ $# != 2 ]; then
|
|
echo "usage: $0 [--display DISPLAY]"
|
|
exit 1
|
|
fi
|
|
DISPLAY=$2
|
|
fi
|
|
if [ ! -z "${DISPLAY}" ]; then
|
|
dispnum=$(echo ${DISPLAY} | ${SED} -E -e 's|:([0-9]+).*|\1|')
|
|
fi
|
|
|
|
if [ ! -f "/tmp/.X${dispnum}-lock" ]; then
|
|
echo "ERROR: Failed to find X lock file for display ${dispnum}"
|
|
exit 1
|
|
fi
|
|
pid=$(${CAT} "/tmp/.X${dispnum}-lock")
|
|
|
|
device=$(${FSTAT} -p ${pid} | ${GREP} ttyv | ${AWK} '{print $8}')
|
|
|
|
if [ -z "${device}" -a -f "/var/log/Xorg.$dispnum.log" ]; then
|
|
device=$(awk '/using VT number/ { print "ttyv" ($7 - 1); }' \
|
|
"/var/log/Xorg.$dispnum.log")
|
|
fi
|
|
|
|
if [ -z "${device}" ]; then
|
|
echo "ERROR: Failed to find TTY device for X server on display ${dispnum}"
|
|
exit 1
|
|
fi
|
|
|
|
ret=""
|
|
for dev in ${device}; do
|
|
if [ "${dev}" \> "${ret}" ]; then
|
|
ret=${dev}
|
|
fi
|
|
done
|
|
|
|
echo "/dev/${dev}"
|