Lines 1-7
Link Here
|
1 |
#!/usr/bin/env python-thinlinc |
1 |
#!/usr/bin/env python-thinlinc |
2 |
# -*- mode: python; coding: utf-8 -*- |
2 |
# -*- mode: python; coding: utf-8 -*- |
3 |
# |
3 |
# |
4 |
# Copyright 2014 Cendio AB. |
4 |
# Copyright 2014-2018 Cendio AB. |
5 |
# For more information, see http://www.cendio.com |
5 |
# For more information, see http://www.cendio.com |
6 |
|
6 |
|
7 |
import sys |
7 |
import sys |
Lines 8-13
Link Here
|
8 |
import os |
8 |
import os |
9 |
import pipes |
9 |
import pipes |
10 |
import re |
10 |
import re |
|
|
11 |
import subprocess |
11 |
|
12 |
|
12 |
# Add modules dirs. FIXME: Use relative paths. |
13 |
# Add modules dirs. FIXME: Use relative paths. |
13 |
sys.path = ["/opt/thinlinc/modules"] + sys.path |
14 |
sys.path = ["/opt/thinlinc/modules"] + sys.path |
Lines 33-38
Link Here
|
33 |
escaped_argv.append(pipes.quote(arg)) |
34 |
escaped_argv.append(pipes.quote(arg)) |
34 |
return " ".join(escaped_argv) |
35 |
return " ".join(escaped_argv) |
35 |
|
36 |
|
|
|
37 |
def update_dbus_environ(environ): |
38 |
if which.which("dbus-update-activation-environment") is None: |
39 |
return |
40 |
|
41 |
print 'Updating D-Bus and systemd environment...' |
42 |
|
43 |
# We need to modify it, so get a local copy |
44 |
environ = environ.copy() |
45 |
|
46 |
# These are session specific and shouldn't be pushed to a common |
47 |
# daemon (only XDG_SESSION_ID is generally set in ThinLinc) |
48 |
for name in ["XDG_SEAT", "XDG_SESSION_ID", "XDG_VTNR"]: |
49 |
if name in environ: |
50 |
del environ[name] |
51 |
|
52 |
# systemd is really fussy about environment variables so we need to |
53 |
# filter out anything that might upset it |
54 |
for name in environ.keys(): |
55 |
try: |
56 |
name.decode("UTF-8") |
57 |
environ[name].decode("UTF-8") |
58 |
except UnicodeDecodeError: |
59 |
print "Ignoring invalid environment variable: %r" % (name + "=" + environ[name]) |
60 |
del environ[name] |
61 |
continue |
62 |
|
63 |
# (regexps taken from gnome-session) |
64 |
if not re.match("^[a-zA-Z_][a-zA-Z0-9_]*$", name) or \ |
65 |
not re.match("^([ \t\r\n\v\f]|[^\x00-\x1F\x7F])*$", environ[name]): |
66 |
print "Ignoring invalid environment variable: %r" % (name + "=" + environ[name]) |
67 |
del environ[name] |
68 |
continue |
69 |
|
70 |
sys.stdout.flush() |
71 |
|
72 |
p = subprocess.Popen(["dbus-update-activation-environment", |
73 |
"--systemd", "--all"], |
74 |
env=environ) |
75 |
p.wait() |
76 |
if p.returncode != 0: |
77 |
print >>sys.stderr, "tl-run-profile: Failed to update D-Bus and systemd environment" |
78 |
|
36 |
if __name__ == "__main__": |
79 |
if __name__ == "__main__": |
37 |
if len(sys.argv) != 1: |
80 |
if len(sys.argv) != 1: |
38 |
print >>sys.stderr, "Usage:" |
81 |
print >>sys.stderr, "Usage:" |
Lines 46-51
Link Here
|
46 |
if not os.getenv("TLCOMMAND").strip(): |
89 |
if not os.getenv("TLCOMMAND").strip(): |
47 |
print >>sys.stderr, "tl-run-profile: Ignoring existing but empty TLCOMMAND." |
90 |
print >>sys.stderr, "tl-run-profile: Ignoring existing but empty TLCOMMAND." |
48 |
else: |
91 |
else: |
|
|
92 |
update_dbus_environ(os.environ) |
49 |
print "Executing start program command: %s" % os.environ["TLCOMMAND"] |
93 |
print "Executing start program command: %s" % os.environ["TLCOMMAND"] |
50 |
sys.stdout.flush() |
94 |
sys.stdout.flush() |
51 |
try: |
95 |
try: |
Lines 152-157
Link Here
|
152 |
|
196 |
|
153 |
break |
197 |
break |
154 |
|
198 |
|
|
|
199 |
update_dbus_environ(environ) |
200 |
|
155 |
if (cmdline is not None) and (cmdline != ""): |
201 |
if (cmdline is not None) and (cmdline != ""): |
156 |
# Explicit command line |
202 |
# Explicit command line |
157 |
print 'Executing profile command: %s' % cmdline |
203 |
print 'Executing profile command: %s' % cmdline |