qw(getmaintainers_reverse),
qw(getpseudodesc),
],
- misc => [qw(make_list globify_scalar english_join)],
+ misc => [qw(make_list globify_scalar english_join checkpid)],
date => [qw(secs_to_english)],
quit => [qw(quit)],
lock => [qw(filelock unfilelock lockpid)],
# getbuglocation() directly first.
return undef if defined $location and
($location ne 'db' and $location ne 'db-h');
+ # if there is no location, the bug doesn't exist
+ return undef if not defined $location;
}
my $dir = getlocationpath($location);
return undef if not defined $dir;
sub lockpid {
my ($pidfile) = @_;
if (-e $pidfile) {
- my $pidfh = IO::File->new($pidfile, 'r') or
- die "Unable to open pidfile $pidfile: $!";
- local $/;
- my $pid = <$pidfh>;
- ($pid) = $pid =~ /(\d+)/;
- if (defined $pid and kill(0,$pid)) {
- return 0;
- }
- close $pidfh;
+ my $pid = checkpid($pidfile);
+ die "Unable to read pidfile $pidfile: $!" if not defined $pid;
+ return 0 if $pid != 0;
unlink $pidfile or
die "Unable to unlink stale pidfile $pidfile $!";
}
return 1;
}
+=head2 checkpid
+
+ checkpid('/path/to/pidfile');
+
+Checks a pid file and determines if the process listed in the pidfile
+is still running. Returns the pid if it is, 0 if it isn't running, and
+undef if the pidfile doesn't exist or cannot be read.
+
+=cut
+
+sub checkpid{
+ my ($pidfile) = @_;
+ if (-e $pidfile) {
+ my $pidfh = IO::File->new($pidfile, 'r') or
+ return undef;
+ local $/;
+ my $pid = <$pidfh>;
+ close $pidfh;
+ ($pid) = $pid =~ /(\d+)/;
+ if (defined $pid and kill(0,$pid)) {
+ return $pid;
+ }
+ return 0;
+ }
+ else {
+ return undef;
+ }
+}
+
=head1 QUIT