Skip to content

Commit 6a4647a

Browse files
committed
FreeBSD $0 dance.
p4raw-id: //depot/perl@19925
1 parent e26ae24 commit 6a4647a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

pod/perlvar.pod

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,8 +851,10 @@ length of C<$0>. In the most extreme case it may be limited to the
851851
space occupied by the original C<$0>.
852852

853853
Note for BSD users: setting C<$0> does not completely remove "perl"
854-
from the ps(1) output. For example, setting C<$0> to C<"foobar"> will
855-
result in C<"perl: foobar (perl)">. This is an operating system feature.
854+
from the ps(1) output. For example, setting C<$0> to C<"foobar"> may
855+
result in C<"perl: foobar (perl)"> (whether both the C<"perl: "> prefix
856+
and the " (perl)" suffix are shown depends on your exact BSD variant
857+
and version). This is an operating system feature, Perl cannot help it.
856858

857859
In multithreaded scripts Perl coordinates the threads so that any
858860
thread may modify its copy of the C<$0> and the change becomes visible

t/op/magic.t

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,11 @@ else {
300300
};
301301
my $ps = $mydollarzero->("x");
302302
ok(!$ps # we allow that something goes wrong with the ps command
303-
# FreeBSD cannot get rid of the trailing " (perl)".
304-
|| $ps =~ /^x\b/,
303+
|| $ps eq 'x'
304+
# FreeBSD cannot get rid of both the leading "perl :"
305+
# and the trailing " (perl)": some FreeBSD versions
306+
# can get rid of the first one.
307+
|| ($^O eq 'freebsd' && $ps =~ m/^(?:perl: )? x (?:\(perl\))?$/)
305308
'altering $0 is effective (testing with `ps`)');
306309
} else {
307310
skip("\$0 check only on Linux and FreeBSD") for 0, 1;

0 commit comments

Comments
 (0)