spawn_func = portage.process.spawn_sandbox
if sesandbox:
- con = selinux.settype(mysettings["PORTAGE_SANDBOX_T"])
- selinux.setexec(con)
+ spawn_func = selinux.spawn_wrapper(spawn_func,
+ mysettings["PORTAGE_SANDBOX_T"])
returnpid = keywords.get("returnpid")
keywords["returnpid"] = True
finally:
if logfile:
os.close(slave_fd)
- if sesandbox:
- selinux.setexec()
if returnpid:
return mypids
os.getuid() == 0 and portage_gid and portage_uid:
kwargs.update(_userpriv_spawn_kwargs)
- try:
+ spawn_func = portage.process.spawn
- if settings.selinux_enabled():
- con = selinux.settype(settings["PORTAGE_FETCH_T"])
- selinux.setexec(con)
- # bash is an allowed entrypoint, while most binaries are not
- if args[0] != BASH_BINARY:
- args = [BASH_BINARY, "-c", "exec \"$@\"", args[0]] + args
+ if settings.selinux_enabled():
+ spawn_func = selinux.spawn_wrapper(spawn_func,
+ settings["PORTAGE_FETCH_T"])
- rval = portage.process.spawn(args,
- env=dict(settings.iteritems()), **kwargs)
+ # bash is an allowed entrypoint, while most binaries are not
+ if args[0] != BASH_BINARY:
+ args = [BASH_BINARY, "-c", "exec \"$@\"", args[0]] + args
- finally:
- if settings.selinux_enabled():
- selinux.setexec()
+ rval = spawn_func(args, env=dict(settings.iteritems()), **kwargs)
return rval
raise OSError(
"setfscreate: Failed setting fs create context \"%s\"." % ctx)
-def spawn(selinux_type, spawn_func, mycommand, opt_name=None, **keywords):
- selinux_type = portage._unicode_encode(selinux_type)
- con = settype(selinux_type)
- setexec(con)
- try:
- return spawn_func(mycommand, opt_name=opt_name, **keywords)
- finally:
- setexec()
+def spawn_wrapper(spawn_func, selinux_type):
+
+ def wrapper_func(*args, **kwargs):
+ selinux_type = portage._unicode_encode(selinux_type)
+ con = settype(selinux_type)
+ setexec(con)
+ try:
+ return spawn_func(*args, **kwargs)
+ finally:
+ setexec()
+
+ return wrapper_func
def symlink(target, link, reflnk):
target = portage._unicode_encode(target)