mirror of
https://github.com/sshuttle/sshuttle.git
synced 2024-11-25 17:33:15 +01:00
Close stdin, stdout, and stderr when using syslog or forking to daemon (#283)
* Close stdin, stdout, and stderr when using syslog or forking to daemon Fixes #139 * Ensure we close devnull after use
This commit is contained in:
parent
7a54d12f80
commit
b473b91633
@ -59,6 +59,8 @@ def main():
|
|||||||
ipport_v6 = "auto" if not opt.disable_ipv6 else None
|
ipport_v6 = "auto" if not opt.disable_ipv6 else None
|
||||||
if opt.syslog:
|
if opt.syslog:
|
||||||
ssyslog.start_syslog()
|
ssyslog.start_syslog()
|
||||||
|
ssyslog.close_stdin()
|
||||||
|
ssyslog.stdout_to_syslog()
|
||||||
ssyslog.stderr_to_syslog()
|
ssyslog.stderr_to_syslog()
|
||||||
return_code = client.main(ipport_v6, ipport_v4,
|
return_code = client.main(ipport_v6, ipport_v4,
|
||||||
opt.ssh_cmd,
|
opt.ssh_cmd,
|
||||||
|
@ -8,12 +8,24 @@ _p = None
|
|||||||
|
|
||||||
def start_syslog():
|
def start_syslog():
|
||||||
global _p
|
global _p
|
||||||
_p = ssubprocess.Popen(['logger',
|
with open(os.devnull, 'w') as devnull:
|
||||||
'-p', 'daemon.notice',
|
_p = ssubprocess.Popen(
|
||||||
'-t', 'sshuttle'], stdin=ssubprocess.PIPE)
|
['logger', '-p', 'daemon.notice', '-t', 'sshuttle'],
|
||||||
|
stdin=ssubprocess.PIPE,
|
||||||
|
stdout=devnull,
|
||||||
|
stderr=devnull
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def close_stdin():
|
||||||
|
sys.stdin.close()
|
||||||
|
|
||||||
|
|
||||||
|
def stdout_to_syslog():
|
||||||
|
sys.stdout.flush()
|
||||||
|
os.dup2(_p.stdin.fileno(), sys.stdout.fileno())
|
||||||
|
|
||||||
|
|
||||||
def stderr_to_syslog():
|
def stderr_to_syslog():
|
||||||
sys.stdout.flush()
|
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
os.dup2(_p.stdin.fileno(), 2)
|
os.dup2(_p.stdin.fileno(), sys.stderr.fileno())
|
||||||
|
Loading…
Reference in New Issue
Block a user