From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 23DAD13800E for ; Fri, 27 Jul 2012 02:43:22 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 39478E0759; Fri, 27 Jul 2012 02:43:15 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 0D3E6E0759 for ; Fri, 27 Jul 2012 02:43:14 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 714EA1B4018 for ; Fri, 27 Jul 2012 02:43:14 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 15DECE5436 for ; Fri, 27 Jul 2012 02:43:13 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1343356971.d938c3ff0a4ef92451cf6381aeb23a6c2d9ad8f2.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/portage/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/_selinux.py X-VCS-Directories: pym/portage/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: d938c3ff0a4ef92451cf6381aeb23a6c2d9ad8f2 X-VCS-Branch: master Date: Fri, 27 Jul 2012 02:43:13 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 760f9cc2-43e5-4612-9756-77acbc5bacf7 X-Archives-Hash: eb755100514e0a90ae4f964306ed7167 commit: d938c3ff0a4ef92451cf6381aeb23a6c2d9ad8f2 Author: Zac Medico gentoo org> AuthorDate: Fri Jul 27 02:42:51 2012 +0000 Commit: Zac Medico gentoo org> CommitDate: Fri Jul 27 02:42:51 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=d938c3ff _selinux/spawn_wrapper: setexec *after* fork This avoids any interference with concurrent threads in the calling process. --- pym/portage/_selinux.py | 40 ++++++++++++++++++++++++++-------------- 1 files changed, 26 insertions(+), 14 deletions(-) diff --git a/pym/portage/_selinux.py b/pym/portage/_selinux.py index 9470978..1737145 100644 --- a/pym/portage/_selinux.py +++ b/pym/portage/_selinux.py @@ -95,20 +95,32 @@ def setfscreate(ctx="\n"): raise OSError( _("setfscreate: Failed setting fs create context \"%s\".") % ctx) -def spawn_wrapper(spawn_func, selinux_type): - - selinux_type = _unicode_encode(selinux_type, - encoding=_encodings['content'], errors='strict') - - def wrapper_func(*args, **kwargs): - con = settype(selinux_type) - setexec(con) - try: - return spawn_func(*args, **kwargs) - finally: - setexec() - - return wrapper_func +class spawn_wrapper(object): + """ + Create a wrapper function for the given spawn function. When the wrapper + is called, it will adjust the arguments such that setexec() to be called + *after* the fork (thereby avoiding any interference with concurrent + threads in the calling process). + """ + __slots__ = ("_con", "_spawn_func") + + def __init__(self, spawn_func, selinux_type): + self._spawn_func = spawn_func + selinux_type = _unicode_encode(selinux_type, + encoding=_encodings['content'], errors='strict') + self._con = settype(selinux_type) + + def __call__(self, *args, **kwargs): + + pre_exec = kwargs.get("pre_exec") + + def _pre_exec(): + if pre_exec is not None: + pre_exec() + setexec(self._con) + + kwargs["pre_exec"] = _pre_exec + return self._spawn_func(*args, **kwargs) def symlink(target, link, reflnk): target = _unicode_encode(target, encoding=_encodings['fs'], errors='strict')