diff options
author | Scott Kuhl <kuhl@mtu.edu> | 2022-01-07 13:05:42 -0500 |
---|---|---|
committer | Scott Kuhl <kuhl@mtu.edu> | 2022-01-07 13:13:37 -0500 |
commit | 8e826cfa7d64f5baa60c074d63e9bfe7076c5cd3 (patch) | |
tree | 05c07506fc60060179713e976805fcebb5be8a26 /sshuttle/helpers.py | |
parent | 286bd3fa8058adc5fa475e4dd032ba54a029308c (diff) |
Print to console with \r\n line endings.
If we run sudo with the use_pty option, the firewall process is
started in a new pseudoterminal. Other processes that are still
printing to the terminal (i.e., the main sshuttle client process,
messages from the shuttle server) have their output incorreclty
displayed. A newline character simply moves the output to the next
line without returning the cursor to the beginning of the line. Simply
changing all print commands to use \r\n line endings fixes the problem
and does not appear to cause any trouble in other configurations.
Diffstat (limited to 'sshuttle/helpers.py')
-rw-r--r-- | sshuttle/helpers.py | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/sshuttle/helpers.py b/sshuttle/helpers.py index 372feb3..8ff536a 100644 --- a/sshuttle/helpers.py +++ b/sshuttle/helpers.py @@ -18,15 +18,19 @@ def log(s): # Put newline at end of string if line doesn't have one. if not s.endswith("\n"): s = s+"\n" - # Allow multi-line messages - if s.find("\n") != -1: - prefix = logprefix - s = s.rstrip("\n") - for line in s.split("\n"): - sys.stderr.write(prefix + line + "\n") - prefix = " " - else: - sys.stderr.write(logprefix + s) + + prefix = logprefix + s = s.rstrip("\n") + for line in s.split("\n"): + # We output with \r\n instead of \n because when we use + # sudo with the use_pty option, the firewall process, the + # other processes printing to the terminal will have the + # \n move to the next line, but they will fail to reset + # cursor to the beginning of the line. Printing output + # with \r\n endings fixes that problem and does not appear + # to cause problems elsewhere. + sys.stderr.write(prefix + line + "\r\n") + prefix = " " sys.stderr.flush() except IOError: # this could happen if stderr gets forcibly disconnected, eg. because |