Revision 7b4baeb1

b/lib/daemon.py
620 620
                            metavar="SSL_CERT_PATH")
621 621

  
622 622
  # Disable the use of fork(2) if the daemon uses threads
623
  utils.no_fork = multithreaded
623
  if multithreaded:
624
    utils.DisableFork()
624 625

  
625 626
  options, args = optionparser.parse_args()
626 627

  
b/lib/utils/__init__.py
62 62

  
63 63

  
64 64
#: when set to True, L{RunCmd} is disabled
65
no_fork = False
65
_no_fork = False
66 66

  
67 67
_RANDOM_UUID_FILE = "/proc/sys/kernel/random/uuid"
68 68

  
......
93 93
_ASN1_TIME_REGEX = re.compile(r"^(\d+)([-+]\d\d)(\d\d)$")
94 94

  
95 95

  
96
def DisableFork():
97
  """Disables the use of fork(2).
98

  
99
  """
100
  global _no_fork # pylint: disable-msg=W0603
101

  
102
  _no_fork = True
103

  
104

  
96 105
class RunResult(object):
97 106
  """Holds the result of running external programs.
98 107

  
......
203 212
  @raise errors.ProgrammerError: if we call this when forks are disabled
204 213

  
205 214
  """
206
  if no_fork:
215
  if _no_fork:
207 216
    raise errors.ProgrammerError("utils.RunCmd() called with fork() disabled")
208 217

  
209 218
  if output and interactive:
......
318 327
  @raise errors.ProgrammerError: if we call this when forks are disabled
319 328

  
320 329
  """
321
  if no_fork:
330
  if _no_fork:
322 331
    raise errors.ProgrammerError("utils.StartDaemon() called with fork()"
323 332
                                 " disabled")
324 333

  
b/test/ganeti.utils_unittest.py
366 366

  
367 367
  def testNoFork(self):
368 368
    """Test that nofork raise an error"""
369
    assert not utils.no_fork
370
    utils.no_fork = True
369
    self.assertFalse(utils._no_fork)
370
    utils.DisableFork()
371 371
    try:
372
      self.assertTrue(utils._no_fork)
372 373
      self.assertRaises(errors.ProgrammerError, RunCmd, ["true"])
373 374
    finally:
374
      utils.no_fork = False
375
      utils._no_fork = False
375 376

  
376 377
  def testWrongParams(self):
377 378
    """Test wrong parameters"""

Also available in: Unified diff