X-Git-Url: https://git.distorted.org.uk/~mdw/termux-packages/blobdiff_plain/188d120104c4b1a2d1d5234a7f8de9f6e8fe9a3d..8170d08b609904f02eefbbad93ff06a691f60343:/packages/mosh/mosh.cc diff --git a/packages/mosh/mosh.cc b/packages/mosh/mosh.cc index 9f0352e6..9c306a22 100644 --- a/packages/mosh/mosh.cc +++ b/packages/mosh/mosh.cc @@ -315,17 +315,18 @@ int main( int argc, char *argv[] ) freeaddrinfo( servinfo ); // all done with this structure int pid = fork(); - if ( pid == -1 ) { - die( "%s: fork: %d", argv[0], errno ); - } + if ( pid == -1 ) die( "%s: fork: %d", argv[0], errno ); if ( pid == 0 ) { - cat( sockfd, 1 ); + close( STDIN_FILENO ); + cat( sockfd, STDOUT_FILENO ); shutdown( sockfd, 0 ); exit( 0 ); } signal( SIGHUP, SIG_IGN ); - cat( 0, sockfd ); - shutdown( sockfd, 1 ); + close( STDOUT_FILENO ); + cat( STDIN_FILENO, sockfd ); + shutdown( sockfd, SHUT_WR /* = 1 */ ); + close( STDIN_FILENO ); waitpid( pid, NULL, 0 ); exit( 0 ); } @@ -338,25 +339,9 @@ int main( int argc, char *argv[] ) char **command = &argv[optind]; int commands = argc - optind; - string color_invocation = client + " -c"; - FILE *color_file = popen( color_invocation.c_str(), "r" ); - if ( !color_file ) { - die( "%s: popen: %d", argv[0], errno ); - } char *buf = NULL; size_t buf_sz = 0; ssize_t n; - if ( ( n = getline( &buf, &buf_sz, color_file ) ) < 0 ) { - die( "%s: Can't count colors: %d", argv[0], errno ); - } - string colors = string( buf, n ); - pclose( color_file ); - - if ( !colors.size() || - colors.find_first_not_of( "0123456789" ) != string::npos || - atoi( colors.c_str() ) < 0 ) { - colors = "0"; - } int pty, pty_slave; struct winsize ws; @@ -369,9 +354,7 @@ int main( int argc, char *argv[] ) } int pid = fork(); - if ( pid == -1 ) { - die( "%s: fork: %d", argv[0], errno ); - } + if ( pid == -1 ) die( "%s: fork: %d", argv[0], errno ); if ( pid == 0 ) { close( pty ); if ( -1 == dup2( pty_slave, 1 ) || @@ -384,11 +367,24 @@ int main( int argc, char *argv[] ) server_args.push_back( "new" ); server_args.push_back( "-s" ); server_args.push_back( "-c" ); - server_args.push_back( colors ); + server_args.push_back( "256" ); if ( port_request.size() ) { server_args.push_back( "-p" ); server_args.push_back( port_request ); } + + for (char const* env_name : { + "LANG", "LANGUAGE", "LC_CTYPE", "LC_NUMERIC", + "LC_TIME", "LC_COLLATE", "LC_MONETARY", "LC_MESSAGES", "LC_PAPER", + "LC_NAME", "LC_ADDRESS", "LC_TELEPHONE", "LC_MEASUREMENT", + "LC_IDENTIFICATION", "LC_ALL" }) { + char* env_value = getenv(env_name); + if (env_value) { + server_args.push_back("-l"); + server_args.push_back(string(env_name) + "=" + env_value); + } + } + if ( commands ) { server_args.insert( server_args.end(), command, command + commands ); }