mirror of
https://github.com/frappe/gunicorn.git
synced 2026-07-03 03:01:31 +08:00
fix: ensure pidfile fd is closed on rename failure
This commit is contained in:
parent
2d4310116d
commit
6ada1ce03a
@ -33,12 +33,14 @@ class Pidfile:
|
||||
if fdir and not os.path.isdir(fdir):
|
||||
raise RuntimeError("%s doesn't exist. Can't create pidfile." % fdir)
|
||||
fd, fname = tempfile.mkstemp(dir=fdir)
|
||||
os.write(fd, ("%s\n" % self.pid).encode('utf-8'))
|
||||
if self.fname:
|
||||
os.rename(fname, self.fname)
|
||||
else:
|
||||
self.fname = fname
|
||||
os.close(fd)
|
||||
try:
|
||||
os.write(fd, ("%s\n" % self.pid).encode('utf-8'))
|
||||
if self.fname:
|
||||
os.rename(fname, self.fname)
|
||||
else:
|
||||
self.fname = fname
|
||||
finally:
|
||||
os.close(fd)
|
||||
|
||||
# set permissions to -rw-r--r--
|
||||
os.chmod(self.fname, 420)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user