Coder Social home page Coder Social logo

vs-pty.net's Introduction

Pty.Net

NuGet package

Pty.Net is a cross platform, .NET library providing idiomatic bindings for forkpty().

Pty.Net supports Linux, macOS, and Windows. On versions of windows older than 1809 the winpty is used. For windows 1809+ this library ships a side-by-side copy of conhost.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

vs-pty.net's People

Contributors

javierdlg avatar markcanary avatar microsoft-github-operations[bot] avatar microsoftopensource avatar zoeyr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vs-pty.net's Issues

Tried to spawn "DIR"

After trying to spawn "dir", application exited with no exceptions.
Log shows kernel errors:

19 Nov 2023 19:35:20	kernel	AutFac[124595]: segfault at 10 ip 0000000000000010 sp 00007ffcf646edc8 error 14
19 Nov 2023 19:35:20	kernel	AutFac[124527]: segfault at 201020029 ip 00007fcde9eeb0b7 sp 00007ffcf646ef88 error 4
19 Nov 2023 19:35:20	kernel	 in AutFac[564e293c5000+7000] likely on CPU 4 (core 8, socket 0)
19 Nov 2023 19:35:20	kernel	Code: Unable to access opcode bytes at 0xffffffffffffffe6.
19 Nov 2023 19:35:20	kernel	 in memfd:doublemapper (deleted)[7fcde9eeb000+1000] likely on CPU 6 (core 12, socket 0)
19 Nov 2023 19:35:20	kernel	Code: 00 00 00 48 8b 07 48 8b 80 a8 00 00 00 ff 60 20 6c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 48 8b 07 48 8b 40 40 <ff> 60 28 05 00 00 00 00 00 48 8b 07 48 8b 40 48 ff 60 28 0d 00 00

Can't find SystemNative_GetEnviron entry point

I am trying to run a .NET 5 Pty.Net application on a Raspberry PI running Ubuntu 20.04.1 LTS and I am getting the following stack trace. Other .NET 5 applications work fine on this device. The application works fine running it on Windows.

