[io-layer] Fix process_wait return value for current process
authorLudovic Henry <ludovic@xamarin.com>
Mon, 22 Feb 2016 11:15:11 +0000 (11:15 +0000)
committerLudovic Henry <ludovic@xamarin.com>
Mon, 22 Feb 2016 11:22:46 +0000 (11:22 +0000)
When waiting on the current process, we would return WAIT_FAILED, as waitpid would return -1, with errno set to ECHILD.
But the semantic of WaitForSingleObjectEx and WaitForMultipleObjectsEx when waiting on current process is to return WAIT_TIMEOUT. This is then a special case that we need to add to this code.

mono/io-layer/processes.c

index 385945f4301cbf99ef96da735e74c01b1d022c54..d54f84bd3242abb26c69473631f355fb4d1f5512 100644 (file)
@@ -2757,6 +2757,11 @@ process_wait (gpointer handle, guint32 timeout, gboolean alertable)
        if (!mp) {
                pid_t res;
 
+               if (pid == mono_process_current_pid ()) {
+                       MONO_TRACE (G_LOG_LEVEL_DEBUG, MONO_TRACE_IO_LAYER, "%s (%p, %u): waiting on current process", __func__, handle, timeout);
+                       return WAIT_TIMEOUT;
+               }
+
                /* This path is used when calling Process.HasExited, so
                 * it is only used to poll the state of the process, not
                 * to actually wait on it to exit */