![]() |
![]()
| ![]() |
![]()
NAMEOpenXPKI::Server::Bedroom - Helper module to... err... make child processes DESCRIPTIONNote on SIGCHLDThe requirements for a proper "SIGCHLD" handling are:
The most compatible way to handle "SIGCHLD" is to set it to 'DEFAULT', letting Perl handle it. This way commands like system() will work properly. But for the "OpenXPKI::Server::Bedroom" parent process to be able to reap its child processes we need a custom "SIGCHLD" handler to call waitpid() on them. So in our custom handler we keep track of the PIDs of our own forked children and only reap those. Other children (e.g. forked via system()) are left untouched. Thus there are two usage modes:
If this object is destroyed while the $SIG{'CHLD'} still refers to our handler then children exiting later on will raise the internal Perl error "Signal SIGCHLD received, but no signal handler set." That is why in "DEMOLISH" we explicitely hand over child reaping to the operating system. But this also means after this the process will not be able to call system() and the like anymore. So a better solution is to keep this object alive as long as possible, ideally until "OpenXPKI::Server" shuts down. Also see <https://github.com/Perl/perl5/issues/17662>, might be related. Also see <https://perldoc.perl.org/perlipc#Signals>. METHODSnew_childTries to fork a child process. Return value depends on who returns: parent will get the child PID and child will get 0. An exception will be thrown if the fork fails. Note on STDIN, STDOUT, STDERR All IO handles will be connected to /dev/null with one exception: if "STDERR" was already redirected to a file (and is not a terminal) then it is left untouched. This is to make sure error messages still go to the desired log files. Parameters
get_stdout_fhReturns the STDOUT filehandle for the given child pid. Is "undef" if the child process was not started using "new_child(... capture_stdout => 1)". Parameters
DEMOLISHHand "SIGCHLD" processing over to operating system via "$SIG{'CHLD'} = 'IGNORE'", see "Note on SIGCHLD".
|