Waiting on 918951
Unhandled exception. One or more errors occurred. (Unable to find an entry point named 'SystemNative_GetEnviron' in shared library 'System.Native'.)
System.AggregateException: One or more errors occurred. (Unable to find an entry point named 'SystemNative_GetEnviron' in shared library 'System.Native'.)
 ---> System.EntryPointNotFoundException: Unable to find an entry point named 'SystemNative_GetEnviron' in shared library 'System.Native'.
   at Pty.Net.Linux.NativeMethods.GetEnviron()
   at Pty.Net.Linux.NativeMethods.execvpe(String file, String[] args, IDictionary`2 environment)
   at Pty.Net.Linux.PtyProvider.StartTerminalAsync(PtyOptions options, TraceSource trace, CancellationToken cancellationToken)
   at Pty.Net.PtyProvider.SpawnAsync(PtyOptions options, CancellationToken cancellationToken)
   at TestTerminal.Program.StartTerminal() in C:\Users\Mark\Downloads\TestTerminal\TestTerminal\Program.cs:line 54
   --- End of inner exception stack trace ---

How to find conpty

When i try to test the assembly, I clone the code, and compiled with .NET48, and got the error.

System.DllNotFoundException: cannot load DLL“os64\conpty.dll”.

mono support

System.Native is not available in .NET and mono, how to make it usable for mono?

Unhandled Exception:
System.IO.IOException: Invalid handle to path "[Unknown]"
  at System.IO.FileStream.Init (Microsoft.Win32.SafeHandles.SafeFileHandle safeHandle, System.IO.FileAccess access, System.Boolean ownsHandle, System.Int32 bufferSize, System.Boolean isAsync, System.Boolean isConsoleWrapper) [0x0007f] in <076b83d5ce5949de82a325f5607fed6f>:0 
  at System.IO.FileStream..ctor (Microsoft.Win32.SafeHandles.SafeFileHandle handle, System.IO.FileAccess access, System.Int32 bufferSize, System.Boolean isAsync) [0x00011] in <076b83d5ce5949de82a325f5607fed6f>:0 
  at Pty.Net.Unix.PtyStream..ctor (System.Int32 fd, System.IO.FileAccess fileAccess) [0x0000d] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at (wrapper remoting-invoke-with-check) Pty.Net.Unix.PtyStream..ctor(int,System.IO.FileAccess)
  at Pty.Net.Unix.PtyConnection..ctor (System.Int32 controller, System.Int32 pid) [0x00014] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.Linux.PtyConnection..ctor (System.Int32 controller, System.Int32 pid) [0x00000] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.Linux.PtyProvider.StartTerminalAsync (Pty.Net.PtyOptions options, System.Diagnostics.TraceSource trace, System.Threading.CancellationToken cancellationToken) [0x00142] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.PtyProvider.SpawnAsync (Pty.Net.PtyOptions options, System.Threading.CancellationToken cancellationToken) [0x00091] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.PtyProvider.Spawn (Pty.Net.PtyOptions options, System.Int32 timeout) [0x0000d] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.PtyProvider.Terminal (System.String name, System.Int32 cols, System.Int32 rows) [0x00060] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at ConsoleApp1.Program.Main (System.String[] args) [0x00001] in <2f412f014020491a96a31603e2a7fcf1>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.IO.IOException: Invalid handle to path "[Unknown]"
  at System.IO.FileStream.Init (Microsoft.Win32.SafeHandles.SafeFileHandle safeHandle, System.IO.FileAccess access, System.Boolean ownsHandle, System.Int32 bufferSize, System.Boolean isAsync, System.Boolean isConsoleWrapper) [0x0007f] in <076b83d5ce5949de82a325f5607fed6f>:0 
  at System.IO.FileStream..ctor (Microsoft.Win32.SafeHandles.SafeFileHandle handle, System.IO.FileAccess access, System.Int32 bufferSize, System.Boolean isAsync) [0x00011] in <076b83d5ce5949de82a325f5607fed6f>:0 
  at Pty.Net.Unix.PtyStream..ctor (System.Int32 fd, System.IO.FileAccess fileAccess) [0x0000d] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at (wrapper remoting-invoke-with-check) Pty.Net.Unix.PtyStream..ctor(int,System.IO.FileAccess)
  at Pty.Net.Unix.PtyConnection..ctor (System.Int32 controller, System.Int32 pid) [0x00014] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.Linux.PtyConnection..ctor (System.Int32 controller, System.Int32 pid) [0x00000] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.Linux.PtyProvider.StartTerminalAsync (Pty.Net.PtyOptions options, System.Diagnostics.TraceSource trace, System.Threading.CancellationToken cancellationToken) [0x00142] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.PtyProvider.SpawnAsync (Pty.Net.PtyOptions options, System.Threading.CancellationToken cancellationToken) [0x00091] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.PtyProvider.Spawn (Pty.Net.PtyOptions options, System.Int32 timeout) [0x0000d] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at Pty.Net.PtyProvider.Terminal (System.String name, System.Int32 cols, System.Int32 rows) [0x00060] in <f5d82a59cf7f4762b0f4ab5b9f493217>:0 
  at ConsoleApp1.Program.Main (System.String[] args) [0x00001] in <2f412f014020491a96a31603e2a7fcf1>:0 

forkpty() / execvpe() causing Segmentation fault under Ubuntu Linux 22.04.1 LTS (.Net 7.0.3)

Entry call:

using System.Collections.Generic;
using System;
using System.Threading.Tasks;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using Pty.Net;

namespace TestApp
{
    internal class Application
    {
        static void Main(string[] args)
        {
            var app = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? Path.Combine(Environment.SystemDirectory, "cmd.exe") : "sh";

            var options = new PtyOptions
            {
                Name = "Custom terminal",
                Cols = 80,
                Rows = 25,
                Cwd = Environment.CurrentDirectory,
                App = app,
                Environment = new Dictionary<string, string>()
                              {
                                { "FOO", "bar" },
                                { "Bazz", string.Empty },
                              },
            };

            PtyProvider.SpawnAsync(options, new CancellationToken());

            Task.Delay(-1).Wait();
        }
    }
}

Segmentation fault happened calling forkpty() / execvpe()

Pty.Net\Linux\PtyProvider.cs

int controller = 0;
int pid = forkpty(ref controller, null, ref term, ref winSize);

if (pid == -1)
{
    throw new InvalidOperationException($"forkpty(4) failed with error {Marshal.GetLastWin32Error()}");
}

if (pid == 0)
{
    // We are in a forked process! See http://man7.org/linux/man-pages/man2/fork.2.html for details.
    // Only our thread is running. We inherited open file descriptors and get a copy of the parent process memory.
    Environment.CurrentDirectory = options.Cwd;
    execvpe(options.App, terminalArgs, options.Environment);

    // Unreachable code after execvpe()
}

**

I have tested for .Net 6, it works.

Wonding whether it related to the large VSZ (Virtual Memory Size) on .Net 7 / .Net 8 which lead to forking
Segmentation fault issue.

**

NetSDK: .Net 7.0.3
Application Type: Console
Distributor ID: Ubuntu
Description: Ubuntu 22.04.1 LTS x64
Release: 22.04
Codename: jammy

NuGet Package?

Is vs-pty.net published as a NuGet package or a compiled library?

What is the actual state of the project?

The package appears unlisted in NuGet, there's no documentation or examples, the version that is in NuGet is from 2018, and there don't appear to be any substantive code changes for over a year.

Are there any major reasons not to use this project? Or is it essentially deprecated?

System.IO.IOException: Invalid handle to path "[Unknown]" on Mono

The error still exits in Mono:

import clr, System
from Pty.Net import *
class Pty:
    def __init__(self, name, cols=180, rows=500):
        self.name = name
        self.started = ph.dd.now()
        self.host = "127.0.0.1"
        self.cols = cols
        self.rows = rows
        app = "/bin/bash"
        options = PtyOptions()
        options.Name = name
        options.Cols = 180
        options.Rows = 500
        options.Cwd = "/root"
        options.App = app
        self.pty = PtyProvider.SpawnAsync(options, System.Threading.CancellationToken()).GetAwaiter().GetResult()
pty = Pty("lo")
System.IO.IOException: Invalid handle to path "[Unknown]"
  at System.IO.FileStream.Init (Microsoft.Win32.SafeHandles.SafeFileHandle safeHandle, System.IO.FileAccess access, System.Boolean ownsHandle, System.Int32 bufferSize, System.Boolean isAsync, System.Boolean isConsoleWrapper) [0x0006a] in <a5426229307d4283803b6b7e2cdc86e0>:0 
  at System.IO.FileStream..ctor (Microsoft.Win32.SafeHandles.SafeFileHandle handle, System.IO.FileAccess access, System.Int32 bufferSize, System.Boolean isAsync) [0x00011] in <a5426229307d4283803b6b7e2cdc86e0>:0 
  at Pty.Net.Unix.PtyStream..ctor (System.Int32 fd, System.IO.FileAccess fileAccess) [0x0000d] in <c5151a3d755045f2a06d1d18f46d910c>:0 
  at (wrapper remoting-invoke-with-check) Pty.Net.Unix.PtyStream..ctor(int,System.IO.FileAccess)
  at Pty.Net.Unix.PtyConnection..ctor (System.Int32 controller, System.Int32 pid) [0x00012] in <c5151a3d755045f2a06d1d18f46d910c>:0 
  at Pty.Net.Linux.PtyConnection..ctor (System.Int32 controller, System.Int32 pid) [0x00000] in <c5151a3d755045f2a06d1d18f46d910c>:0 
  at Pty.Net.Linux.PtyProvider.StartTerminalAsync (Pty.Net.PtyOptions options, System.Diagnostics.TraceSource trace, System.Threading.CancellationToken cancellationToken) [0x0011f] in <c5151a3d755045f2a06d1d18f46d910c>:0 
  at Pty.Net.PtyProvider.SpawnAsync (Pty.Net.PtyOptions options, System.Threading.CancellationToken cancellationToken) [0x0007b] in <c5151a3d755045f2a06d1d18f46d910c>:0 
  at (wrapper delegate-invoke) 

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.