[WebUI] Cleanup donotdaemonize

This commit is contained in:
Calum Lind 2016-04-18 11:49:50 +01:00
commit 092d496944

View file

@ -12,7 +12,7 @@ from __future__ import print_function
import logging import logging
import os import os
from deluge.common import osx_check, run_profiled, windows_check from deluge.common import run_profiled, windows_check
from deluge.configmanager import get_config_dir from deluge.configmanager import get_config_dir
from deluge.ui.ui import UI from deluge.ui.ui import UI
@ -39,7 +39,7 @@ class Web(UI):
group.add_argument("-b", "--base", metavar="<path>", action="store", default=None, group.add_argument("-b", "--base", metavar="<path>", action="store", default=None,
help="Set the base path that the ui is running on (proxying)") help="Set the base path that the ui is running on (proxying)")
if not (windows_check() or osx_check()): if not windows_check():
group.add_argument("-d", "--do-not-daemonize", dest="donotdaemonize", action="store_true", default=False, group.add_argument("-d", "--do-not-daemonize", dest="donotdaemonize", action="store_true", default=False,
help="Do not daemonize the web interface") help="Do not daemonize the web interface")
group.add_argument("-P", "--pidfile", metavar="<pidfile>", action="store", default=None, group.add_argument("-P", "--pidfile", metavar="<pidfile>", action="store", default=None,
@ -71,23 +71,15 @@ class Web(UI):
def start(self, args=None): def start(self, args=None):
super(Web, self).start(args) super(Web, self).start(args)
# Steps taken from http://www.faqs.org/faqs/unix-faq/programmer/faq/ # If donotdaemonize is set, skip process forking.
# Section 1.7 if not (windows_check() or self.options.donotdaemonize):
if self.options.donotdaemonize is not True:
# fork() so the parent can exit, returns control to the command line
# or shell invoking the program.
if os.fork(): if os.fork():
os._exit(0) os._exit(0)
# setsid() to become a process group and session group leader.
os.setsid() os.setsid()
# Do second fork
# fork() again so the parent, (the session group leader), can exit.
if os.fork(): if os.fork():
os._exit(0) os._exit(0)
# Ensure process doesn't keep any directory in use that may prevent a filesystem unmount.
# chdir() to esnure that our process doesn't keep any directory in
# use that may prevent a filesystem unmount.
os.chdir(get_config_dir()) os.chdir(get_config_dir())
if self.options.pidfile: if self.options.pidfile: