From 76e476dcfa8c43a1e70f998ba90caa458ba109fd Mon Sep 17 00:00:00 2001 From: David Wilson Date: Sun, 17 Sep 2017 21:09:52 +0530 Subject: [PATCH] Tidy up logging of command lines for easier cutpaste. --- mitogen/master.py | 18 ++++++++++++++---- mitogen/ssh.py | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/mitogen/master.py b/mitogen/master.py index d1f716d5..034c87a4 100644 --- a/mitogen/master.py +++ b/mitogen/master.py @@ -4,6 +4,7 @@ starting new contexts via SSH. Its size is also restricted, since it must be sent to any context that will be used to establish additional child contexts. """ +import commands import errno import getpass import imp @@ -55,6 +56,15 @@ def get_child_modules(path, fullname): return ['%s.%s' % (fullname, name) for _, name, _ in it] +def format_cmdline(args): + return ' '.join( + commands.mkarg(arg).strip() + if any(s in arg for s in (" '\"$")) else + arg + for arg in args + ) + + def create_child(*args): """Create a child process whose stdin/stdout is connected to a socket, returning `(pid, socket_obj)`.""" @@ -69,8 +79,8 @@ def create_child(*args): raise SystemExit childfp.close() - LOG.debug('create_child() child %d fd %d, parent %d, args %r', - pid, parentfp.fileno(), os.getpid(), args) + LOG.debug('create_child() child %d fd %d, parent %d, cmd: %s', + pid, parentfp.fileno(), os.getpid(), format_cmdline(args)) return pid, os.dup(parentfp.fileno()) @@ -141,8 +151,8 @@ def tty_create_child(*args): raise SystemExit os.close(slave_fd) - LOG.debug('tty_create_child() child %d fd %d, parent %d, args %r', - pid, master_fd, os.getpid(), args) + LOG.debug('tty_create_child() child %d fd %d, parent %d, cmd: %s', + pid, master_fd, os.getpid(), format_cmdline(args)) return pid, master_fd diff --git a/mitogen/ssh.py b/mitogen/ssh.py index c5668ba9..88f0edc3 100644 --- a/mitogen/ssh.py +++ b/mitogen/ssh.py @@ -62,7 +62,7 @@ class Stream(mitogen.master.Stream): ] bits.append(self.hostname) base = super(Stream, self).get_boot_command() - return bits + map(commands.mkarg, base) + return bits + [commands.mkarg(s).strip() for s in base] def connect(self): super(Stream, self).connect()