From a2cc62702fb5d6b54aa68c4a4ed2bf300e582b31 Mon Sep 17 00:00:00 2001 From: Sebastian Pipping Date: Wed, 7 Jul 2010 21:40:51 +0200 Subject: Close stdin of child processes in quiet mode --- CHANGES | 3 +++ doc/layman.8.xml | 13 +++++++------ layman/overlays/source.py | 14 ++++++++++++-- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 10b4371..707c171 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,9 @@ Version TODO - Replace os.system() by subprocess.Popen() + - Close stdin of child processes when run in quiet mode + to avoid running into infinite and blindly interactive sessions. + Version 1.3.4 - Released 2010-07-05 =================================== diff --git a/doc/layman.8.xml b/doc/layman.8.xml index 0988ff4..ccd127e 100644 --- a/doc/layman.8.xml +++ b/doc/layman.8.xml @@ -482,12 +482,13 @@ Makes layman completely quiet. - This option is dangerous: If the processes spawned by - layman when adding or synchronizing overlays require - any input layman will hang without telling you - why. This might happen for example if your overlay - resides in subversion and the SSL certificate of - the server needs acceptance. + In quiet mode child processes will be run with stdin closed + to avoid running into infinite and blindly interactive sessions. + Thus a child process may abort once it runs into an + situation with need for human interaction. + For example this might happen if your overlay + resides in Subversion and the SSL certificate of + the server needs manual acceptance. diff --git a/layman/overlays/source.py b/layman/overlays/source.py index 621cf4c..9836526 100644 --- a/layman/overlays/source.py +++ b/layman/overlays/source.py @@ -130,20 +130,30 @@ class OverlaySource(object): OUT.info('Running... # %s' % command_repr, 2) if self.quiet: + input_source = subprocess.PIPE output_target = open('/dev/null', 'w') else: - output_target = None # i.e. re-use parent file descriptors + # Re-use parent file descriptors + input_source = None + output_target = None proc = subprocess.Popen(args, + stdin=input_source, stdout=output_target, stderr=output_target, cwd=cwd, env=env) + if self.quiet: + # Make child non-interactive + proc.stdin.close() + + result = proc.wait() + if self.quiet: output_target.close() - return proc.wait() + return result def to_xml_hook(self, repo_elem): pass -- cgit v1.2.3-1-g7c22