Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using external C programs from SSH #48

Open
nyh opened this issue Apr 13, 2014 · 2 comments
Open

Using external C programs from SSH #48

nyh opened this issue Apr 13, 2014 · 2 comments

Comments

@nyh
Copy link
Contributor

nyh commented Apr 13, 2014

Currently, when running an external C program ("run ...", or even "ifconfig") via ssh, the output goes to the console instead of ssh (the input too, of course). This needs to be fixed. The "ifconfig" problem can be fixed by rewriting it in Java (probably a good idea anyway), but the general problem of running arbitrary C code needs to be fixed.

Normal C code written for Linux will use file descriptor 1 (stdout) and 0 (stdin) for their output and input. In OSv, this is currently always the serial console and/or the VGA, even if you log in through ssh, which is not very useful.

What we need to do is this: Our "run" command (used to run netperf) needs to open two pipes [1] and replace file descriptors 0, 1, 2, with halves of these two pipes [2]. Now netperf will not write or read from the serial console or VGA, but rather write and read to these pipes. Netperf will be run in a separate thread, and the original thread doing the "run" will just read from the pipe and use crash's Java "write" to output it (so it will go to the ssh layer as appropriate), and similarly, will read input with Java (coming from ssh) and write it to the other pipe going into netperf.

I would hope that Crsh already has some command to "run" external commands on Linux, which already should be doing something similar to what I described above (opening pipes, etc.), otherwise even on Linux, Crsh would only be useful for running builtin commands implemented in Java. But even if it doesn't, what I described above, using pipes, is pretty straightforward to implement (I can elaborate if something isn't clear).

[1] Linux has the notion of a "pty" (pseudo-terminals) which improves on this and supports stty, line discipline, etc, but we don't support ptys yet, so can start with ordinary pipes, and this will be good enough in most cases. I can add pty support later if there's interest - this mostly means moving some of the code in console.cc to a separate pty layer.

[2] Initially, we can replace fd 0, 1, 2 with the pipe-ends using a simple close() and dup(). This will work but effect the entire OSv, so one will not be able to use two ssh sessions in parallel. If we need to support parallel ssh being able to run external commands, we can do what I suggested in issue #90 in osv.gt, which is a simple per-thread file descriptor feature: File descriptors 0, 1, 2 to behave differently on different threads (all other file descriptors will be shared, as usual on a process-less system).

@tzach
Copy link
Member

tzach commented Apr 13, 2014

IMHO its better to invest on a run API rather than the CRaSH CLI.
Output of the program should be pushed into the log
See #46

@dorlaor
Copy link

dorlaor commented Apr 13, 2014

On Sun, Apr 13, 2014 at 12:38 PM, Tzach Livyatan
[email protected]:

IMHO its better to invest on a run API rather than the CRaSH CLI.
Output of the program should be pushed into the log

The best way is to combine the suggestion - send the in/out streams through
the api to be consumed by
a local CLI running on the client machine. It needs Nadav's changes and
later when we have the api we can move
to it too

Reply to this email directly or view it on GitHubhttps://github.com//issues/48#issuecomment-40303510
.

@tzach tzach added CLI labels Apr 13, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants