[Mono-bugs] [Bug 80770][Nor] New - Console fails to initialize when any std file descriptor is closed
bugzilla-daemon at bugzilla.ximian.com
bugzilla-daemon at bugzilla.ximian.com
Fri Feb 9 08:05:54 EST 2007
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by kornelpal at gmail.com.
http://bugzilla.ximian.com/show_bug.cgi?id=80770
--- shadow/80770 2007-02-09 08:05:54.000000000 -0500
+++ shadow/80770.tmp.29422 2007-02-09 08:05:54.000000000 -0500
@@ -0,0 +1,84 @@
+Bug#: 80770
+Product: Mono: Class Libraries
+Version: 1.2
+OS: unknown
+OS Details: All non-Windows
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: CORLIB
+AssignedTo: mono-bugs at ximian.com
+ReportedBy: kornelpal at gmail.com
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: Console fails to initialize when any std file descriptor is closed
+
+Test case:
+using System;
+using Mono.Unix.Native;
+
+class NoConsoleTest
+{
+ static void Main (string [] args)
+ {
+ Syscall.close (0); // stdin
+ Syscall.close (1); // stdout
+ // keep stderr to be able to print stack trace
+
+
+ System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor
+ (typeof (Console).TypeHandle);
+ }
+}
+
+Actual results:
+Unhandled Exception: System.TypeInitializationException: An exception was
+thrown by the type initializer for System.Console --->
+System.ArgumentException: handle
+Parameter name: Invalid.
+ at System.IO.FileStream..ctor (IntPtr handle, FileAccess access,
+Boolean ownsHandle, Int32 bufferSize, Boolean isAsync, Boolean
+noBuffering) [0x00108] in /mono-
+src/mcs/class/corlib/System.IO/FileStream.cs:106
+ at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor
+(intptr,System.IO.FileAccess,bool,int,bool,bool)
+ at System.Console.OpenStandardOutput (Int32 bufferSize) [0x00000]
+in /mono-src/mcs/class/corlib/System/Console.cs:208
+ at System.Console..cctor () [0x00134] in /mono-
+src/mcs/class/corlib/System/Console.cs:119 --- End of inner exception
+stack trace ---
+
+ at <0x00000> <unknown method>
+ at (wrapper managed-to-native)
+System.Runtime.CompilerServices.RuntimeHelpers:RunClassConstructor
+(intptr)
+ at System.Runtime.CompilerServices.RuntimeHelpers.RunClassConstructor
+(RuntimeTypeHandle type) [0x00000] in /mono-
+src/mcs/class/corlib/System.Runtime.CompilerServices/RuntimeHelpers.cs:94
+ at NoConsoleTest.Main (System.String[] args) [0x00000]
+
+Expected results:
+No error.
+
+Cause:
+io-layer returns INVALID_HANDLE_VALUE in GetStdHandle when the requested
+std handle is not available. On the other hand Windows returns NULL for
+the same error.
+
+Mono FileStream throws IOException for NULL and ArgumentException for
+INVALID_HANDLE_VALUE. .NET Framework however throws ArgumentException for
+both cases.
+
+Mono Console only checks for IOException.
+
+Solution:
+I think that io-layer, FileStream and Console should be modified as well
+to match Windows and .NET Framework behavior (NULL instead of
+INVALID_HANDLE_VALUE, ArgumentException for NULL and INVALID_HANDLE_VALUE
+as well, null-stream for invalid and unusable console handles).
+
+In addition I think it's better to use Stream.Null instead of a new
+NullStream to save resources.
More information about the mono-bugs
mailing list