MCPcopy Create free account
hub / github.com/apenwarr/sshuttle / daemonize

Function daemonize

client.py:46–69  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

44
45
46def daemonize():
47 if os.fork():
48 os._exit(0)
49 os.setsid()
50 if os.fork():
51 os._exit(0)
52
53 outfd = os.open(_pidname, os.O_WRONLY|os.O_CREAT|os.O_EXCL, 0666)
54 try:
55 os.write(outfd, '%d\n' % os.getpid())
56 finally:
57 os.close(outfd)
58 os.chdir("/")
59
60 # Normal exit when killed, or try/finally won't work and the pidfile won't
61 # be deleted.
62 signal.signal(signal.SIGTERM, got_signal)
63
64 si = open('/dev/null', 'r+')
65 os.dup2(si.fileno(), 0)
66 os.dup2(si.fileno(), 1)
67 si.close()
68
69 ssyslog.stderr_to_syslog()
70
71
72def daemon_cleanup():

Callers 1

_mainFunction · 0.85

Calls 1

writeMethod · 0.45

Tested by

no test coverage detected