Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Stone <michael@laptop.org>2009-12-06 01:19:25 (GMT)
committer Michael Stone <michael@laptop.org>2009-12-06 01:24:43 (GMT)
commitcae1f620dd7a231caa73a6e044437edc3aef02f7 (patch)
tree138e10ef59161e5beabea1686365c5fd20c27fbd
parent9b315631c53719706d8ff942f1a0660755efd5da (diff)
Make xephyr usage resumable.
-rw-r--r--rainbow/rainbow/inject.py39
1 files changed, 26 insertions, 13 deletions
diff --git a/rainbow/rainbow/inject.py b/rainbow/rainbow/inject.py
index f5195e4..7dd1d32 100644
--- a/rainbow/rainbow/inject.py
+++ b/rainbow/rainbow/inject.py
@@ -2,7 +2,7 @@ import os
from os import R_OK, W_OK, X_OK, fork, symlink, unlink, O_CREAT, O_EXCL, chown, chmod
from os import setgroups, setgid, setuid, chdir, umask, execvpe, waitpid, WEXITSTATUS
from os import getpid, getuid, _exit, rename, readlink
-from os.path import join, basename, realpath, lexists
+from os.path import join, basename, realpath, lexists, exists
from subprocess import check_call, Popen, PIPE
from stat import S_IFDIR
from tempfile import mkdtemp, mkstemp
@@ -232,19 +232,32 @@ def configure_xephyr(_, spool, owner_gid, uid, env, safe_fds):
# XXX: MUST CHECK RETURN VALUES on subprocesses!!!!!
# XXX: I shouldn't be running these subprocesses as uid 0.
# XXX: Must get env, fds right!!!!
- cookie = Popen(["mcookie"], stdout=PIPE).communicate()[0]
- symlink(cookie, join(spool, 'uid_to_xephyr_cookie', str(uid)))
- display = reserve_elt(join(spool, 'xephyr_display_pool'), 100, 10000, 2, 'displays')
- symlink(str(display), join(spool, 'uid_to_xephyr_display', str(uid)))
-
- fd, name = mkstemp(prefix='tmp', dir=join(spool, 'uid_to_xephyr_auth'))
- os.close(fd)
- Popen(["xauth", "-f", name], stdin=PIPE).communicate("add :%d . %s\n" % (display, cookie))
- auth_path = join(spool, 'uid_to_xephyr_auth', str(uid))
- rename(name, auth_path)
- chmod(auth_path, 0640)
- chown(auth_path, 0, owner_gid)
+ cookie_path = join(spool, 'uid_to_xephyr_cookie', str(uid))
+ if lexists(cookie_path):
+ cookie = readlink(cookie_path)
+ else:
+ cookie = Popen(["mcookie"], stdout=PIPE).communicate()[0]
+ symlink(cookie, join(spool, 'uid_to_xephyr_cookie', str(uid)))
+ display_path = join(spool, 'uid_to_xephyr_display', str(uid))
+ if lexists(display_path):
+ display = int(readlink(display_path))
+ else:
+ display = reserve_elt(join(spool, 'xephyr_display_pool'), 100, 10000, 2, 'displays')
+ symlink(str(display), display_path)
+
+ auth_path = join(spool, 'uid_to_xephyr_auth', str(uid))
+ if not exists(auth_path):
+ fd, name = mkstemp(prefix='tmp', dir=join(spool, 'uid_to_xephyr_auth'))
+ os.close(fd)
+ Popen(["xauth", "-f", name], stdin=PIPE).communicate("add :%d . %s\n" % (display, cookie))
+ rename(name, auth_path)
+ chmod(auth_path, 0640)
+ chown(auth_path, 0, owner_gid)
+
+ # NB: Current versions of Xephyr will exit if the display we specified is
+ # already in use. This permits us to run Xephyr unconditionally even when
+ # we're resuming an old uid. <MS>
Popen(["Xephyr", "-screen", "800x600x24", "-auth", auth_path, "-reset", "-terminate", ":%d" % display])
newenv = {'DISPLAY' : ':%d' % display, 'XAUTHORITY' : auth_path}