[PATCH] Fix execWith* functions for non-redirected use.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I came across the issue while trying to use them for mdadm testing.
There is no BZ for it, we don't use the functions in the exception
raising way in the code now (and it is unlikely that we will).
But i needed to fix it for my purposes anyway, so here's the patch.

We was mixing file descriptors and file objects, so that exception would be
thrown if default arguments for stdin, stderr, and stdout were used (which is
not in the code now). They were defined as file descriptors while we were
using them as file objects in execWithCapture and execWithRedirect. In
execWithPulseProgress they were used in a very mixed way.
---
 iutil.py |   20 +++++++-------------
 1 files changed, 7 insertions(+), 13 deletions(-)

diff --git a/iutil.py b/iutil.py
index f13956f..2f13630 100644
--- a/iutil.py
+++ b/iutil.py
@@ -40,7 +40,7 @@ log = logging.getLogger("anaconda")
 # @param searchPath Should command be searched for in $PATH?
 # @param root The directory to chroot to before running command.
 # @return The return code of command.
-def execWithRedirect(command, argv, stdin = 0, stdout = 1, stderr = 2,
+def execWithRedirect(command, argv, stdin = sys.stdin, stdout = sys.stdout, stderr = sys.stderr,
                      searchPath = 0, root = '/'):
     def chroot ():
         os.chroot(root)
@@ -52,8 +52,6 @@ def execWithRedirect(command, argv, stdin = 0, stdout = 1, stderr = 2,
     if type(stdin) == type("string"):
         if os.access(stdin, os.R_OK):
             stdin = open(stdin)
-        else:
-            stdin = 0
     if type(stdout) == type("string"):
         stdout = open(stdout, "w")
     if type(stderr) == type("string"):
@@ -100,7 +98,7 @@ def execWithRedirect(command, argv, stdin = 0, stdout = 1, stderr = 2,
 # @param stderr The file descriptor to redirect stderr to.
 # @param root The directory to chroot to before running command.
 # @return The output of command from stdout.
-def execWithCapture(command, argv, stdin = 0, stderr = 2, root='/'):
+def execWithCapture(command, argv, stdin = sys.stdin, stderr = sys.stderr, root='/'):
     def chroot():
         os.chroot(root)
 
@@ -142,7 +140,8 @@ def execWithCapture(command, argv, stdin = 0, stderr = 2, root='/'):
 
     return rc
 
-def execWithPulseProgress(command, argv, stdin = 0, stdout = 1, stderr = 2,
+def execWithPulseProgress(command, argv, stdin = sys.stdin, stdout = sys.stdout, stderr =
+                          sys.stderr,
                           progress = None, root = '/'):
     def chroot():
         os.chroot(root)
@@ -151,8 +150,6 @@ def execWithPulseProgress(command, argv, stdin = 0, stdout = 1, stderr = 2,
     if type(stdin) == type("string"):
         if os.access(stdin, os.R_OK):
             stdin = open(stdin)
-        else:
-            stdin = 0
     if type(stdout) == type("string"):
         stdout = open(stdout, "w")
     if type(stderr) == type("string"):
@@ -164,12 +161,9 @@ def execWithPulseProgress(command, argv, stdin = 0, stdout = 1, stderr = 2,
     childpid = os.fork()
     if not childpid:
         os.close(p[0])
-        os.dup2(p[1], 1)
-        os.dup2(stderr.fileno(), 2)
-        os.dup2(stdin, 0)
-        os.close(stdin)
-        os.close(p[1])
-        stderr.close()
+        os.dup2(p[1], sys.stdout.fileno())
+        os.dup2(stderr.fileno(), sys.stderr.fileno())
+        os.dup2(stdin.fileno(), sys.stdin.fileno())
 
         os.execvp(command, [command] + argv)
         os._exit(1)
-- 
1.5.4.3

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux