Close terminal fd's to properly detach on old sshd (e.g. RHEL/CentOS 5.0).
May help some sufferers of #114 github issue.
This commit is contained in:
@@ -66,7 +66,7 @@ void serve( int host_fd,
|
|||||||
ServerConnection &network );
|
ServerConnection &network );
|
||||||
|
|
||||||
int run_server( const char *desired_ip, const char *desired_port,
|
int run_server( const char *desired_ip, const char *desired_port,
|
||||||
char *command[], const int colors );
|
char *command[], const int colors, bool verbose );
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -111,6 +111,8 @@ int main( int argc, char *argv[] )
|
|||||||
char *desired_port = NULL;
|
char *desired_port = NULL;
|
||||||
char **command = NULL;
|
char **command = NULL;
|
||||||
int colors = 0;
|
int colors = 0;
|
||||||
|
bool verbose = false; /* don't close stdin/stdout/stderr */
|
||||||
|
/* Will cause mosh-server not to correctly detach on old versions of sshd. */
|
||||||
|
|
||||||
/* strip off command */
|
/* strip off command */
|
||||||
for ( int i = 0; i < argc; i++ ) {
|
for ( int i = 0; i < argc; i++ ) {
|
||||||
@@ -128,7 +130,7 @@ int main( int argc, char *argv[] )
|
|||||||
&& (strcmp( argv[ 1 ], "new" ) == 0) ) {
|
&& (strcmp( argv[ 1 ], "new" ) == 0) ) {
|
||||||
/* new option syntax */
|
/* new option syntax */
|
||||||
int opt;
|
int opt;
|
||||||
while ( (opt = getopt( argc - 1, argv + 1, "i:p:c:s" )) != -1 ) {
|
while ( (opt = getopt( argc - 1, argv + 1, "i:p:c:sv" )) != -1 ) {
|
||||||
switch ( opt ) {
|
switch ( opt ) {
|
||||||
case 'i':
|
case 'i':
|
||||||
desired_ip = optarg;
|
desired_ip = optarg;
|
||||||
@@ -143,6 +145,9 @@ int main( int argc, char *argv[] )
|
|||||||
case 'c':
|
case 'c':
|
||||||
colors = myatoi( optarg );
|
colors = myatoi( optarg );
|
||||||
break;
|
break;
|
||||||
|
case 'v':
|
||||||
|
verbose = true;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
print_usage( argv[ 0 ] );
|
print_usage( argv[ 0 ] );
|
||||||
/* don't die on unknown options */
|
/* don't die on unknown options */
|
||||||
@@ -201,7 +206,7 @@ int main( int argc, char *argv[] )
|
|||||||
assert_utf8_locale();
|
assert_utf8_locale();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return run_server( desired_ip, desired_port, command, colors );
|
return run_server( desired_ip, desired_port, command, colors, verbose );
|
||||||
} catch ( Network::NetworkException e ) {
|
} catch ( Network::NetworkException e ) {
|
||||||
fprintf( stderr, "Network exception: %s: %s\n",
|
fprintf( stderr, "Network exception: %s: %s\n",
|
||||||
e.function.c_str(), strerror( e.the_errno ) );
|
e.function.c_str(), strerror( e.the_errno ) );
|
||||||
@@ -214,7 +219,7 @@ int main( int argc, char *argv[] )
|
|||||||
}
|
}
|
||||||
|
|
||||||
int run_server( const char *desired_ip, const char *desired_port,
|
int run_server( const char *desired_ip, const char *desired_port,
|
||||||
char *command[], const int colors ) {
|
char *command[], const int colors, bool verbose ) {
|
||||||
/* 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 ) {
|
||||||
@@ -332,6 +337,12 @@ int run_server( const char *desired_ip, const char *desired_port,
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* parent */
|
/* parent */
|
||||||
|
if ( !verbose ) {
|
||||||
|
/* Necessary to properly detach on old versions of sshd (e.g. RHEL/CentOS 5.0). */
|
||||||
|
close( STDIN_FILENO );
|
||||||
|
close( STDOUT_FILENO );
|
||||||
|
close( STDERR_FILENO );
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_UTEMPTER
|
#ifdef HAVE_UTEMPTER
|
||||||
/* make utmp entry */
|
/* make utmp entry */
|
||||||
|
|||||||
Reference in New Issue
Block a user