diff options
author | Gurusamy Sarathy <gsar@cpan.org> | 2001-07-20 18:38:48 +0000 |
---|---|---|
committer | Gurusamy Sarathy <gsar@cpan.org> | 2001-07-20 18:38:48 +0000 |
commit | 52e18b1f277416a33dff2c066a83fdab0520a2d7 (patch) | |
tree | 0d35a4f042171ce3c05667667ca19d69d060a292 /pp_sys.c | |
parent | 9046a8ae3aad1f7eda5affd38301ac2313201634 (diff) | |
download | perl-52e18b1f277416a33dff2c066a83fdab0520a2d7.tar.gz |
Make perl fork()-safe (in a slightly limited way) even on
platforms that don't have pthread_atfork() (extension of
the fix in change#11151).
Note that this will not help extensions that call fork()
directly in C, or that link to libraries that call fork()
directly. Such cases must be fixed to either call
PerlProc_fork(), or call atfork_lock() in parent before the
calling the function that forks and call atfork_unlock()
in both parent and child immediately after the fork().
(There are no worries if C code calls exec() in the child
immediately after a fork(). Only cases where the child
calls perl's API functions (including New()) after the
fork() are problematic.)
This change also eliminates the use of vfork() from perl,
since all such uses were violating the severe restrictions
on modifying the state of the process between the vfork()
and the exec().
This is a modified version of patches suggested by Abhijit
Menon-Sen and Richard Soderberg.
p4raw-link: @11151 on //depot/perl: 50dd6e574ff39b609595ddb16b2fe9f625a26f8c
p4raw-id: //depot/perl@11423
Diffstat (limited to 'pp_sys.c')
-rw-r--r-- | pp_sys.c | 15 |
1 files changed, 3 insertions, 12 deletions
@@ -104,11 +104,6 @@ extern int h_errno; # endif #endif -/* Put this after #includes because fork and vfork prototypes may conflict. */ -#ifndef HAS_VFORK -# define vfork fork -#endif - #ifdef HAS_CHSIZE # ifdef my_chsize /* Probably #defined to Perl_my_chsize in embed.h */ # undef my_chsize @@ -3874,13 +3869,9 @@ PP(pp_fork) Pid_t childpid; GV *tmpgv; -# if defined(USE_ITHREADS) && !defined(HAS_PTHREAD_ATFORK) - Perl_croak(aTHX_ "No pthread_atfork() -- fork() too unsafe"); -# endif - EXTEND(SP, 1); PERL_FLUSHALL_FOR_CHILD; - childpid = fork(); + childpid = PerlProc_fork(); if (childpid < 0) RETSETUNDEF; if (!childpid) { @@ -3991,7 +3982,7 @@ PP(pp_system) if (PerlProc_pipe(pp) >= 0) did_pipes = 1; - while ((childpid = vfork()) == -1) { + while ((childpid = PerlProc_fork()) == -1) { if (errno != EAGAIN) { value = -1; SP = ORIGMARK; @@ -4019,7 +4010,7 @@ PP(pp_system) (void)rsignal_restore(SIGQUIT, &qhand); #endif STATUS_NATIVE_SET(result == -1 ? -1 : status); - do_execfree(); /* free any memory child malloced on vfork */ + do_execfree(); /* free any memory child malloced on fork */ SP = ORIGMARK; if (did_pipes) { int errkid; |