[System] Make process pipe creation exception more verbose
authorLudovic Henry <ludovic@xamarin.com>
Tue, 6 Oct 2015 13:19:33 +0000 (14:19 +0100)
committerLudovic Henry <ludovic@xamarin.com>
Tue, 6 Oct 2015 13:21:43 +0000 (14:21 +0100)
mcs/class/System/System.Diagnostics/Process.cs
mcs/class/corlib/System.IO/MonoIO.cs
mono/metadata/file-io.c
mono/metadata/file-io.h
mono/metadata/icall-def.h

index a3147ffc72781bd4149b53ee4dbc5a7890e4fd3d..44fc79725bce06ee772befb4648c0b76b7dc39ca 100644 (file)
@@ -983,6 +983,8 @@ namespace System.Diagnostics {
                //
                static void CreatePipe (out IntPtr read, out IntPtr write, bool writeDirection)
                {
+                       MonoIOError error;
+
                        //
                        // Creates read/write pipe from parent -> child perspective
                        // a child process uses same descriptors after fork. That's
@@ -1003,25 +1005,23 @@ namespace System.Diagnostics {
                        //
                        // It can still be tricky for predefined descriptiors http://unixwiz.net/techtips/remap-pipe-fds.html
                        //
-                       var ret = MonoIO.CreatePipe (out read, out write);
-                       if (!ret)
-                               throw new IOException ("Error creating process pipe");
+                       if (!MonoIO.CreatePipe (out read, out write, out error))
+                               throw MonoIO.GetException (error);
 
                        if (IsWindows) {
                                const int DUPLICATE_SAME_ACCESS = 0x00000002;
                                var tmp = writeDirection ? write : read;
 
-                               ret = MonoIO.DuplicateHandle (Process.GetCurrentProcess ().Handle, tmp,
-                                       Process.GetCurrentProcess ().Handle, out tmp, 0, 0, DUPLICATE_SAME_ACCESS);
-                               if (!ret)
-                                       return;
+                               if (!MonoIO.DuplicateHandle (Process.GetCurrentProcess ().Handle, tmp, Process.GetCurrentProcess ().Handle, out tmp, 0, 0, DUPLICATE_SAME_ACCESS, out error))
+                                       throw MonoIO.GetException (error);
 
-                               MonoIOError error;
                                if (writeDirection) {
-                                       MonoIO.Close (write, out error);
+                                       if (!MonoIO.Close (write, out error))
+                                               throw MonoIO.GetException (error);
                                        write = tmp;
                                } else {
-                                       MonoIO.Close (read, out error);
+                                       if (!MonoIO.Close (read, out error))
+                                               throw MonoIO.GetException (error);
                                        read = tmp;
                                }
                        }
index 9d816f40a5952a5e7edcb570a187b34eec2d5427..a15c475bbaa88aab7ec9854f900dd4bf16215afa 100644 (file)
@@ -572,11 +572,11 @@ namespace System.IO
                // pipe handles
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
-               public extern static bool CreatePipe (out IntPtr read_handle, out IntPtr write_handle);
+               public extern static bool CreatePipe (out IntPtr read_handle, out IntPtr write_handle, out MonoIOError error);
 
                [MethodImplAttribute (MethodImplOptions.InternalCall)]
                public extern static bool DuplicateHandle (IntPtr source_process_handle, IntPtr source_handle,
-                       IntPtr target_process_handle, out IntPtr target_handle, int access, int inherit, int options);
+                       IntPtr target_process_handle, out IntPtr target_handle, int access, int inherit, int options, out MonoIOError error);
 
                // path characters
 
index fec434715b57dd6b963524948abf281552d5fed5..b193e0a54945d373379c6dc1c990ea4855eaf8b6 100644 (file)
@@ -1055,8 +1055,7 @@ ves_icall_System_IO_MonoIO_get_ConsoleError ()
 }
 
 MonoBoolean
-ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle,
-                                      HANDLE *write_handle)
+ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle, HANDLE *write_handle, gint32 *error)
 {
        SECURITY_ATTRIBUTES attr;
        gboolean ret;
@@ -1070,6 +1069,7 @@ ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle,
        MONO_FINISH_BLOCKING;
 
        if(ret==FALSE) {
+               *error = GetLastError ();
                /* FIXME: throw an exception? */
                return(FALSE);
        }
@@ -1077,9 +1077,9 @@ ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle,
        return(TRUE);
 }
 
