-
Notifications
You must be signed in to change notification settings - Fork 714
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
Added C++ wrapper script. #96
base: master
Are you sure you want to change the base?
Conversation
This has a few build errors on my Linux system. I'm working on fixes. |
I have a few fixes here. I also rebased out the erroneous binary file add. It still fails to build because |
Here are pure implementations of fgetln() and getline(). |
I have also tested it (with fgetln replacements of course) an confirm that this C++ version of the wrapper works correctly under cygwin (even key mappings are OK in Midnight Commander, wow!), so C's cygwin PTYs work without bugs (not the same as Perl's PTYs which seems to be quite buggy). So it may be freely merged into the mainstream (possibly with some corrections, because I suppose perl's wrapper is ahead by functionality). |
The Perl script seems to have crystallized enough that I think we don't lose anything by moving to C++. Peter, this looks really good. One thing I would like is to execute the subsidiary SSH "properly" with forkpty() (similarly to how mosh-server works) and then have the wrapper proxy all the user's keystrokes to SSH and then handle displaying the SSH output itself. Right now ssh is reading directly from /dev/tty and printing the password prompt to /dev/tty (which goes straight to the user's terminal, bypassing the Perl script), and then the later output to stdout (which the Perl script parses line-by-line). We can fix issue #52 by having all keystrokes go through the wrapper and all output be parsed by the wrapper before display. This does make the logic a little more complicated because we want to display the line to the user on a byte-by-byte basis unless it seems to be starting with \nMOSH IP... |
There are a few more issues we need to address before this is merged.
|
I have pushed an updated version that addresses the boost, formatting, and --ssh issues. For compatibility with 86113b5 I am invoking sh -c with the fully-composed exec string. According to perl.org/functions/exec, this behavior is system-dependent. |
Possibly you could add fgetln() emulation (e.g. from the code at http://codepad.org/swe7NRct I've copied from its original sources) and create a new (final) pull request? I suppose it could speed up the process. |
@DmitryKoterov, it might help if you made clear what the provenance and license of that code is. |
This code is from http://www.gnu-darwin.org/www001/ports-1.5a-CURRENT/ftp/bsdftpd-ssl/work/bsdftpd-ssl-1.1.0/contrib/libbsdport/libc/stdio/fgetln.c and http://ar.runcode.us/q/are-there-alternate-implementations-of-gnu-getline-interface - I don't know what licences are used (suppose the same as libc). The pieces are so short that they could be rewritten from scratch. :-) |
My cxx-wrapper branch now avoids fgetln, using getline instead. Builds on OS X and whatever flavor of Debian is running on linerva.mit.edu. |
People say that getline() is not supported in Mac OS X Snow Leopard: http://stackoverflow.com/questions/1117108/compiling-c-code-using-gnu-c-getline-on-mac-osx Why don't you get rid of it totally? You may use fgets() with a fixed length buffer - fgets() is supported by any platform. In such case you should also replace
by
And - after that - could you please update this pull request? |
The I wonder if this should be part of the I think the most important thing with this code is the correctness of the string and buffer manipulation, which is pretty hard to verify. I did notice a few self-contained things though.
ioctl( 0, TIOCGWINSZ, &ws ); You don't check for an error. If static const char *const MOSH_VERSION = "1.2"; Autoconf already defines inline string shell_quote_string( string x ) ...
inline string shell_quote( SequenceT &sequence ) ...
void predict_check( string predict, bool env_set ) ... The void die( const char *format, ... ) ... I think this function would be simpler as a variadic macro. static char **argv; It looks like this global is only used for signal( SIGHUP, SIG_IGN ); The Linux
But later on the manpage suggests it's portable for Instead of string explanation;
if ( env_set ) {
explanation = " (MOSH_PREDICTION_DISPLAY in environment)";
}
fprintf( stderr, "%s: Unknown mode \"%s\"%s.\n", argv[0], predict.c_str(), explanation.c_str() ); how about fprintf( stderr, "%s: Unknown mode \"%s\"%s.\n", argv[0], predict.c_str(),
env_set ? " (MOSH_PREDICTION_DISPLAY in environment)" : "" ); Did we decide anything about using This file has a 125 character line, which I think is too long. I know Mosh has some longer lines but I'd like to keep them below 100 where possible. |
Errors from read and ioctl trapped. Replaced MOSH_VERSION with PACKAGE_VERSION. Used const. Replaced argv global with argv0. Made other cleanups including line wrapping. I don't trust myself to write a portable variadic macro. You can't open an iostream from a file descriptor or a FILE* in a portable way, so I don't see an obvious alternative to getline. |
Why don't you use fgets() with a static buffer? I've written above that it may be used safely: #96 (comment) |
I needed to fix patch-3, See piannucci#1 which merges patch-3 into master. Tested ok on linux and cygwin, the cygwin ssh prompt issue was tested ok. |
I've uploaded now an experimental cygwin package 1.2.2-2 with this branch. http://cygwin.com/ml/cygwin-announce/2012-07/msg00021.html I've also added this commit rurban@f53009c
|
Following the approach used in mosh-server.
The newest version doesn't parse the
It also leaves the |
This isn't going to be picked up? I'd like to help with this but it hasn't been touched in nearly a year. |
are there any technical difficulties holding this back, or is just more testing? |
No description provided.