extras-buildsys/common ExecUtils.py,1.2,1.3
Daniel Williams (dcbw)
fedora-extras-commits at redhat.com
Mon Nov 14 01:02:29 UTC 2005
Author: dcbw
Update of /cvs/fedora/extras-buildsys/common
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv4619/common
Modified Files:
ExecUtils.py
Log Message:
2005-11-13 Dan Williams <dcbw at redhat.com>
* common/ExecUtils.py
- On python 2.3 and lower, unblock signals before execing
processes. Requires py_pthread_sigmask module.
Index: ExecUtils.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/common/ExecUtils.py,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ExecUtils.py 31 Aug 2005 01:56:38 -0000 1.2
+++ ExecUtils.py 14 Nov 2005 01:02:27 -0000 1.3
@@ -17,6 +17,35 @@
import types
import select
+#
+# pthread_sigmask
+#
+# Python 2.3 and earlier use pthread_sigmask to block all
+# signals right before creating a new thread. Since exec-ed
+# processes inherit the signal mask of the thread that's
+# executing them, this causes problems if the exec-ed process
+# is expecting a sane signal mask. Some symptoms include
+# unreaped children and parents stuck in waitpid(), among others.
+#
+use_pthread_sigmask = False
+if sys.version_info[:3] < (2, 4, 0):
+ try:
+ import signal
+ import pthread_sigmask
+ use_pthread_sigmask = True
+
+ i = 1
+ unblock_signal_list = []
+ while i < signal.NSIG:
+ unblock_signal_list.append(i)
+ i = i + 1
+ except:
+ print """WARNING: You might want to install the pthread_sigmask module.
+Python versions earlier than 2.4 have problems with signals and
+spawned processes."""
+ pass
+
+
def getfd(filespec, readOnly = 0):
if type(filespec) == types.IntType:
return filespec
@@ -54,6 +83,13 @@
os.dup2(stderr, 2)
os.close(stderr)
+ # Set signal mask to something sane if we can
+ if use_pthread_sigmask:
+ # Unblock all signals before execing
+ (ret, oldmask) = pthread_sigmask.pthread_sigmask(
+ pthread_sigmask.SIG_UNBLOCK,
+ unblock_signal_list)
+
try:
os.execv(cmd, argv)
except OSError, e:
@@ -62,13 +98,3 @@
return childpid
-
-def foo():
- status = -1
- try:
- (pid, status) = os.waitpid(childpid, 0)
- except OSError, (errno, msg):
- print __name__, "waitpid:", msg
-
- return status
-
More information about the scm-commits
mailing list