extras-buildsys/common ExecUtils.py,1.3,1.4
Daniel Williams (dcbw)
fedora-extras-commits at redhat.com
Mon Nov 14 19:13:03 UTC 2005
Author: dcbw
Update of /cvs/fedora/extras-buildsys/common
In directory cvs-int.fedora.redhat.com:/tmp/cvs-serv6112/common
Modified Files:
ExecUtils.py
Log Message:
2005-11-14 Dan Williams <dcbw at redhat.com>
* common/ExecUtils.py
- Close files opened in parent after exec() of child
Index: ExecUtils.py
===================================================================
RCS file: /cvs/fedora/extras-buildsys/common/ExecUtils.py,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- ExecUtils.py 14 Nov 2005 01:02:27 -0000 1.3
+++ ExecUtils.py 14 Nov 2005 19:13:01 -0000 1.4
@@ -48,28 +48,31 @@
def getfd(filespec, readOnly = 0):
if type(filespec) == types.IntType:
- return filespec
+ return (filespec, False)
if filespec == None:
filespec = "/dev/null"
flags = os.O_RDWR | os.O_CREAT
if (readOnly):
flags = os.O_RDONLY
- return os.open(filespec, flags, 0644)
+ fd = os.open(filespec, flags, 0644)
+ return (fd, True)
def exec_with_redirect(cmd, argv, stdin=0, stdout=1, stderr=2):
- stdin = getfd(stdin)
- if stdout == stderr:
- stdout = getfd(stdout)
- stderr = stdout
- else:
- stdout = getfd(stdout)
- stderr = getfd(stderr)
-
cmd = os.path.abspath(cmd)
if not os.access (cmd, os.X_OK):
raise RuntimeError(cmd + " can not be run")
+ stdout_opened = False
+ stderr_opened = False
+ (stdin, stdin_opened) = getfd(stdin)
+ if stdout == stderr:
+ (stdout, stdout_opened) = getfd(stdout)
+ stderr = stdout
+ else:
+ (stdout, stdout_opened) = getfd(stdout)
+ (stderr, stderr_opened) = getfd(stderr)
+
childpid = os.fork()
if (not childpid):
if stdin != 0:
@@ -96,5 +99,13 @@
print "Could not execute command '%s'. Reason: %s" % (cmd, e)
sys.exit(1)
+ # Close any files we may have opened
+ if stdin_opened:
+ os.close(stdin)
+ if stdout_opened:
+ os.close(stdout)
+ if stderr != stdout and stderr_opened:
+ os.close(stderr)
+
return childpid
More information about the fedora-extras-commits
mailing list