qw(getmaintainers_reverse),
qw(getpseudodesc),
],
- misc => [qw(make_list globify_scalar)],
+ misc => [qw(make_list globify_scalar english_join checkpid)],
date => [qw(secs_to_english)],
quit => [qw(quit)],
lock => [qw(filelock unfilelock lockpid)],
for my $file (@config{qw(maintainer_file maintainer_file_override pseduo_maint_file)}) {
next unless defined $file;
my $maintfile = IO::File->new($file,'r') or
- die "Unable to open maintainer file $file: $!");
+ die "Unable to open maintainer file $file: $!";
while(<$maintfile>) {
next unless m/^(\S+)\s+(\S.*\S)\s*$/;
($a,$b)=($1,$2);
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
}
+=head2 english_join
+
+ print english_join(', ',' and ',@list);
+
+Joins list properly to make an english phrase.
+
+
+
+=cut
+
+sub english_join {
+ my ($normal,$last,@list) = @_;
+ if (@list <= 1) {
+ return @list?$list[0]:'';
+ }
+ my $ret = $last . pop(@list);
+ $ret = join($normal,@list) . $ret;
+ return $ret;
+}
+
+
=head2 globify_scalar
my $handle = globify_scalar(\$foo);