Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Trying to open a pseudo-tty throws an exception on 5.13+ Linux kernels #21203

@csanchezdll

Description

@csanchezdll

This was already reported and fixed in #20218, but Linux kernel changes have rendered the fix there insufficient.

Note: Ubuntu seems to have included this patch in their 5.4.0-75 kernels for Focal, so this is probably happening to you even if your mainline kernel version is <5.13 (it was my case).

Steps to Reproduce

On a Linux system:

  1. Compile the following code
using System.IO.Ports;

public class Test
{
	public static void Main(string[] args)
	{
		SerialPort port;

		port = new SerialPort();
		port.PortName="/tmp/ttyA";
		port.Open();
	}
}
  1. Use socat to open a PTY
socat PTY,rawer,link=/tmp/ttyA STDIO
  1. Run the testcase

Current Behavior

An exception is thrown.

Unhandled Exception:
System.IO.IOException: Inappropriate ioctl for device
  at System.IO.Ports.SerialPortStream.ThrowIOException () [0x0000f] in <7024908a7fd94b32a39c17e950046899>:0 
  at System.IO.Ports.SerialPortStream.SetSignal (System.IO.Ports.SerialSignal signal, System.Boolean value) [0x00030] in <7024908a7fd94b32a39c17e950046899>:0 
  at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream.SetSignal(System.IO.Ports.SerialSignal,bool)
  at System.IO.Ports.SerialPortStream..ctor (System.String portName, System.Int32 baudRate, System.Int32 dataBits, System.IO.Ports.Parity parity, System.IO.Ports.StopBits stopBits, System.Boolean dtrEnable, System.Boolean rtsEnable, System.IO.Ports.Handshake handshake, System.Int32 readTimeout, System.Int32 writeTimeout, System.Int32 readBufferSize, System.Int32 writeBufferSize) [0x00051] in <7024908a7fd94b32a39c17e950046899>:0 
  at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream..ctor(string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
  at System.IO.Ports.SerialPort.Open () [0x0006f] in <7024908a7fd94b32a39c17e950046899>:0 
  at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort.Open()
  at Test.Main (System.String[] args) [0x00011] in <51bd885d7d6f450eb7e9eb1425cc99f2>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.IOException: Inappropriate ioctl for device
  at System.IO.Ports.SerialPortStream.ThrowIOException () [0x0000f] in <7024908a7fd94b32a39c17e950046899>:0 
  at System.IO.Ports.SerialPortStream.SetSignal (System.IO.Ports.SerialSignal signal, System.Boolean value) [0x00030] in <7024908a7fd94b32a39c17e950046899>:0 
  at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream.SetSignal(System.IO.Ports.SerialSignal,bool)
  at System.IO.Ports.SerialPortStream..ctor (System.String portName, System.Int32 baudRate, System.Int32 dataBits, System.IO.Ports.Parity parity, System.IO.Ports.StopBits stopBits, System.Boolean dtrEnable, System.Boolean rtsEnable, System.IO.Ports.Handshake handshake, System.Int32 readTimeout, System.Int32 writeTimeout, System.Int32 readBufferSize, System.Int32 writeBufferSize) [0x00051] in <7024908a7fd94b32a39c17e950046899>:0 
  at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPortStream..ctor(string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
  at System.IO.Ports.SerialPort.Open () [0x0006f] in <7024908a7fd94b32a39c17e950046899>:0 
  at (wrapper remoting-invoke-with-check) System.IO.Ports.SerialPort.Open()
  at Test.Main (System.String[] args) [0x00011] in <51bd885d7d6f450eb7e9eb1425cc99f2>:0 

Expected Behavior

Program ending without errors.

On which platforms did you notice this

[ ] macOS
[X ] Linux
[ ] Windows

Version Used:

Mono JIT compiler version 6.13.0 (main/1bdb6cc55c3 mié 25 ago 2021 07:42:55 UTC)
Copyright (C) Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug 
        Interpreter:   yes
        LLVM:          supported, not enabled.
        Suspend:       hybrid
        GC:            sgen (concurrent by default)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions