Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH 1/2] portage.process.spawn: add cwd parameter
Date: Sat, 24 Nov 2018 00:18:01
Message-Id: 20181124001525.31921-2-zmedico@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH 0/2] git: drop privileges for gc and merge (bug 669496) by Zac Medico
1 Signed-off-by: Zac Medico <zmedico@g.o>
2 ---
3 lib/portage/process.py | 13 ++++++++++---
4 1 file changed, 10 insertions(+), 3 deletions(-)
5
6 diff --git a/lib/portage/process.py b/lib/portage/process.py
7 index 75ec299f0..ed1a49247 100644
8 --- a/lib/portage/process.py
9 +++ b/lib/portage/process.py
10 @@ -220,7 +220,7 @@ def cleanup():
11 pass
12
13 def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
14 - uid=None, gid=None, groups=None, umask=None, logfile=None,
15 + uid=None, gid=None, groups=None, umask=None, cwd=None, logfile=None,
16 path_lookup=True, pre_exec=None,
17 close_fds=(sys.version_info < (3, 4)), unshare_net=False,
18 unshare_ipc=False, unshare_mount=False, unshare_pid=False,
19 @@ -248,6 +248,8 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
20 @type groups: List
21 @param umask: An integer representing the umask for the process (see man chmod for umask details)
22 @type umask: Integer
23 + @param cwd: Current working directory
24 + @type cwd: String
25 @param logfile: name of a file to use for logging purposes
26 @type logfile: String
27 @param path_lookup: If the binary is not fully specified then look for it in PATH
28 @@ -350,7 +352,7 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
29 if pid == 0:
30 try:
31 _exec(binary, mycommand, opt_name, fd_pipes,
32 - env, gid, groups, uid, umask, pre_exec, close_fds,
33 + env, gid, groups, uid, umask, cwd, pre_exec, close_fds,
34 unshare_net, unshare_ipc, unshare_mount, unshare_pid,
35 cgroup)
36 except SystemExit:
37 @@ -421,7 +423,8 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
38 # Everything succeeded
39 return 0
40
41 -def _exec(binary, mycommand, opt_name, fd_pipes, env, gid, groups, uid, umask,
42 +def _exec(binary, mycommand, opt_name, fd_pipes,
43 + env, gid, groups, uid, umask, cwd,
44 pre_exec, close_fds, unshare_net, unshare_ipc, unshare_mount, unshare_pid,
45 cgroup):
46
47 @@ -446,6 +449,8 @@ def _exec(binary, mycommand, opt_name, fd_pipes, env, gid, groups, uid, umask,
48 @type uid: Integer
49 @param umask: an int representing a unix umask (see man chmod for umask details)
50 @type umask: Integer
51 + @param cwd: Current working directory
52 + @type cwd: String
53 @param pre_exec: A function to be called with no arguments just prior to the exec call.
54 @type pre_exec: callable
55 @param unshare_net: If True, networking will be unshared from the spawned process
56 @@ -609,6 +614,8 @@ def _exec(binary, mycommand, opt_name, fd_pipes, env, gid, groups, uid, umask,
57 os.setuid(int(uid))
58 if umask:
59 os.umask(umask)
60 + if cwd is not None:
61 + os.chdir(cwd)
62 if pre_exec:
63 pre_exec()
64
65 --
66 2.18.1