develooper Front page | perl.perl5.porters | Postings from April 2000

PATCH: fork weirdness under Win32

Thread Next
From:
Clinton A. Pierce
Date:
April 21, 2000 12:17
Subject:
PATCH: fork weirdness under Win32
Message ID:
200004211916.PAA28147@budman.backroom

This is an attempted patch to fix the silly fork() error message under 
Win32.  fork() will now returns a pid (one of those pseudo-pids), 0 or 
undef depending on what happens like it does under Unix.

I went ahead and wrapped the pp_sys.c code in an #ifndef so it 
matches the corresponding code in perlhost.h.  Everything should be in 
sync.

*** perlhost.orig.h	Fri Apr 21 10:56:00 2000
--- perlhost.h	Fri Apr 21 10:56:46 2000
***************
*** 1770,1777 ****
  			  (LPVOID)new_perl, 0, &id);
  #    endif
      PERL_SET_THX(aTHXo);	/* XXX perl_clone*() set TLS */
!     if (!handle)
! 	Perl_croak(aTHX_ "panic: pseudo fork() failed");
      w32_pseudo_child_handles[w32_num_pseudo_children] = handle;
      w32_pseudo_child_pids[w32_num_pseudo_children] = id;
      ++w32_num_pseudo_children;
--- 1770,1777 ----
  			  (LPVOID)new_perl, 0, &id);
  #    endif
      PERL_SET_THX(aTHXo);	/* XXX perl_clone*() set TLS */
!     if (!handle) 
! 	return(1);
      w32_pseudo_child_handles[w32_num_pseudo_children] = handle;
      w32_pseudo_child_pids[w32_num_pseudo_children] = id;
      ++w32_num_pseudo_children;

--- pp_sys.orig.c	Fri Apr 21 10:54:33 2000
+++ pp_sys.c	Fri Apr 21 15:01:13 2000
@@ -3680,6 +3680,12 @@
     EXTEND(SP, 1);
     PERL_FLUSHALL_FOR_CHILD;
     childpid = PerlProc_fork();
+#    ifndef PERL_SYNC_FORK
+    if (childpid == 1) {
+	errno=EAGAIN;
+	RETSETUNDEF;
+    }
+#    endif
     PUSHi(childpid);
     RETURN;
 #  else

I see what you mean that potential negative PIDS from Win95 might cause problems.
Can you accept this patch as it stands, and I promise to work on something more
comprehensive?  

I've got to learn how the PerlProc_fork() call relates to the PerlProcFork 
definiton in perlhost.h and how difficult it would be to change the return type 
of that to something more flexible than an int.  I'm new at hacking Perl and
want to make sure I don't do more damage than good just to get a bug fixed.

Thank you.


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About