diff --git a/PBot/Factoids.pm b/PBot/Factoids.pm index 9c516c88..b95cb3e1 100644 --- a/PBot/Factoids.pm +++ b/PBot/Factoids.pm @@ -845,7 +845,17 @@ sub interpreter { return ""; } - return $self->handle_action($stuff, $action); + if ($self->{factoids}->get_data($channel, $keyword, 'background-process')) { + my $timeout = $self->{factoids}->get_data($channel, $keyword, 'process-timeout') // $self->{pbot}->{registry}->get_value('processmanager', 'default_timeout'); + $self->{pbot}->{process_manager}->execute_process( + $stuff, + sub { $stuff->{result} = $self->handle_action($stuff, $action); }, + $timeout + ); + return ""; + } else { + return $self->handle_action($stuff, $action); + } } sub handle_action { diff --git a/PBot/ProcessManager.pm b/PBot/ProcessManager.pm index 3910af04..d34a7b9a 100644 --- a/PBot/ProcessManager.pm +++ b/PBot/ProcessManager.pm @@ -148,6 +148,12 @@ sub execute_process { if (not exists $stuff->{commands}) { $stuff->{commands} = [$stuff->{command}]; } + # don't fork again if we're already a forked process + if (exists $stuff->{pid}) { + $subref->($stuff); + return $stuff->{result}; + } + pipe(my $reader, my $writer); $stuff->{pid} = fork;