From e9394e8599bc421fe8bb3467b2b977036dd02013 Mon Sep 17 00:00:00 2001 From: "J. King" Date: Fri, 25 Jun 2021 19:43:26 -0400 Subject: [PATCH] More forking tweaks --- lib/AbstractException.php | 1 + lib/Service/Daemon.php | 4 ++-- locale/en.php | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/AbstractException.php b/lib/AbstractException.php index 968f9e7..501634d 100644 --- a/lib/AbstractException.php +++ b/lib/AbstractException.php @@ -113,6 +113,7 @@ abstract class AbstractException extends \Exception { "Service/Exception.pidDuplicate" => 10809, "Service/Exception.pidLocked" => 10810, "Service/Exception.pidInaccessible" => 10811, + "Service/Exception.forkFailed" => 10812, ]; protected $symbol; diff --git a/lib/Service/Daemon.php b/lib/Service/Daemon.php index f5ae3d1..ef44ceb 100644 --- a/lib/Service/Daemon.php +++ b/lib/Service/Daemon.php @@ -30,7 +30,7 @@ class Daemon { switch (@pcntl_fork()) { case -1: // Unable to fork - throw new \Exception("Unable to fork"); + throw new Exception("forkFailed", ['instance' => 1]); case 0: fclose($pipe[0]); # In the child, call setsid() to detach from any terminal and create an independent session. @@ -39,7 +39,7 @@ class Daemon { switch (@pcntl_fork()) { case -1: // Unable to fork - throw new \Exception("Unable to fork"); + throw new Exception("forkFailed", ['instance' => 2]); case 0: // We do some things out of order because as far as I know there's no way to reconnect stdin, stdout, and stderr without closing the channel to the parent first # In the daemon process, write the daemon PID (as returned by getpid()) to a PID file, for example /run/foobar.pid (for a hypothetical daemon "foobar") to ensure that the daemon cannot be started more than once. This must be implemented in race-free fashion so that the PID file is only updated when it is verified at the same time that the PID previously stored in the PID file no longer exists or belongs to a foreign process. diff --git a/locale/en.php b/locale/en.php index a0de158..0189866 100644 --- a/locale/en.php +++ b/locale/en.php @@ -219,4 +219,5 @@ return [ 'Exception.JKingWeb/Arsse/Service/Exception.pidDuplicate' => 'Service is already running with process identifier {pid}', 'Exception.JKingWeb/Arsse/Service/Exception.pidLocked' => 'PID file "{pidfile}" is locked', 'Exception.JKingWeb/Arsse/Service/Exception.pidInaccessible' => 'Unable to open PID file "{pidfile}"', + 'Exception.JKingWeb/Arsse/Service/Exception.forkFailed' => 'Failed to spawn child process ({instance, ordinal} instance)', ];