From 62d6165351b39f78d6fbadb0cccfe1751971b5f1 Mon Sep 17 00:00:00 2001 From: frytimo Date: Sat, 12 Jul 2025 11:13:29 -0300 Subject: [PATCH] Fix service parent class failed to remove PID file after shutdown (#7422) Fixes the following: - The service would exit but fail to remove the PID file when the shutdown command was sent to the service. Added the following: - Better feedback during service start up if the PID fails to be created - Appropriate POSIX error codes on failure of modifying the PID file --- resources/classes/service.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/resources/classes/service.php b/resources/classes/service.php index 5ed9f7ca5f..081a20785a 100644 --- a/resources/classes/service.php +++ b/resources/classes/service.php @@ -299,12 +299,12 @@ abstract class service { if (function_exists('posix_getsid')) { if (posix_getsid($pid) !== false) { //return the pid for reloading configuration - return $pid; + return intval($pid); } } else { if (file_exists('/proc/' . $pid)) { //return the pid for reloading configuration - return $pid; + return intval($pid); } } } @@ -321,7 +321,11 @@ abstract class service { // Remove the old pid file if (file_exists(self::$pid_file)) { - unlink(self::$pid_file); + if (is_writable(self::$pid_file)) { + unlink(self::$pid_file); + } else { + throw new \RuntimeException("Unable to write to PID file " . self::$pid_file, 73); //Unix error code 73 - unable to write/create file + } } // Show the details to the user @@ -330,7 +334,10 @@ abstract class service { self::log("PID File : " . self::$pid_file, LOG_INFO); // Save the pid file - file_put_contents(self::$pid_file, $pid); + $success = file_put_contents(self::$pid_file, $pid); + if ($success === false) { + throw new \RuntimeException("Failed writing to PID file " . self::$pid_file, 74); //Unix error code 74 - I/O error + } } /**