> Do a cvs diff -u and post the patch to the list with [PATCH] in the subject;
> CC me directly.
> I'll try and apply it over the weekend, unless someone else here applies
> it for you in the meantime.

That would be great :)
 
> Thanks for your extensive testing of proc_open/proc_close :-)

No problems. Something gives me the impression that I'm the first person
to use the functions to any great extent, but it's been fun learning and
playing with the PHP source.

The patch is somewhat more developed than what I posted before, I
commented what's actually happening (once I figured out what was
actually happening), and it checks that the process exited normally now
(it didn't before, which would have returned spurious exit codes in some
cases).

I am moderately confident that it should be fairy reliable, as opposed
to what I posted before, which was more of a one-off "this works for me,
someone please make it work for everyone".

Thanks,

KimS
? proc_close_patch
Index: ext/standard/exec.c
===================================================================
RCS file: /repository/php4/ext/standard/exec.c,v
retrieving revision 1.76
diff -u -r1.76 exec.c
--- ext/standard/exec.c 23 May 2002 10:17:07 -0000      1.76
+++ ext/standard/exec.c 13 Jun 2002 00:03:21 -0000
@@ -559,23 +559,33 @@
        GetExitCodeProcess(child, &wstatus);
        FG(pclose_ret) = wstatus;
 #else
-# if HAVE_SYS_WAIT
+#if HAVE_SYS_WAIT_H
        int wstatus;
        pid_t child, wait_pid;
        
        child = (pid_t)rsrc->ptr;
 
        do {
+               /* fetch status of child process */
                wait_pid = waitpid(child, &wstatus, 0);
-       } while (wait_pid == -1 && errno = EINTR);
+               
+               /* if wait_pid == 1 and errno == EINTR, then waitpid() is just
+                * alerting of a signal that's been caught - so keep looping
+                * until wait_pid != -1 (the child process has exited) or
+                * errno != EINTR (there was a real error, not just a caught
+                * signal)
+                */
+       } while (wait_pid == -1 && errno == EINTR);
        
-       if (wait_pid == -1)
-               FG(pclose_ret) = -1;
-       else
-               FG(pclose_ret) = wstatus;
-# else
+       /* if the child process exited normally, set pclose_ret to the exit
+        * status of the child process, otherwise set it to -1 (this might
+        * happen if there's no child process, or it didn't exit normally)
+        */
+       FG(pclose_ret) = wait_pid > 0 && WIFEXITED(wstatus) ? 
+               WEXITSTATUS(wstatus) : -1;
+#else
        FG(pclose_ret) = -1;
-# endif
+#endif
 #endif
 }
 

-- 
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to