Commit a059a46d authored by Martín Ferrari's avatar Martín Ferrari

Set environment variables when changing user

parent 510c2ed1
#!/usr/bin/env python #!/usr/bin/env python
# vim:ts=4:sw=4:et:ai:sts=4 # vim:ts=4:sw=4:et:ai:sts=4
import base64, os, passfd, re, select, signal, socket, sys, tempfile, time, errno import base64, errno, os, passfd, re, select, signal, socket, sys, tempfile
import traceback, unshare import time, traceback, unshare
import netns.subprocess_, netns.iproute import netns.subprocess_, netns.iproute
from netns.environ import * from netns.environ import *
......
...@@ -281,7 +281,12 @@ def spawn(executable, argv = None, cwd = None, env = None, close_fds = False, ...@@ -281,7 +281,12 @@ def spawn(executable, argv = None, cwd = None, env = None, close_fds = False,
if user != None: if user != None:
user, uid, gid = get_user(user) user, uid, gid = get_user(user)
home = pwd.getpwuid(uid)[5]
groups = [x[2] for x in grp.getgrall() if user in x[3]] groups = [x[2] for x in grp.getgrall() if user in x[3]]
if not env:
env = dict(os.environ)
env['HOME'] = home
env['USER'] = user
(r, w) = os.pipe() (r, w) = os.pipe()
pid = os.fork() pid = os.fork()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment