1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 13:12:41 +00:00

More forking tweaks

This commit is contained in:
J. King 2021-06-25 19:43:26 -04:00
parent 577356cd3d
commit e9394e8599
3 changed files with 4 additions and 2 deletions

View file

@ -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;

View file

@ -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.

View file

@ -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)',
];