FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

 
 
LinkBack Thread Tools
 
Old 02-11-2009, 12:57 PM
Radek Vykydal
 
Default Fix execWith* functions for non-redirected use.

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@redhat.com
https://www.redhat.com/mailman/listinfo/anaconda-devel-list
 
Old 02-11-2009, 02:55 PM
Joel Granados
 
Default Fix execWith* functions for non-redirected use.

The patch looks good.

----- "Radek Vykydal" <rvykydal@redhat.com> wrote:

> 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@redhat.com
> https://www.redhat.com/mailman/listinfo/anaconda-devel-list

--
Joel Andres Granados
Red Hat / Brno Czech Republic

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

Thread Tools




All times are GMT. The time now is 08:01 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org