-MonoBoolean ves_icall_System_IO_MonoIO_DuplicateHandle (HANDLE source_process_handle, 
-                                               HANDLE source_handle, HANDLE target_process_handle, HANDLE *target_handle, 
-                                               gint32 access, gint32 inherit, gint32 options)
+MonoBoolean
+ves_icall_System_IO_MonoIO_DuplicateHandle (HANDLE source_process_handle, HANDLE source_handle,
+               HANDLE target_process_handle, HANDLE *target_handle, gint32 access, gint32 inherit, gint32 options, gint32 *error)
 {
        /* This is only used on Windows */
        gboolean ret;
@@ -1089,6 +1089,7 @@ MonoBoolean ves_icall_System_IO_MonoIO_DuplicateHandle (HANDLE source_process_ha
        MONO_FINISH_BLOCKING;
 
        if(ret==FALSE) {
+               *error = GetLastError ();
                /* FIXME: throw an exception? */
                return(FALSE);
        }
index 564bca32711733eee1cd25bd7cde804a40d40740..271bc58af7785a76521b9307e35a89ed24ecf10b 100644 (file)
@@ -216,12 +216,11 @@ extern HANDLE
 ves_icall_System_IO_MonoIO_get_ConsoleError (void);
 
 extern MonoBoolean
-ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle,
-                                      HANDLE *write_handle);
+ves_icall_System_IO_MonoIO_CreatePipe (HANDLE *read_handle, HANDLE *write_handle, gint32 *error);
 
-extern MonoBoolean ves_icall_System_IO_MonoIO_DuplicateHandle (HANDLE source_process_handle, 
-                                               HANDLE source_handle, HANDLE target_process_handle, HANDLE *target_handle, 
-                                               gint32 access, gint32 inherit, gint32 options);
+extern MonoBoolean
+ves_icall_System_IO_MonoIO_DuplicateHandle (HANDLE source_process_handle, HANDLE source_handle,
+               HANDLE target_process_handle, HANDLE *target_handle, gint32 access, gint32 inherit, gint32 options, gint32 *error);
 
 extern gunichar2 
 ves_icall_System_IO_MonoIO_get_VolumeSeparatorChar (void);
index faca20862bf7b847bef7019d03b3e5fd8d8aa554..20ba63609db3c1692ba45d05a407152b0fe69aa4 100644 (file)
@@ -325,7 +325,7 @@ ICALL(MONOIO_1, "Close(intptr,System.IO.MonoIOError&)", ves_icall_System_IO_Mono
 #ifndef PLATFORM_RO_FS
 ICALL(MONOIO_2, "CopyFile(string,string,bool,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CopyFile)
 ICALL(MONOIO_3, "CreateDirectory(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_CreateDirectory)
-ICALL(MONOIO_4, "CreatePipe(intptr&,intptr&)", ves_icall_System_IO_MonoIO_CreatePipe)
+ICALL(MONOIO_4, "CreatePipe", ves_icall_System_IO_MonoIO_CreatePipe)
 ICALL(MONOIO_5, "DeleteFile(string,System.IO.MonoIOError&)", ves_icall_System_IO_MonoIO_DeleteFile)
 #endif /* !PLATFORM_RO_FS */
 ICALL(MONOIO_34, "DuplicateHandle", ves_icall_System_IO_MonoIO_DuplicateHandle)