Make relative PID path absolute

The daemon changes the current directory to root.
This commit is contained in:
Unrud 2017-05-07 21:56:02 +02:00
parent 65c53df5b3
commit 6ade44c773

View File

@ -120,9 +120,9 @@ def daemonize(configuration, logger):
# Check and create PID file in a race-free manner # Check and create PID file in a race-free manner
if configuration.get("server", "pid"): if configuration.get("server", "pid"):
try: try:
pid_path = os.path.abspath(configuration.get("server", "pid"))
pid_fd = os.open( pid_fd = os.open(
configuration.get("server", "pid"), pid_path, os.O_CREAT | os.O_EXCL | os.O_WRONLY)
os.O_CREAT | os.O_EXCL | os.O_WRONLY)
except OSError as e: except OSError as e:
raise OSError("PID file exists: %s" % raise OSError("PID file exists: %s" %
configuration.get("server", "pid")) from e configuration.get("server", "pid")) from e
@ -149,7 +149,7 @@ def daemonize(configuration, logger):
# Remove PID file # Remove PID file
if (configuration.get("server", "pid") and if (configuration.get("server", "pid") and
configuration.getboolean("server", "daemon")): configuration.getboolean("server", "daemon")):
os.unlink(configuration.get("server", "pid")) os.unlink(pid_path)
atexit.register(cleanup) atexit.register(cleanup)