From 9df2cddf573ad574a98b57164f0c186cf86dfcc4 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Mon, 22 May 2006 10:53:14 -0400 Subject: [PATCH] Add script that starts Xephyr, dbus, and metacity for a test user then dumps you to a shell --- spawn-test-env.py | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 spawn-test-env.py diff --git a/spawn-test-env.py b/spawn-test-env.py new file mode 100755 index 00000000..1364eff7 --- /dev/null +++ b/spawn-test-env.py @@ -0,0 +1,67 @@ +#!/usr/bin/python -t + +import sys, os +import gtk, gobject +import pwd +import types + +def change_user(user): + try: + pwrec = pwd.getpwnam(user) + except KeyError: + raise Exception("Username '%s' does not exist." % user) + uid = pwrec[2] + os.setuid(uid) + return pwrec[6] + +def shell_watch_cb(pid, condition, user_data=None): + print "In shell watch callback." + gtk.main_quit() + +def main(): + if len(sys.argv) < 1: + print "Usage: %s " % sys.argv[0] + user = sys.argv[1] + + # Start Xephyr + DISPLAY = ":10" + args = "/usr/bin/Xephyr -ac -host-cursor -screen 800x600 %s" % DISPLAY + args = args.split() + (xephyr_pid, ign1, ign2, ign3) = gobject.spawn_async(args, flags=gobject.SPAWN_STDERR_TO_DEV_NULL | gobject.SPAWN_STDOUT_TO_DEV_NULL) + print "Xepyhr pid is %d" % xephyr_pid + + shell = change_user(user) + + args = "/bin/dbus-daemon --session --print-address".split() + (dbus_pid, ign1, dbus_stdout, ign3) = gobject.spawn_async(args, flags=gobject.SPAWN_STDERR_TO_DEV_NULL, standard_output=True) + dbus_file = os.fdopen(dbus_stdout) + addr = dbus_file.readline() + addr = addr.strip() + print "dbus-daemon pid is %d, session bus address is %s" % (dbus_pid, addr) + dbus_file.close() + + os.environ["DISPLAY"] = DISPLAY + os.environ["DBUS_SESSION_BUS_ADDRESS"] = addr + + args = "/usr/bin/metacity" + (metacity_pid, ign1, ign2, ign3) = gobject.spawn_async([args], flags=gobject.SPAWN_STDERR_TO_DEV_NULL | gobject.SPAWN_STDOUT_TO_DEV_NULL) + + print "\n" + (shell_pid, ign1, ign2, ign3) = gobject.spawn_async([shell], flags=gobject.SPAWN_LEAVE_DESCRIPTORS_OPEN | gobject.SPAWN_CHILD_INHERITS_STDIN | gobject.SPAWN_DO_NOT_REAP_CHILD) + gobject.child_watch_add(shell_pid, shell_watch_cb) + try: + gtk.main() + except KeyboardInterrupt: + pass + + try: + os.kill(dbus_pid, 9) + except OSError: + pass + try: + os.kill(metacity_pid, 9) + except OSError: + pass + +if __name__ == "__main__": + main()