MT#55283 support shutdown callback

Change-Id: I4eee25fa3b6852b8c2ec5b656cceac955f228bcd
pull/2149/head
Richard Fuchs 2 weeks ago
parent 60c2a1f8c1
commit 9c79476802

@ -412,21 +412,31 @@ sub use_json {
$c->{json} = $bool;
}
sub shut_rtpe {
my ($cb) = @_;
END {
if ($rtpe_pid) {
kill('INT', $rtpe_pid) or terminate("cannot interrupt rtpe");
# wait for daemon to terminate
my $status = -1;
for (1 .. 50) {
$status = waitpid($rtpe_pid, WNOHANG);
last if $status != 0;
Time::HiRes::usleep(100000); # 100 ms x 50 = 5 sec
}
kill('KILL', $rtpe_pid) if $status == 0;
$status == $rtpe_pid or terminate("cannot wait for process $rtpe_pid: $status: $!");
$? == 0 or terminate("process exited with $?");
return unless $rtpe_pid;
kill('INT', $rtpe_pid) or terminate("cannot interrupt rtpe");
$cb and $cb->();
# wait for daemon to terminate
my $status = -1;
for (1 .. 50) {
$status = waitpid($rtpe_pid, WNOHANG);
last if $status != 0;
Time::HiRes::usleep(100000); # 100 ms x 50 = 5 sec
}
kill('KILL', $rtpe_pid) if $status == 0;
$status == $rtpe_pid or terminate("cannot wait for process $rtpe_pid: $status: $!");
$? == 0 or terminate("process exited with $?");
undef $rtpe_pid;
}
END {
shut_rtpe();
}

Loading…
Cancel
Save