2

I want to know if someone is logged into a local X-session. In the past I looked at the output of ck-list-sessions. The output looked something like this:

Session12:
    unix-user = '[redacted]'
    realname = '[redacted]'
    seat = 'Seat1'
    session-type = ''
    active = TRUE
    x11-display = ':0'
    x11-display-device = '/dev/tty8'
    display-device = ''
    remote-host-name = ''
    is-local = TRUE
    on-since = '2012-10-22T18:17:55.553236Z'
    login-session-id = '4294967295'

If no one was logged in, there was no output. I checked if someone was logged in with

ck_result" string => execresult("/usr/bin/ck-list-sessions | /bin/grep x11 | /usr/bin/cut --delimiter=\\' -f 2 | /usr/bin/wc -w

This no longer works, because lightdm greeter looks like a logged in user

Session12:
    unix-user = '[redacted]'
    realname = 'Light Display Manager'
    seat = 'Seat1'
    session-type = 'LoginWindow'
    active = TRUE
    x11-display = ':0'
    x11-display-device = '/dev/tty8'
    display-device = ''
    remote-host-name = ''
    is-local = TRUE
    on-since = '2012-10-22T22:17:55.553236Z'
    login-session-id = '4294967295'

I guess I could check session-type, but I don't know how to do that and check x11-display in one-liner. I then need to write my own script, but at that point I thought I would check if anyone else has already done the work or if there is a way to get ConsoleKit to tell me what I want (or if I should be using a different tool)?

2 Answers 2

0

See the answer to this question. You will probably end up using D-Bus and ConsoleKit.

3
  • I may go with parsing the output of ck-list-sessions. That seems simpler that going through dbus, which isn't really designed for human interaction.
    – Jack
    Oct 23, 2012 at 15:01
  • I figured out how to use the dbus interface, but it doesn't appear to provide different information than is available with ck-list-sessions (which is probably using dbus under the hood).
    – Jack
    Oct 23, 2012 at 15:08
  • Now that I looked up ck-list-sessions I feel dumb; this is ConsoleKit, so the answers are essentially equivalent!
    – January
    Oct 23, 2012 at 16:55
0

As it happens, I just needed to solve this - but the best I've managed is 'nasty hack'-esque code:

dbus-send --system --type=method_call --print-reply=literal --dest=org.freedesktop.ConsoleKit `dbus-send --system --type=method_call --print-reply=literal --dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Seat1 org.freedesktop.ConsoleKit.Seat.GetActiveSession` org.freedesktop.ConsoleKit.Session.GetX11Display | grep ":" &&  dbus-send --system --type=method_call --print-reply=literal --dest=org.freedesktop.ConsoleKit `dbus-send --system --type=method_call --print-reply=literal --dest=org.freedesktop.ConsoleKit /org/freedesktop/ConsoleKit/Seat1 org.freedesktop.ConsoleKit.Seat.GetActiveSession` org.freedesktop.ConsoleKit.Session.GetUnixUser | grep -v "uint32 122$" && echo "Active User"

I believe the uid of lightdm is consistent across Ubuntu installs, but this would need adjustment for other display managers.

The code checks:

  1. Does the active physical seat have an X Display?
  2. If it does, does its uid match 122 (lightdm)?
  3. You end up with output of the X display, the users uid, and could execute arbitrary success code script of echo "Active User".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .