From: Gisle Aas Date: Wed, 11 Jan 2006 09:52:18 +0000 (+0000) Subject: Make setting 'PL_origalen = 1' before perl_parse() disable X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a2722ac963c473daf784eb7bed19dab587ac5fe6;p=p5sagit%2Fp5-mst-13.2.git Make setting 'PL_origalen = 1' before perl_parse() disable argv[0] munging when $0 is assigned to. p4raw-id: //depot/perl@26779 --- diff --git a/mg.c b/mg.c index 3e3ebfd..87cea48 100644 --- a/mg.c +++ b/mg.c @@ -2540,7 +2540,7 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) /* The BSDs don't show the argv[] in ps(1) output, they * show a string from the process struct and provide * the setproctitle() routine to manipulate that. */ - { + if (PL_origalen != 1) { s = SvPV_const(sv, len); # if __FreeBSD_version > 410001 /* The leading "-" removes the "perl: " prefix, @@ -2561,7 +2561,7 @@ Perl_magic_set(pTHX_ SV *sv, MAGIC *mg) } #endif #if defined(__hpux) && defined(PSTAT_SETCMD) - { + if (PL_origalen != 1) { union pstun un; s = SvPV_const(sv, len); un.pst_command = (char *)s; diff --git a/perl.c b/perl.c index b1671d9..2958599 100644 --- a/perl.c +++ b/perl.c @@ -1439,7 +1439,10 @@ setuid perl scripts securely.\n"); PL_origargc = argc; PL_origargv = argv; - { + if (PL_origalen != 0) { + PL_origalen = 1; /* don't use old PL_origalen if perl_parse() is called again */ + } + else { /* Set PL_origalen be the sum of the contiguous argv[] * elements plus the size of the env in case that it is * contiguous with the argv[]. This is used in mg.c:Perl_magic_set() diff --git a/pod/perlembed.pod b/pod/perlembed.pod index 38211e5..0bd569f 100644 --- a/pod/perlembed.pod +++ b/pod/perlembed.pod @@ -793,6 +793,7 @@ with L whenever possible. } perl_construct(my_perl); + PL_origalen = 1; /* don't let $0 assignment update the proctitle or embedding[0] */ exitstatus = perl_parse(my_perl, NULL, 2, embedding, NULL); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; if(!exitstatus) { @@ -852,6 +853,21 @@ perl 5.7.2 you can specify C to get the new behaviour. This also enables the running of END blocks if the perl_parse fails and C will return the exit value. +=head2 $0 assignments + +When a perl script assigns a value to $0 then the perl runtime will +try to make this value show up as the program name reported by "ps" by +updating the memory pointed to by the argv passed to perl_parse() and +also calling API functions like setproctitle() where available. This +behaviour might not be appropriate when embedding perl and can be +disabled by assigning the value C<1> to the variable C +before perl_parse() is called. + +The F example above is for instance likely to segfault +when $0 is assigned to if the C assignment is +removed. This because perl will try to write to the read only memory +of the C strings. + =head2 Maintaining multiple interpreter instances Some rare applications will need to create more than one interpreter