mirror of
https://github.com/sshuttle/sshuttle.git
synced 2024-11-22 07:53:43 +01:00
3a25f709e5
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).
31 lines
541 B
Python
31 lines
541 B
Python
import sys, os
|
|
|
|
logprefix = ''
|
|
verbose = 0
|
|
|
|
def log(s):
|
|
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:
|
|
log(s)
|
|
|
|
def debug2(s):
|
|
if verbose >= 2:
|
|
log(s)
|
|
|
|
def debug3(s):
|
|
if verbose >= 3:
|
|
log(s)
|
|
|
|
|
|
class Fatal(Exception):
|
|
pass
|