summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvery Pennarun <apenwarr@gmail.com>2010-05-16 17:55:46 -0400
committerAvery Pennarun <apenwarr@gmail.com>2010-05-16 17:57:18 -0400
commit3a25f709e5aa318f40476beae549389c29138170 (patch)
tree9a848bdcce174f493b819e7a53ed0364a644a0de
parenta8b3d6985626abf8af60f9debb0cb4f0b63a7852 (diff)
log(): don't abort if we fail to write to stderr.
Failing to write to the log sucks, but not as much as failing to clean up just because stderr disappeared. So let's catch any IOError exception from log() and just ignore it. This should fix a problem reported by Camille Moncelier, which is that sshuttle firewall entries stick around if your tty dies strangely (eg. your X server aborts for some reason).
-rw-r--r--helpers.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/helpers.py b/helpers.py
index e43eea2..8793417 100644
--- a/helpers.py
+++ b/helpers.py
@@ -4,9 +4,14 @@ logprefix = ''
verbose = 0
def log(s):
- sys.stdout.flush()
- sys.stderr.write(logprefix + s)
- sys.stderr.flush()
+ try:
+ sys.stdout.flush()
+ sys.stderr.write(logprefix + s)
+ sys.stderr.flush()
+ except IOError:
+ # this could happen if stderr gets forcibly disconnected, eg. because
+ # our tty closes. That sucks, but it's no reason to abort the program.
+ pass
def debug1(s):
if verbose >= 1: