daemon.GenericMain: Don't use list of multithreaded daemons
authorMichael Hanselmann <hansmi@google.com>
Fri, 27 Nov 2009 16:13:06 +0000 (17:13 +0100)
committerMichael Hanselmann <hansmi@google.com>
Tue, 1 Dec 2009 13:29:34 +0000 (14:29 +0100)
Passing it in as a parameter seems more logical.

Signed-off-by: Michael Hanselmann <hansmi@google.com>
Reviewed-by: Guido Trotter <ultrotter@google.com>

daemons/ganeti-masterd
lib/constants.py
lib/daemon.py

index 3a77be4..392bfac 100755 (executable)
@@ -602,7 +602,8 @@ def main():
           (constants.SOCKET_DIR, constants.SOCKET_DIR_MODE),
          ]
   daemon.GenericMain(constants.MASTERD, parser, dirs,
-                     CheckMasterd, ExecMasterd)
+                     CheckMasterd, ExecMasterd,
+                     multithreaded=True)
 
 
 if __name__ == "__main__":
index d2ad24d..b4d82f8 100644 (file)
@@ -118,8 +118,6 @@ CONFD = "ganeti-confd"
 RAPI = "ganeti-rapi"
 MASTERD = "ganeti-masterd"
 
-MULTITHREADED_DAEMONS = frozenset([MASTERD])
-
 DAEMONS_SSL = {
   # daemon-name: (default-cert-path, default-key-path)
   NODED: (SSL_CERT_FILE, SSL_CERT_FILE),
index 6818d7d..569b84d 100644 (file)
@@ -221,7 +221,8 @@ class Mainloop(object):
     self._signal_wait.append(owner)
 
 
-def GenericMain(daemon_name, optionparser, dirs, check_fn, exec_fn):
+def GenericMain(daemon_name, optionparser, dirs, check_fn, exec_fn,
+                multithreaded=False):
   """Shared main function for daemons.
 
   @type daemon_name: string
@@ -237,6 +238,8 @@ def GenericMain(daemon_name, optionparser, dirs, check_fn, exec_fn):
   @type exec_fn: function which accepts (options, args)
   @param exec_fn: function that's executed with the daemon's pid file held, and
                   runs the daemon itself.
+  @type multithreaded: bool
+  @param multithreaded: Whether the daemon uses threads
 
   """
   optionparser.add_option("-f", "--foreground", dest="fork",
@@ -271,7 +274,8 @@ def GenericMain(daemon_name, optionparser, dirs, check_fn, exec_fn):
                             help="SSL certificate",
                             default=default_cert, type="string")
 
-  multithread = utils.no_fork = daemon_name in constants.MULTITHREADED_DAEMONS
+  # Disable the use of fork(2) if the daemon uses threads
+  utils.no_fork = multithreaded
 
   options, args = optionparser.parse_args()
 
@@ -298,7 +302,7 @@ def GenericMain(daemon_name, optionparser, dirs, check_fn, exec_fn):
     utils.SetupLogging(logfile=constants.DAEMONS_LOGFILES[daemon_name],
                        debug=options.debug,
                        stderr_logging=not options.fork,
-                       multithreaded=multithread)
+                       multithreaded=multithreaded)
     logging.info("%s daemon startup", daemon_name)
     exec_fn(options, args)
   finally: