summaryrefslogtreecommitdiff
path: root/sysutils/consolekit/files/ck-get-x11-display-device
diff options
context:
space:
mode:
Diffstat (limited to 'sysutils/consolekit/files/ck-get-x11-display-device')
-rw-r--r--sysutils/consolekit/files/ck-get-x11-display-device35
1 files changed, 35 insertions, 0 deletions
diff --git a/sysutils/consolekit/files/ck-get-x11-display-device b/sysutils/consolekit/files/ck-get-x11-display-device
new file mode 100644
index 000000000000..6fc508360b92
--- /dev/null
+++ b/sysutils/consolekit/files/ck-get-x11-display-device
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+FSTAT="/usr/bin/fstat"
+GREP="/usr/bin/grep"
+AWK="/usr/bin/awk"
+SED="/usr/bin/sed"
+CAT="/bin/cat"
+HEAD="/usr/bin/head"
+
+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 | ${HEAD} -1 | ${AWK} '{print $8}')
+
+if [ -z "${device}" ]; then
+ echo "ERROR: Failed to find TTY device for X server on display ${dispnum}"
+ exit 1
+fi
+
+echo "/dev/${device}"