[gnome-shell] [gnome-shell.in] When we don't have DISPLAY, attempt to pull in running session



commit 855272198365de506d342b6388e8659bda7d610d
Author: Colin Walters <walters verbum org>
Date:   Thu Feb 25 13:35:32 2010 -0500

    [gnome-shell.in] When we don't have DISPLAY, attempt to pull in running session
    
    This is a convenience for debugging when logging in over ssh.  Longer term
    we should stick this code (in a more OS portable fashion) into ConsoleKit.

 src/gnome-shell.in |   50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 50 insertions(+), 0 deletions(-)
---
diff --git a/src/gnome-shell.in b/src/gnome-shell.in
old mode 100755
new mode 100644
index 254cdee..36548c5
--- a/src/gnome-shell.in
+++ b/src/gnome-shell.in
@@ -14,6 +14,50 @@ import termios
 import time
 import errno
 
+def get_running_session_environs():
+    wanted_environment = ['DBUS_SESSION_BUS_ADDRESS', 'DISPLAY', 'XDG_DATA_DIRS',
+                          'XAUTHORITY', 'XDG_SESSION_COOKIE', 'ORBIT_SOCKETDIR',
+                          'SESSION_MANAGER']
+    num_re = re.compile('^[0-9]+$')
+    myuid = os.getuid()
+    if not os.path.isdir('/proc'):
+        return {}
+    for filename in os.listdir('/proc'):
+        if not num_re.match(filename):
+            continue
+        piddir = '/proc/' + filename
+        try:
+            stat = os.stat(piddir)
+        except OSError, e:
+            continue
+        if not stat.st_uid == myuid:
+            continue
+        try:
+            exe = os.readlink(piddir + '/exe')
+        except OSError, e:
+            continue
+        if os.path.basename(exe) != 'gnome-session':
+            continue
+        try:
+            f = open(os.path.join(piddir, 'environ'))
+        except OSError, e:
+            continue
+        environ_data = f.read()
+        f.close()
+        # There's a trailing null at the last one, so remove the
+        # empty string
+        environs = environ_data.split('\0')[:-1]
+        # Rumor has it the presence of just FOO (instead of FOO=bar)
+        # represents a deleted environment variable
+        environs = filter(lambda x: '=' in x, environs)
+        # Turn it into a dictionary
+        environs = dict(map(lambda x: x.split('=', 1), environs))
+        result = {}
+        for key in wanted_environment:
+            if key in environs:
+                result[key] = environs[key]
+        return result
+
 def start_xephyr():
     tmpdir = tempfile.mkdtemp("", "gnome-shell.")
     atexit.register(shutil.rmtree, tmpdir)
@@ -343,6 +387,12 @@ else:
 if options.verbose:
     print "Starting shell"
 
+
+# Handle ssh logins
+if 'DISPLAY' not in os.environ:
+    running_env = get_running_session_environs()
+    os.environ.update(running_env)
+
 if options.debug:
     # Record initial terminal state so we can reset it to that
     # later, in case we kill gdb at a bad time



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]