I need to get the active DISPLAY for any logged in user, so if they enter through SSH, they can query it.
Under Ubuntu 12.04, I used a script that, using the consolekit dbus interface, iterated through the active sessions, matching the user UID. A bit complicated, but that would give me the Display that I needed.
This is the code I used:
function obtener_display(){
_UID=$1
SESIONES_RAW=$(dbus-send --system --dest=org.freedesktop.ConsoleKit --print-reply /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.GetSessions)
SESIONES=$(echo "$SESIONES_RAW" | grep "object path" | sed -r 's/^.*"(.*)".*$/\1/')
for SESION in $SESIONES ; do
USUARIOS_RAW=$(dbus-send --system --dest=org.freedesktop.ConsoleKit --print-reply $SESION org.freedesktop.ConsoleKit.Session.GetUnixUser)
USUARIOS=$(echo "$USUARIOS_RAW" | grep "uint32" | sed -r 's/^.*uint32 (.*)$/\1/')
for USUARIO in $USUARIOS ; do
if [ $_UID -eq $USUARIO ] ; then
X11DISPLAY_RAW=$(dbus-send --system --dest=org.freedesktop.ConsoleKit --print-reply $SESION org.freedesktop.ConsoleKit.Session.GetX11Display)
X11DISPLAY=$(echo "$X11DISPLAY_RAW" | grep "string" | sed -r 's/^.*string "(.*)"$/\1/')
if [ ! -z "$X11DISPLAY" ] ; then
DISPLAY_VALIDO="$X11DISPLAY"
fi
fi
done
done
if [ ! -z "$DISPLAY_VALIDO" ] ; then
echo "$DISPLAY_VALIDO"
else
echo "FALSE"
fi
}
And it worked like a charm! Well, kind of. At least it seemed to work properly, never heard anything bad about it. Anyways, it doesn't work under 14.04. The first method I used to get the ConsoleKit sessions returns an empty array. And every method from Manager also return empty arrays.
Is there any way I can fix this? Fix this method should do it, but any other way to get the active DISPLAY for any logged in user should also work.