From 92cabced973e546161c6f85e387aeba7af59ae70 Mon Sep 17 00:00:00 2001 From: Shoghi Cervantes Date: Mon, 25 Aug 2014 23:24:18 +0200 Subject: [PATCH] Ctrl+C handling and kill signals are working again --- src/pocketmine/Server.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/pocketmine/Server.php b/src/pocketmine/Server.php index e59f39ec9a..f8d6b4ae9f 100644 --- a/src/pocketmine/Server.php +++ b/src/pocketmine/Server.php @@ -1822,9 +1822,10 @@ class Server{ $this->tickCounter = 0; if(function_exists("pcntl_signal")){ - pcntl_signal(SIGTERM, array($this, "shutdown")); - pcntl_signal(SIGINT, array($this, "shutdown")); - pcntl_signal(SIGHUP, array($this, "shutdown")); + pcntl_signal(SIGTERM, [$this, "handleSignal"]); + pcntl_signal(SIGINT, [$this, "handleSignal"]); + pcntl_signal(SIGHUP, [$this, "handleSignal"]); + $this->getScheduler()->scheduleRepeatingTask(new CallbackTask("pcntl_signal_dispatch"), 5); } $this->logger->info("Default game type: " . self::getGamemodeString($this->getGamemode())); //TODO: string name @@ -1837,6 +1838,12 @@ class Server{ gc_collect_cycles(); } + public function handleSignal($signo){ + if($signo === SIGTERM or $signo === SIGINT or $signo === SIGHUP){ + $this->shutdown(); + } + } + public function checkTicks(){ if($this->getTicksPerSecond() < 12){ $this->logger->warning("Can't keep up! Is the server overloaded?");