Commit 7b4baeb1 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

utils: Use function to disable fork

Use a function instead of a variable written by another module.
Signed-off-by: default avatarMichael Hanselmann <>
Reviewed-by: default avatarIustin Pop <>
parent 8342c325
......@@ -620,7 +620,8 @@ def GenericMain(daemon_name, optionparser,
# Disable the use of fork(2) if the daemon uses threads
utils.no_fork = multithreaded
if multithreaded:
options, args = optionparser.parse_args()
......@@ -62,7 +62,7 @@ from ganeti.utils.hash import * # pylint: disable-msg=W0401
#: when set to True, L{RunCmd} is disabled
no_fork = False
_no_fork = False
_RANDOM_UUID_FILE = "/proc/sys/kernel/random/uuid"
......@@ -93,6 +93,15 @@ _SHELLPARAM_REGEX = re.compile(r"^[-a-zA-Z0-9._+/:%@]+$")
_ASN1_TIME_REGEX = re.compile(r"^(\d+)([-+]\d\d)(\d\d)$")
def DisableFork():
"""Disables the use of fork(2).
global _no_fork # pylint: disable-msg=W0603
_no_fork = True
class RunResult(object):
"""Holds the result of running external programs.
......@@ -203,7 +212,7 @@ def RunCmd(cmd, env=None, output=None, cwd="/", reset_env=False,
@raise errors.ProgrammerError: if we call this when forks are disabled
if no_fork:
if _no_fork:
raise errors.ProgrammerError("utils.RunCmd() called with fork() disabled")
if output and interactive:
......@@ -318,7 +327,7 @@ def StartDaemon(cmd, env=None, cwd="/", output=None, output_fd=None,
@raise errors.ProgrammerError: if we call this when forks are disabled
if no_fork:
if _no_fork:
raise errors.ProgrammerError("utils.StartDaemon() called with fork()"
" disabled")
......@@ -366,12 +366,13 @@ class TestRunCmd(testutils.GanetiTestCase):
def testNoFork(self):
"""Test that nofork raise an error"""
assert not utils.no_fork
utils.no_fork = True
self.assertRaises(errors.ProgrammerError, RunCmd, ["true"])
utils.no_fork = False
utils._no_fork = False
def testWrongParams(self):
"""Test wrong parameters"""
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment