Subject: | Not safe for daemonizing programs |
in check(): If the PID file exists and it was created by the current program it is not re-
created even if it contains a different PID than the current program's.
Testcase: check(); fork()/daemonize(); (re)check() -- now the PID file exists but contains an
invalid PID while the program keeps running.
Testcase 2: check; sleep(); (on other console: echo "9999" > pid.PID), check(); --- the check
succeeds but the program is NOT pid-file-protected and could be started a second time.
Workaround: clear @File::Pid::Quick::pid_files_created before calling check().
Fix:
in check():
my $recreate = undef;
if($pid != $$ and kill 0, $pid) {
[...]
}
}
elsif ($pid != $$) {
$recreate = 1;
}
close $pid_in;
}
if($recreate or not grep { $_ eq $pid_file } @pid_files_created) {
=====
PS: "my $pid_data = <$pid_in>;" should be expanded to "my $pid_data = <$pid_in>; $pid_data =
'' if not defined $PID_data;" to avoid warnings if the file has 0-length.