Subject: | [PATCH] Add support for Cygwin |
The attached patch adds support for the Cygwin platform.
Subject: | patch.txt |
diff -urN Proc-PID-File-1.25.orig/File.pm Proc-PID-File-1.25/File.pm
--- Proc-PID-File-1.25.orig/File.pm 2009-09-26 21:50:51.000000000 -0400
+++ Proc-PID-File-1.25/File.pm 2009-09-28 16:43:32.221628400 -0400
@@ -75,11 +75,17 @@
=item I<verify> = 1 | string
-This parameter helps prevent the problem described in the WARNING section below. If set to a string, it will be interpreted as a I<regular expression> and used to search within the name of the running process. A 1 may also be passed, indicating that the value of I<$0> should be used (stripped of its full path). If the parameter is not passed, no verification will take place.
+This parameter helps prevent the problem described in the WARNING section
+below. If set to a string, it will be interpreted as a I<regular expression>
+and used to search within the name of the running process. A 1 may also be
+passed: For Linux and FreeBSD, this indicates that the value of I<$0> should
+be used (stripped of its full path), and for Cygwin, I<$^X> (stripped of its
+full path and extension). If the parameter is not passed, no verification
+will take place.
Please note that verification will only work for the operating systems listed below and that the os will be auto-sensed. See also DEPENDENCIES section below.
-Supported platforms: Linux, FreeBSD
+Supported platforms: Linux, FreeBSD, Cygwin
=item I<debug>
@@ -121,13 +127,18 @@
my ($self, $pid) = @_;
return 1 unless $self->{verify};
- eval "use Config";
- die "$@\nCannot use the Config module. Please install.\n" if $@;
-
- $self->debug("verifying on: $Config::Config{osname}");
- if ($Config::Config{osname} =~ /linux|freebsd/i) {
+ $self->debug("verifying on: $^O");
+ if ($^O =~ /linux|freebsd|cygwin/i) {
my $me = $self->{verify};
- ($me = $0) =~ s|.*/|| if !$me || $me eq "1";
+ if (!$me || $me eq "1") {
+ if ($^O eq 'cygwin') {
+ $^X =~ m|([^/]+)$|;
+ $me = $1;
+ $me =~ s/\.exe$//;
+ } else {
+ $me = $ME;
+ }
+ }
my @ps = split m|$/|, qx/ps -fp $pid/
|| die "ps utility not available: $!";
s/^\s+// for @ps; # leading spaces confuse us
@@ -207,7 +218,10 @@
=head1 DEPENDENCIES
-For Linux and FreeBSD, support of the I<verify> option (simple interface) requires the B<ps> utility to be available. This is typically found in the B<procps> RPM.
+For Linux, FreeBSD and Cygwin, support of the I<verify> option (simple
+interface) requires the B<ps> utility to be available. For Linux and FreeBSD,
+this is typically found in the B<procps> RPM. For Cygwin, you must be using
+version 1.5.20 or later for this to work.
=head1 WARNING
diff -urN Proc-PID-File-1.25.orig/test.pl Proc-PID-File-1.25/test.pl
--- Proc-PID-File-1.25.orig/test.pl 2009-09-26 21:13:27.000000000 -0400
+++ Proc-PID-File-1.25/test.pl 2009-09-28 16:43:47.771189900 -0400
@@ -61,8 +61,12 @@
my $rc = Proc::PID::File->running(%args);
ok($rc, "running");
-$rc = Proc::PID::File->running(%args, verify => 1);
-ok($rc, "verified: real");
+SKIP: {
+ skip('Verify not supported on this platform', 1)
+ if ($^O !~ /linux|freebsd|cygwin/i);
+ $rc = Proc::PID::File->running(%args, verify => 1);
+ ok($rc, "verified: real");
+}
# WARNING: the following test takes over the pidfile from the
# daemon such that he cannot clean it up. this is as it should be