Secured daemon PID files.
They are no longer readable or writeable (whoops) by anyone other than the user who owns the process.
This commit is contained in:
parent
ea7473f18d
commit
6c517a9126
1 changed files with 3 additions and 1 deletions
|
@ -3,10 +3,11 @@
|
||||||
|
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
# This code was stolen from:
|
# This code was (mostly, with some tweaks) stolen from:
|
||||||
# http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
|
# http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/
|
||||||
|
|
||||||
import sys, os, time, atexit
|
import sys, os, time, atexit
|
||||||
|
import stat
|
||||||
from signal import SIGTERM
|
from signal import SIGTERM
|
||||||
|
|
||||||
class Daemon:
|
class Daemon:
|
||||||
|
@ -65,6 +66,7 @@ class Daemon:
|
||||||
atexit.register(self.delpid)
|
atexit.register(self.delpid)
|
||||||
pid = str(os.getpid())
|
pid = str(os.getpid())
|
||||||
file(self.pidfile,'w+').write("%s\n" % pid)
|
file(self.pidfile,'w+').write("%s\n" % pid)
|
||||||
|
os.chmod(self.pidfile, stat.S_IRUSR|stat.S_IWUSR)
|
||||||
|
|
||||||
def delpid(self):
|
def delpid(self):
|
||||||
os.remove(self.pidfile)
|
os.remove(self.pidfile)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue