summaryrefslogtreecommitdiff
path: root/mg.c
diff options
context:
space:
mode:
authorMax Maischein <corion@corion.net>2011-05-22 21:36:57 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-05-22 21:50:50 -0700
commit0e21945565eb4664d843bb819fb032cedee4d5a6 (patch)
treeb5b5ab6ecccabc65812e44ac0a5baefa3f5e5000 /mg.c
parent369fb445f856204b1f9717b96bde7cd9bb9da369 (diff)
downloadperl-0e21945565eb4664d843bb819fb032cedee4d5a6.tar.gz
Turn $$ into a magical readonly variable that always fetches getpid() instead of caching it
The intent is that by not caching $$, we eliminate one opportunity for bugs: If one embeds Perl or uses XS and calls fork(3) from C, Perls notion of $$ may go out of sync with what getpid() returns. By always fetching the value of $$ via getpid(), this bug opportunity is eliminated. The overhead of always fetching $$ should be small and is likely only used for tempfile creation, which should be dwarfed by file system accesses.
Diffstat (limited to 'mg.c')
-rw-r--r--mg.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/mg.c b/mg.c
index 85b546175b..af2c6474bc 100644
--- a/mg.c
+++ b/mg.c
@@ -1114,6 +1114,10 @@ Perl_magic_get(pTHX_ SV *sv, MAGIC *mg)
if (PL_ors_sv)
sv_copypv(sv, PL_ors_sv);
break;
+ case '$': /* $$ */
+ sv_setiv(sv, (IV)PerlProc_getpid());
+ break;
+
case '!':
{
dSAVE_ERRNO;