Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 675868
Collapse All | Expand All

(-)a/bin/pid-ns-init (-3 / +23 lines)
Lines 39-45 def forward_kill_signal(main_child_pid, signum, frame): Link Here
39
39
40
def main(argv):
40
def main(argv):
41
	if len(argv) < 2:
41
	if len(argv) < 2:
42
		return 'Usage: {} <main-child-pid> or <pass_fds> <binary> <argv0> [arg]..'.format(argv[0])
42
		return 'Usage: {} <main-child-pid> or <uid> <gid> <groups> <umask> <pass_fds> <binary> <argv0> [arg]..'.format(argv[0])
43
43
44
	if len(argv) == 2:
44
	if len(argv) == 2:
45
		# The child process is init (pid 1) in a child pid namespace, and
45
		# The child process is init (pid 1) in a child pid namespace, and
Lines 50-62 def main(argv): Link Here
50
		proc = None
50
		proc = None
51
	else:
51
	else:
52
		# The current process is init (pid 1) in a child pid namespace.
52
		# The current process is init (pid 1) in a child pid namespace.
53
		pass_fds, binary, args = tuple(int(fd) for fd in argv[1].split(',')), argv[2], argv[3:]
53
		uid, gid, groups, umask, pass_fds, binary, args = argv[1], argv[2], argv[3], argv[4], tuple(int(fd) for fd in argv[5].split(',')), argv[6], argv[7:]
54
		if uid:
55
			uid = int(uid)
56
		if gid:
57
			gid = int(gid)
58
		if groups:
59
			groups = tuple(int(group) for group in groups.split(','))
60
		if umask:
61
			umask = int(umask)
62
63
		def preexec():
64
			if gid:
65
				os.setgid(gid)
66
			if groups:
67
				os.setgroups(groups)
68
			if uid:
69
				os.setuid(uid)
70
			if umask:
71
				os.umask(umask)
72
			if signal_disposition_preexec is not None:
73
				signal_disposition_preexec()
54
74
55
		popen_kwargs = {}
75
		popen_kwargs = {}
56
		if sys.version_info.major > 2:
76
		if sys.version_info.major > 2:
57
			popen_kwargs['pass_fds'] = pass_fds
77
			popen_kwargs['pass_fds'] = pass_fds
58
		proc = subprocess.Popen(args, executable=binary,
78
		proc = subprocess.Popen(args, executable=binary,
59
			preexec_fn=signal_disposition_preexec, **popen_kwargs)
79
			preexec_fn=preexec, **popen_kwargs)
60
		main_child_pid = proc.pid
80
		main_child_pid = proc.pid
61
81
62
	sig_handler = functools.partial(forward_kill_signal, main_child_pid)
82
	sig_handler = functools.partial(forward_kill_signal, main_child_pid)
(-)a/lib/portage/process.py (-3 / +10 lines)
Lines 1-5 Link Here
1
# portage.py -- core Portage functionality
1
# portage.py -- core Portage functionality
2
# Copyright 1998-2018 Gentoo Authors
2
# Copyright 1998-2019 Gentoo Authors
3
# Distributed under the terms of the GNU General Public License v2
3
# Distributed under the terms of the GNU General Public License v2
4
4
5
5
Lines 467-473 def _exec(binary, mycommand, opt_name, fd_pipes, Link Here
467
	@param gid: Group ID to run the process under
467
	@param gid: Group ID to run the process under
468
	@type gid: Integer
468
	@type gid: Integer
469
	@param groups: Groups the Process should be in.
469
	@param groups: Groups the Process should be in.
470
	@type groups: Integer
470
	@type groups: List
471
	@param uid: User ID to run the process under
471
	@param uid: User ID to run the process under
472
	@type uid: Integer
472
	@type uid: Integer
473
	@param umask: an int representing a unix umask (see man chmod for umask details)
473
	@param umask: an int representing a unix umask (see man chmod for umask details)
Lines 571-578 def _exec(binary, mycommand, opt_name, fd_pipes, Link Here
571
									portage._python_interpreter,
571
									portage._python_interpreter,
572
									os.path.join(portage._bin_path,
572
									os.path.join(portage._bin_path,
573
										'pid-ns-init'),
573
										'pid-ns-init'),
574
									_unicode_encode(str(uid) if uid is not None else ''),
575
									_unicode_encode(str(gid) if gid is not None else ''),
576
									_unicode_encode(','.join(str(group) for group in groups) if groups is not None else ''),
577
									_unicode_encode(str(umask) if umask is not None else ''),
574
									_unicode_encode(','.join(str(fd) for fd in fd_pipes)),
578
									_unicode_encode(','.join(str(fd) for fd in fd_pipes)),
575
									binary] + myargs
579
									binary] + myargs
580
								uid = None
581
								gid = None
582
								groups = None
583
								umask = None
576
							else:
584
							else:
577
								# Execute a supervisor process which will forward
585
								# Execute a supervisor process which will forward
578
								# signals to init and forward exit status to the
586
								# signals to init and forward exit status to the
579
- 

Return to bug 675868