From cfe6d444a99beb9085036374adfbd6dd5886f8bf Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Mon, 25 Feb 2013 21:59:26 +0400 Subject: [PATCH] add workaround against shutdown() being called in child task context --- update_daemon2.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/update_daemon2.php b/update_daemon2.php index b2b2cc98..4b6a4399 100755 --- a/update_daemon2.php +++ b/update_daemon2.php @@ -86,10 +86,12 @@ pcntl_waitpid(-1, $status, WNOHANG); } - function shutdown() { - if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) { - _debug("removing lockfile (master)..."); - unlink(LOCK_DIRECTORY . "/update_daemon.lock"); + 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"); + } } } @@ -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; } -- 2.39.2