Skip to content

Commit

Permalink
Properly check that DBUS_SESSION_BUS_ADDRESS exists from @alxchk
Browse files Browse the repository at this point in the history
  • Loading branch information
AlessandroZ committed May 24, 2017
1 parent 0e5722c commit 43bc0fb
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Linux/lazagne/config/homes.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,27 @@ def sessions(setenv=True):

if setenv:
previous_uid = os.geteuid()
previous = None
if not uid == previous_uid:
try:
os.seteuid(uid)
except:
continue

previous = os.environ['DBUS_SESSION_BUS_ADDRESS']
if 'DBUS_SESSION_BUS_ADDRESS' is os.environ:
previous = os.environ['DBUS_SESSION_BUS_ADDRESS']

os.environ['DBUS_SESSION_BUS_ADDRESS'] = address

try:
yield (uid, address)
finally:
if setenv:
os.environ['DBUS_SESSION_BUS_ADDRESS'] = previous

if previous:
os.environ['DBUS_SESSION_BUS_ADDRESS'] = previous
else:
del os.environ['DBUS_SESSION_BUS_ADDRESS']

if previous_uid != uid:
try:
os.seteuid(previous_uid)
Expand Down

0 comments on commit 43bc0fb

Please sign in to comment.