summaryrefslogtreecommitdiff
path: root/src/test-open-session
blob: c037cee350d8de043f94a22c0831487a3220562a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
#
# Test opening a new session
#

import os
import gobject
import dbus
import dbus.glib

print "uid=%d pid=%d" % (os.geteuid (), os.getpid ())

bus = dbus.SystemBus ()

manager_obj = bus.get_object ('org.freedesktop.ConsoleKit', '/org/freedesktop/ConsoleKit/Manager')

manager = dbus.Interface (manager_obj, 'org.freedesktop.ConsoleKit.Manager')

cookie = manager.OpenSession ()
os.environ['XDG_SESSION_COOKIE'] = cookie
print "Got cookie: %s" % cookie

seats = manager.GetSeats ()
for sid in seats:
    seat_obj = bus.get_object ('org.freedesktop.ConsoleKit', sid)
    seat = dbus.Interface (seat_obj, 'org.freedesktop.ConsoleKit.Seat')
    sessions = seat.GetSessions ()
    for ssid in sessions:
            session_obj = bus.get_object ('org.freedesktop.ConsoleKit', ssid)
            session = dbus.Interface (session_obj, 'org.freedesktop.ConsoleKit.Session')
            uid = session.GetUser ()

# Hmm looks like the proc environment doesn't get updated when
# os.environ is set.  So, we won't use GetCurrentSession.
#current_session = manager.GetCurrentSession ()
current_session = manager.GetSessionForCookie (cookie)
print "Current session: %s" % current_session

session_obj = bus.get_object ('org.freedesktop.ConsoleKit', ssid)
session = dbus.Interface (session_obj, 'org.freedesktop.ConsoleKit.Session')

mainloop = gobject.MainLoop ()

gobject.timeout_add (30000, mainloop.quit)

mainloop.run()