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

Function check_daemon

client.py:15–43  ·  view source on GitHub ↗
(pidfile)

Source from the content-addressed store, hash-verified

13
14_pidname = None
15def check_daemon(pidfile):
16 global _pidname
17 _pidname = os.path.abspath(pidfile)
18 try:
19 oldpid = open(_pidname).read(1024)
20 except IOError, e:
21 if e.errno == errno.ENOENT:
22 return # no pidfile, ok
23 else:
24 raise Fatal("can't read %s: %s" % (_pidname, e))
25 if not oldpid:
26 os.unlink(_pidname)
27 return # invalid pidfile, ok
28 oldpid = int(oldpid.strip() or 0)
29 if oldpid <= 0:
30 os.unlink(_pidname)
31 return # invalid pidfile, ok
32 try:
33 os.kill(oldpid, 0)
34 except OSError, e:
35 if e.errno == errno.ESRCH:
36 os.unlink(_pidname)
37 return # outdated pidfile, ok
38 elif e.errno == errno.EPERM:
39 pass
40 else:
41 raise
42 raise Fatal("%s: sshuttle is already running (pid=%d)"
43 % (_pidname, oldpid))
44
45
46def daemonize():

Callers 1

mainFunction · 0.85

Calls 2

FatalClass · 0.85
killMethod · 0.45

Tested by

no test coverage detected