Skip to content

Commit 9a77d03

Browse files
vieirabrianmay
authored andcommitted
Respect --syslog as soon as possible
When executing with the option --syslog start redirecting to syslog immediately after the command line options are validated. This way when using with some init daemon, e.g., upstart all the relevant information (connection failures, etc) can be retrieved from the log instead of being lost to stdout or stderr.
1 parent 4fdd715 commit 9a77d03

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

sshuttle/__main__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import sshuttle.client as client
77
import sshuttle.firewall as firewall
88
import sshuttle.hostwatch as hostwatch
9+
import sshuttle.ssyslog as ssyslog
910
from sshuttle.helpers import family_ip_tuple, log, Fatal
1011

1112

@@ -197,6 +198,9 @@ def parse_list(list):
197198
ipport_v6 = parse_ipport6(ip)
198199
else:
199200
ipport_v4 = parse_ipport4(ip)
201+
if opt.syslog:
202+
ssyslog.start_syslog()
203+
ssyslog.stderr_to_syslog()
200204
return_code = client.main(ipport_v6, ipport_v4,
201205
opt.ssh_cmd,
202206
remotename,
@@ -209,7 +213,7 @@ def parse_list(list):
209213
opt.auto_nets,
210214
parse_subnets(includes),
211215
parse_subnets(excludes),
212-
opt.syslog, opt.daemon, opt.pidfile)
216+
opt.daemon, opt.pidfile)
213217

214218
if return_code == 0:
215219
log('Normal exit code, exiting...')

sshuttle/client.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ def daemonize():
8181
os.dup2(si.fileno(), 1)
8282
si.close()
8383

84-
ssyslog.stderr_to_syslog()
85-
8684

8785
def daemon_cleanup():
8886
try:
@@ -389,8 +387,7 @@ def ondns(listener, method, mux, handlers):
389387

390388
def _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename,
391389
python, latency_control,
392-
dns_listener, seed_hosts, auto_nets,
393-
syslog, daemon):
390+
dns_listener, seed_hosts, auto_nets, daemon):
394391

395392
debug1('Starting client with Python version %s\n'
396393
% platform.python_version())
@@ -440,15 +437,11 @@ def _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename,
440437
if initstring != expected:
441438
raise Fatal('expected server init string %r; got %r'
442439
% (expected, initstring))
443-
debug1('connected.\n')
444-
print('Connected.')
440+
log('Connected.\n')
445441
sys.stdout.flush()
446442
if daemon:
447443
daemonize()
448444
log('daemonizing (%s).\n' % _pidname)
449-
elif syslog:
450-
debug1('switching to syslog.\n')
451-
ssyslog.stderr_to_syslog()
452445

453446
def onroutes(routestr):
454447
if auto_nets:
@@ -500,10 +493,8 @@ def onhostlist(hostlist):
500493
def main(listenip_v6, listenip_v4,
501494
ssh_cmd, remotename, python, latency_control, dns, nslist,
502495
method_name, seed_hosts, auto_nets,
503-
subnets_include, subnets_exclude, syslog, daemon, pidfile):
496+
subnets_include, subnets_exclude, daemon, pidfile):
504497

505-
if syslog:
506-
ssyslog.start_syslog()
507498
if daemon:
508499
try:
509500
check_daemon(pidfile)
@@ -651,8 +642,7 @@ def main(listenip_v6, listenip_v4,
651642
try:
652643
return _main(tcp_listener, udp_listener, fw, ssh_cmd, remotename,
653644
python, latency_control, dns_listener,
654-
seed_hosts, auto_nets, syslog,
655-
daemon)
645+
seed_hosts, auto_nets, daemon)
656646
finally:
657647
try:
658648
if daemon:

0 commit comments

Comments
 (0)