From: Jarkko Hietaniemi <jhi@iki.fi>
Date: Wed, 2 Jul 2003 08:40:36 +0000 (+0000)
Subject: FreeBSD $0 dance.
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6a4647a3a8b62032c9f9f86043d233d69786c400;p=p5sagit%2Fp5-mst-13.2.git

FreeBSD $0 dance.

p4raw-id: //depot/perl@19925
---

diff --git a/pod/perlvar.pod b/pod/perlvar.pod
index af50613..e00ec4f 100644
--- a/pod/perlvar.pod
+++ b/pod/perlvar.pod
@@ -851,8 +851,10 @@ length of C<$0>.  In the most extreme case it may be limited to the
 space occupied by the original C<$0>.
 
 Note for BSD users: setting C<$0> does not completely remove "perl"
-from the ps(1) output.  For example, setting C<$0> to C<"foobar"> will
-result in C<"perl: foobar (perl)">.  This is an operating system feature.
+from the ps(1) output.  For example, setting C<$0> to C<"foobar"> may
+result in C<"perl: foobar (perl)"> (whether both the C<"perl: "> prefix
+and the " (perl)" suffix are shown depends on your exact BSD variant
+and version).  This is an operating system feature, Perl cannot help it.
 
 In multithreaded scripts Perl coordinates the threads so that any
 thread may modify its copy of the C<$0> and the change becomes visible
diff --git a/t/op/magic.t b/t/op/magic.t
index 1f98221..cee52cb 100755
--- a/t/op/magic.t
+++ b/t/op/magic.t
@@ -300,8 +300,11 @@ else {
             };
             my $ps = $mydollarzero->("x");
             ok(!$ps  # we allow that something goes wrong with the ps command
-	       # FreeBSD cannot get rid of the trailing " (perl)".
-               || $ps =~ /^x\b/,
+               || $ps eq 'x'
+	       # FreeBSD cannot get rid of both the leading "perl :"
+	       # and the trailing " (perl)": some FreeBSD versions
+	       # can get rid of the first one.
+	       || ($^O eq 'freebsd' && $ps =~ m/^(?:perl: )? x (?:\(perl\))?$/)
 		       'altering $0 is effective (testing with `ps`)');
 	} else {
 	    skip("\$0 check only on Linux and FreeBSD") for 0, 1;