mosh-server: Allow startup without PTY
This commit is contained in:
+25
-18
@@ -334,9 +334,13 @@ int run_server( const char *desired_ip, const char *desired_port,
|
|||||||
/* get initial window size */
|
/* get initial window size */
|
||||||
struct winsize window_size;
|
struct winsize window_size;
|
||||||
if ( ioctl( STDIN_FILENO, TIOCGWINSZ, &window_size ) < 0 ) {
|
if ( ioctl( STDIN_FILENO, TIOCGWINSZ, &window_size ) < 0 ) {
|
||||||
perror( "ioctl TIOCGWINSZ" );
|
fprintf( stderr, "Server started without pseudo-terminal. Opening 80x24 terminal.\n" );
|
||||||
fprintf( stderr, "If running with ssh, please use ssh -t to provide a PTY.\n" );
|
|
||||||
exit( 1 );
|
/* Fill in sensible defaults. */
|
||||||
|
/* They will be overwritten by client on first connection. */
|
||||||
|
memset( &window_size, 0, sizeof( window_size ) );
|
||||||
|
window_size.ws_col = 80;
|
||||||
|
window_size.ws_row = 24;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* open parser and terminal */
|
/* open parser and terminal */
|
||||||
@@ -361,13 +365,6 @@ int run_server( const char *desired_ip, const char *desired_port,
|
|||||||
fatal_assert( 0 == sigaction( SIGHUP, &sa, NULL ) );
|
fatal_assert( 0 == sigaction( SIGHUP, &sa, NULL ) );
|
||||||
fatal_assert( 0 == sigaction( SIGPIPE, &sa, NULL ) );
|
fatal_assert( 0 == sigaction( SIGPIPE, &sa, NULL ) );
|
||||||
|
|
||||||
struct termios child_termios;
|
|
||||||
|
|
||||||
/* Get terminal configuration */
|
|
||||||
if ( tcgetattr( STDIN_FILENO, &child_termios ) < 0 ) {
|
|
||||||
perror( "tcgetattr" );
|
|
||||||
exit( 1 );
|
|
||||||
}
|
|
||||||
|
|
||||||
/* detach from terminal */
|
/* detach from terminal */
|
||||||
pid_t the_pid = fork();
|
pid_t the_pid = fork();
|
||||||
@@ -385,13 +382,7 @@ int run_server( const char *desired_ip, const char *desired_port,
|
|||||||
|
|
||||||
int master;
|
int master;
|
||||||
|
|
||||||
#ifdef HAVE_IUTF8
|
#ifndef HAVE_IUTF8
|
||||||
if ( !(child_termios.c_iflag & IUTF8) ) {
|
|
||||||
/* SSH should also convey IUTF8 across connection. */
|
|
||||||
// fprintf( stderr, "Warning: Locale is UTF-8 but termios IUTF8 flag not set. Setting IUTF8 flag.\n" );
|
|
||||||
child_termios.c_iflag |= IUTF8;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
fprintf( stderr, "\nWarning: termios IUTF8 flag not defined.\nCharacter-erase of multibyte character sequence\nprobably does not work properly on this platform.\n" );
|
fprintf( stderr, "\nWarning: termios IUTF8 flag not defined.\nCharacter-erase of multibyte character sequence\nprobably does not work properly on this platform.\n" );
|
||||||
#endif /* HAVE_IUTF8 */
|
#endif /* HAVE_IUTF8 */
|
||||||
|
|
||||||
@@ -423,7 +414,7 @@ int run_server( const char *desired_ip, const char *desired_port,
|
|||||||
snprintf( utmp_entry, 64, "mosh [%d]", getpid() );
|
snprintf( utmp_entry, 64, "mosh [%d]", getpid() );
|
||||||
|
|
||||||
/* Fork child process */
|
/* Fork child process */
|
||||||
pid_t child = forkpty( &master, NULL, &child_termios, &window_size );
|
pid_t child = forkpty( &master, NULL, NULL, &window_size );
|
||||||
|
|
||||||
if ( child == -1 ) {
|
if ( child == -1 ) {
|
||||||
perror( "forkpty" );
|
perror( "forkpty" );
|
||||||
@@ -444,6 +435,22 @@ int run_server( const char *desired_ip, const char *desired_port,
|
|||||||
/* close server-related file descriptors */
|
/* close server-related file descriptors */
|
||||||
delete network;
|
delete network;
|
||||||
|
|
||||||
|
/* set IUTF8 if available */
|
||||||
|
#ifdef HAVE_IUTF8
|
||||||
|
struct termios child_termios;
|
||||||
|
if ( tcgetattr( STDIN_FILENO, &child_termios ) < 0 ) {
|
||||||
|
perror( "tcgetattr" );
|
||||||
|
exit( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
child_termios.c_iflag |= IUTF8;
|
||||||
|
|
||||||
|
if ( tcsetattr( STDIN_FILENO, TCSANOW, &child_termios ) < 0 ) {
|
||||||
|
perror( "tcsetattr" );
|
||||||
|
exit( 1 );
|
||||||
|
}
|
||||||
|
#endif /* HAVE_IUTF8 */
|
||||||
|
|
||||||
/* set TERM */
|
/* set TERM */
|
||||||
const char default_term[] = "xterm";
|
const char default_term[] = "xterm";
|
||||||
const char color_term[] = "xterm-256color";
|
const char color_term[] = "xterm-256color";
|
||||||
|
|||||||
Reference in New Issue
Block a user