Revision 8a20c732 daemons/ganeti-masterd
b/daemons/ganeti-masterd | ||
---|---|---|
427 | 427 |
# here a real node is at the top of the list |
428 | 428 |
all_votes = sum(item[1] for item in votes) |
429 | 429 |
top_node, top_votes = votes[0] |
430 |
|
|
430 | 431 |
result = False |
431 | 432 |
if top_node != myself: |
432 | 433 |
logging.critical("It seems we are not the master (top-voted node" |
... | ... | |
466 | 467 |
rpc.Shutdown() |
467 | 468 |
|
468 | 469 |
|
470 |
def _RunInSeparateProcess(fn): |
|
471 |
"""Runs a function in a separate process. |
|
472 |
|
|
473 |
Note: Only boolean return values are supported. |
|
474 |
|
|
475 |
@type fn: callable |
|
476 |
@param fn: Function to be called |
|
477 |
@rtype: bool |
|
478 |
|
|
479 |
""" |
|
480 |
pid = os.fork() |
|
481 |
if pid == 0: |
|
482 |
# Child process |
|
483 |
try: |
|
484 |
# Call function |
|
485 |
result = int(bool(fn())) |
|
486 |
assert result in (0, 1) |
|
487 |
except: |
|
488 |
logging.exception("Error while calling function in separate process") |
|
489 |
# 0 and 1 are reserved for the return value |
|
490 |
result = 33 |
|
491 |
|
|
492 |
os._exit(result) |
|
493 |
|
|
494 |
# Parent process |
|
495 |
|
|
496 |
# Avoid zombies and check exit code |
|
497 |
(_, status) = os.waitpid(pid, 0) |
|
498 |
|
|
499 |
if os.WIFSIGNALED(status): |
|
500 |
signum = os.WTERMSIG(status) |
|
501 |
exitcode = None |
|
502 |
else: |
|
503 |
signum = None |
|
504 |
exitcode = os.WEXITSTATUS(status) |
|
505 |
|
|
506 |
if not (exitcode in (0, 1) and signum is None): |
|
507 |
logging.error("Child program failed (code=%s, signal=%s)", |
|
508 |
exitcode, signum) |
|
509 |
sys.exit(constants.EXIT_FAILURE) |
|
510 |
|
|
511 |
return bool(exitcode) |
|
512 |
|
|
513 |
|
|
469 | 514 |
def ExecMasterd (options, args): |
470 | 515 |
"""Main master daemon function, executed with the PID file held. |
471 | 516 |
|
Also available in: Unified diff