summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorScott Moser <smoser@ubuntu.com>2012-07-16 16:46:22 -0400
committerScott Moser <smoser@ubuntu.com>2012-07-16 16:46:22 -0400
commita37d2ee7d61bfc0a59590f76bb8426d4bf5dd1b1 (patch)
tree91d3043b410812b1f986cf9b4af89c7641239dd7 /cloudinit/util.py
parent1bac4c2eef943157d190a06f775321675784a7ea (diff)
downloadvyos-cloud-init-a37d2ee7d61bfc0a59590f76bb8426d4bf5dd1b1.tar.gz
vyos-cloud-init-a37d2ee7d61bfc0a59590f76bb8426d4bf5dd1b1.zip
improve debug via _CLOUD_INIT_SAVE_STDIN and _CLOUD_INIT_SAVE_STDOUT
This does 2 things: a.) fixes broken logic in 'close_stdin' previously _CLOUD_INIT_SAVE_STDIN had to be set to false to preserve stdin. "save_stdin" should be true to indicate it should be saved. The net result is that you can stuff just add import pdb; pdb.set_trace() to code, and then run something like: sudo _CLOUD_INIT_SAVE_STDIN=1 _CLOUD_INIT_SAVE_STDOUT=1 \ cloud-init single --name=mounts --frequency=always And enter the debugger even if you had a 'output' that would redirect stdin/out by default, like: output: {all: '| tee -a /var/log/cloud-init-output.log'}
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index 23b67d48..6eb2a10e 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -406,7 +406,16 @@ def fixup_output(cfg, mode):
#
# with a '|', arguments are passed to shell, so one level of
# shell escape is required.
+#
+# if _CLOUD_INIT_SAVE_STDOUT is set in environment to a non empty and true
+# value then output input will not be closed (useful for debugging).
+#
def redirect_output(outfmt, errfmt, o_out=None, o_err=None):
+
+ if is_true(os.environ.get("_CLOUD_INIT_SAVE_STDOUT")):
+ LOG.debug("Not redirecting output due to _CLOUD_INIT_SAVE_STDOUT")
+ return
+
if not o_out:
o_out = sys.stdout
if not o_err:
@@ -853,10 +862,10 @@ def close_stdin():
reopen stdin as /dev/null so even subprocesses or other os level things get
/dev/null as input.
- if _CLOUD_INIT_SAVE_STDIN is set in environment to a non empty or '0' value
- then input will not be closed (only useful potentially for debugging).
+ if _CLOUD_INIT_SAVE_STDIN is set in environment to a non empty and true
+ value then input will not be closed (useful for debugging).
"""
- if is_false(os.environ.get("_CLOUD_INIT_SAVE_STDIN")):
+ if is_true(os.environ.get("_CLOUD_INIT_SAVE_STDIN")):
return
with open(os.devnull) as fp:
os.dup2(fp.fileno(), sys.stdin.fileno())