Skip Menu |

This queue is for tickets about the Proc-PID-File CPAN distribution.

Report information
The Basics
Id: 15015
Status: open
Priority: 0/
Queue: Proc-PID-File

People
Owner: Nobody in particular
Requestors: qha [...] lysator.liu.se
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.24
Fixed in: (no value)



Subject: verify should not fail when the program was started with low $ENV{COLUMNS}
I asume the form until now has already included that my problem is with Proc::PID::File 1.24. Perl version: v5.8.7 built for i386-linux-thread-multi Operating System: Debian GNU/Linux; testing/unstable The file that contains the module has the following line in it: $Id: File.pm,v 1.16 2004/04/08 02:27:25 ekkis Exp $ Steps to reproduce: # echo $COLUMNS 80 # cat > short-example-of-bad-verify.pl <<'EOF' #! /usr/bin/perl use strict; use warnings; use Proc::PID::File; die "Already running!" if Proc::PID::File->running(verify => 1); while (1) { sleep 20; } EOF # chmod +x short-example-of-bad-verify.pl # ./short-example-of-bad-verify.pl& # ./short-example-of-bad-verify.pl& # pgrep short-ex 21481 21482 # echo Notice that there are now two processes running. Notice that there are now two processes running. # echo 'Maximize your terminal emulator!' Maximize your terminal emulator! # echo $COLUMNS 191 # ./short-example-of-bad-verify.pl Already running! at ./short-example-of-bad-verify.pl line 7. The reason for this is that `ps -fp $pid' adjusts its output to the width of the terminal resulting in no match for grep /$me/ unless $ENV{COLUMNS} is way high. I had expected the second invocation of short-example-of-bad-verify.pl to fail stating "Already running!...". "looking at /proc/$PID/stat for a process name" as suggested in the POD or possibly /proc/$PID/cmdline (at least at GNU/Linux) is probably a better solution than relying on ps.
Subject: [PATCH] verify should not fail when the program was started with low $ENV{COLUMNS}
The attached patch fixes this problem. On Tue Oct 11 18:04:01 2005, guest wrote: Show quoted text
> I asume the form until now has already included that my problem is > with Proc::PID::File 1.24. > > Perl version: v5.8.7 built for i386-linux-thread-multi > > Operating System: Debian GNU/Linux; testing/unstable > > The file that contains the module has the following line in it: > $Id: File.pm,v 1.16 2004/04/08 02:27:25 ekkis Exp $ > > > Steps to reproduce: > > # echo $COLUMNS > 80 > > # cat > short-example-of-bad-verify.pl <<'EOF' > #! /usr/bin/perl > > use strict; > use warnings; > > use Proc::PID::File; > die "Already running!" if Proc::PID::File->running(verify => 1); > > while (1) { > sleep 20; > } > EOF > > # chmod +x short-example-of-bad-verify.pl > > # ./short-example-of-bad-verify.pl& > # ./short-example-of-bad-verify.pl& > > # pgrep short-ex > 21481 > 21482 > > # echo Notice that there are now two processes running. > Notice that there are now two processes running. > > # echo 'Maximize your terminal emulator!' > Maximize your terminal emulator! > > # echo $COLUMNS > 191 > > # ./short-example-of-bad-verify.pl > Already running! at ./short-example-of-bad-verify.pl line 7. > > The reason for this is that `ps -fp $pid' adjusts its output to the > width of the terminal resulting in no match for grep /$me/ unless > $ENV{COLUMNS} is way high. > > I had expected the second invocation of short-example-of-bad-verify.pl > to fail stating "Already running!...". > > "looking at /proc/$PID/stat for a process name" as suggested in the > POD or possibly /proc/$PID/cmdline (at least at GNU/Linux) is probably > a better solution than relying on ps.
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:36:33.289874500 -0400 @@ -128,9 +128,13 @@ if ($Config::Config{osname} =~ /linux|freebsd/i) { my $me = $self->{verify}; ($me = $0) =~ s|.*/|| if !$me || $me eq "1"; + my $old_cols = delete($ENV{'COLUMNS'}); my @ps = split m|$/|, qx/ps -fp $pid/ || die "ps utility not available: $!"; s/^\s+// for @ps; # leading spaces confuse us + if (defined($old_cols)) { + $ENV{'COLUMNS'} = $old_cols; + } no warnings; # hate that deprecated @_ thing my $n = split(/\s+/, $ps[0]);
CC: Mike Canzoneri <mikecanzoneri [...] gmail.com>
Subject: Re: [rt.cpan.org #15015] [PATCH] verify should not fail when the program was started with low $ENV{COLUMNS}
Date: Wed, 30 Sep 2009 13:54:55 -0700
To: bug-Proc-PID-File [...] rt.cpan.org
From: Erick Calder <e [...] arix.com>
I am unable to reproduce this problem in my environment so I've applied the patch as rev 2468 and verified it doesn't break anything, however, I'm not sure how to write a test case for it - I tried setting the $COLUMNS value to 40 and taking a look at the output of / ps/ but it seems fine. if either of you could do it it would be great. - e On Sep 28, 2009, at 1:39 PM, Jerry D. Hedden via RT wrote: Show quoted text
> Queue: Proc-PID-File > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=15015 > > > The attached patch fixes this problem. > > On Tue Oct 11 18:04:01 2005, guest wrote:
>> I asume the form until now has already included that my problem is >> with Proc::PID::File 1.24. >> >> Perl version: v5.8.7 built for i386-linux-thread-multi >> >> Operating System: Debian GNU/Linux; testing/unstable >> >> The file that contains the module has the following line in it: >> $Id: File.pm,v 1.16 2004/04/08 02:27:25 ekkis Exp $ >> >> >> Steps to reproduce: >> >> # echo $COLUMNS >> 80 >> >> # cat > short-example-of-bad-verify.pl <<'EOF' >> #! /usr/bin/perl >> >> use strict; >> use warnings; >> >> use Proc::PID::File; >> die "Already running!" if Proc::PID::File->running(verify => 1); >> >> while (1) { >> sleep 20; >> } >> EOF >> >> # chmod +x short-example-of-bad-verify.pl >> >> # ./short-example-of-bad-verify.pl& >> # ./short-example-of-bad-verify.pl& >> >> # pgrep short-ex >> 21481 >> 21482 >> >> # echo Notice that there are now two processes running. >> Notice that there are now two processes running. >> >> # echo 'Maximize your terminal emulator!' >> Maximize your terminal emulator! >> >> # echo $COLUMNS >> 191 >> >> # ./short-example-of-bad-verify.pl >> Already running! at ./short-example-of-bad-verify.pl line 7. >> >> The reason for this is that `ps -fp $pid' adjusts its output to the >> width of the terminal resulting in no match for grep /$me/ unless >> $ENV{COLUMNS} is way high. >> >> I had expected the second invocation of short-example-of-bad- >> verify.pl >> to fail stating "Already running!...". >> >> "looking at /proc/$PID/stat for a process name" as suggested in the >> POD or possibly /proc/$PID/cmdline (at least at GNU/Linux) is >> probably >> a better solution than relying on ps.
> > > > 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:36:33.289874500 -0400 > @@ -128,9 +128,13 @@ > if ($Config::Config{osname} =~ /linux|freebsd/i) { > my $me = $self->{verify}; > ($me = $0) =~ s|.*/|| if !$me || $me eq "1"; > + my $old_cols = delete($ENV{'COLUMNS'}); > my @ps = split m|$/|, qx/ps -fp $pid/ > || die "ps utility not available: $!"; > s/^\s+// for @ps; # leading spaces confuse us > + if (defined($old_cols)) { > + $ENV{'COLUMNS'} = $old_cols; > + } > > no warnings; # hate that deprecated @_ thing > my $n = split(/\s+/, $ps[0]);
Subject: Re: [rt.cpan.org #15015] [PATCH] verify should not fail when the program was started with low $ENV{COLUMNS}
Date: Wed, 30 Sep 2009 23:22:42 +0200
To: bug-Proc-PID-File [...] rt.cpan.org
From: Ulrik Haugen <qha [...] lysator.liu.se>
I'm not sure what procps is up to, but apparently forty columns is not quite to its taste when printing a full process listing. % COLUMNS=90 ps -fp 9836 UID PID PPID C STIME TTY TIME CMD qha 9836 1 1 Sep24 ? 05:34:08 /usr/lib/iceweasel/firefox-bin -a icewease % COLUMNS=80 ps -fp 9836 UID PID PPID C STIME TTY TIME CMD qha 9836 1 1 Sep24 ? 05:34:08 /usr/lib/iceweasel/firefox-bin - % COLUMNS=70 ps -fp 9836 UID PID PPID C STIME TTY TIME CMD qha 9836 1 1 Sep24 ? 05:34:09 /usr/lib/iceweasel/fir % COLUMNS=40 ps -fp 9836 UID PID PPID C STIME TTY TIME CMD qha 9836 1 1 Sep24 ? 05:34:09 /usr/lib/iceweasel/firefox-bin - % ps V procps version 3.2.7 To its credit (i guess) procps seems perfectly happy with limiting itself to forty columns if only asked to print pid and command: % COLUMNS=40 ps -o pid,args -p 9836 PID COMMAND 9836 /usr/lib/iceweasel/firefox-bin -a % COLUMNS=80 ps -o pid,args -p 9836 PID COMMAND 9836 /usr/lib/iceweasel/firefox-bin -a iceweasel -P default Best regards /Ulrik Haugen