Subject: | DESTROY{} does the wrong thing |
This method removes PID files, whether or not they should be deleted.
sub DESTROY {
my $self = shift;
$self->remove() if $self->{path};
}
What it is meant to do, is remove the PID file when the owning process exits. However, what it does do is remove the PID file whenever a process exits that has created a Proc::PID::File object (i.e. any process that has called the new() constructor method).
Here's where I noticed the problem.
1. First long-running process starts and creates a PID file.
2. Second process starts, calls alive() to see whether another process is running, and exits because of existing PID file. On exit, the DESTROY method is called, which removes the PID file.
3. Third process starts, calls alive() to see whether another process is running, and falsely creates a fresh PID file.
The following alteration fixes the bug. Attached is a tarfile, with amended module, Changes, and test.pl which fails under old version and passes under new version.
sub DESTROY {
my $self = shift;
my $pid = $self->read();
$self->remove() if $self->{path} && $pid && $pid == $$;
}
Message body not shown because it is not plain text.