Handle EPERM from os.kill(), bug #358211.
authorZac Medico <zmedico@gentoo.org>
Mon, 9 Sep 2013 16:49:39 +0000 (09:49 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 9 Sep 2013 16:49:39 +0000 (09:49 -0700)
pym/_emerge/SpawnProcess.py
pym/_emerge/SubProcess.py

index 021e54616b4872bb8312108801d9556c161a88d2..6024ef779bcb91d1c9bc75a7b577a580895927d2 100644 (file)
@@ -8,6 +8,7 @@ except ImportError:
        fcntl = None
 
 import errno
+import logging
 import platform
 import signal
 import sys
@@ -16,6 +17,7 @@ from _emerge.SubProcess import SubProcess
 import portage
 from portage import os
 from portage.const import BASH_BINARY
+from portage.util import writemsg_level
 from portage.util._async.PipeLogger import PipeLogger
 
 # On Darwin, FD_CLOEXEC triggers errno 35 for stdout (bug #456296)
@@ -198,7 +200,13 @@ class SpawnProcess(SubProcess):
                                        try:
                                                os.kill(int(p), sig)
                                        except OSError as e:
-                                               if e.errno != errno.ESRCH:
+                                               if e.errno == errno.EPERM:
+                                                       # Reported with hardened kernel (bug #358211).
+                                                       writemsg_level(
+                                                               "!!! kill: (%i) - Operation not permitted\n" %
+                                                               (p,), level=logging.ERROR,
+                                                               noiselevel=-1)
+                                               elif e.errno != errno.ESRCH:
                                                        raise
 
                        # step 1: kill all orphans
index 4ccf9164f8682eda96a7b8330e93cc391185b431..13d93829777a401afb85a398f8967f3a31fb9a91 100644 (file)
@@ -1,7 +1,10 @@
 # Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
+import logging
+
 from portage import os
+from portage.util import writemsg_level
 from _emerge.AbstractPollTask import AbstractPollTask
 import signal
 import errno
@@ -45,7 +48,13 @@ class SubProcess(AbstractPollTask):
                        try:
                                os.kill(self.pid, signal.SIGTERM)
                        except OSError as e:
-                               if e.errno != errno.ESRCH:
+                               if e.errno == errno.EPERM:
+                                       # Reported with hardened kernel (bug #358211).
+                                       writemsg_level(
+                                               "!!! kill: (%i) - Operation not permitted\n" %
+                                               (self.pid,), level=logging.ERROR,
+                                               noiselevel=-1)
+                               elif e.errno != errno.ESRCH:
                                        raise
 
        def isAlive(self):
@@ -64,7 +73,13 @@ class SubProcess(AbstractPollTask):
                                        try:
                                                os.kill(self.pid, signal.SIGKILL)
                                        except OSError as e:
-                                               if e.errno != errno.ESRCH:
+                                               if e.errno == errno.EPERM:
+                                                       # Reported with hardened kernel (bug #358211).
+                                                       writemsg_level(
+                                                               "!!! kill: (%i) - Operation not permitted\n" %
+                                                               (self.pid,), level=logging.ERROR,
+                                                               noiselevel=-1)
+                                               elif e.errno != errno.ESRCH:
                                                        raise
                                                del e
                                        self._wait_loop(timeout=self._cancel_timeout)