1
0
mirror of https://git.tt-rss.org/git/tt-rss.git synced 2025-12-15 22:55:56 +00:00

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

View File

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