add workaround against shutdown() being called in child task context

This commit is contained in:
Andrew Dolgov 2013-02-25 21:59:26 +04:00
parent f421fcd7e5
commit cfe6d444a9
1 changed files with 8 additions and 6 deletions

View File

@ -86,12 +86,14 @@
pcntl_waitpid(-1, $status, WNOHANG);
}
function shutdown() {
function shutdown($caller_pid) {
if ($caller_pid == posix_getpid()) {
if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) {
_debug("removing lockfile (master)...");
unlink(LOCK_DIRECTORY . "/update_daemon.lock");
}
}
}
function task_shutdown() {
$pid = posix_getpid();
@ -104,7 +106,7 @@
function sigint_handler() {
_debug("[MASTER] SIG_INT received.\n");
shutdown();
shutdown(posix_getpid());
die;
}
@ -162,7 +164,7 @@
if (!$master_handlers_installed) {
_debug("[MASTER] installing shutdown handlers");
pcntl_signal(SIGINT, 'sigint_handler');
register_shutdown_function('shutdown');
register_shutdown_function('shutdown', posix_getpid());
$master_handlers_installed = true;
}