1
0
mirror of https://github.com/mobile-shell/mosh.git synced 2026-03-01 18:23:30 +01:00

Server detaches from controlling terminal.

This commit is contained in:
Keith Winstein
2012-02-03 02:48:13 -05:00
parent ec89d17a8a
commit fcc629ac71
2 changed files with 11 additions and 3 deletions

4
mosh
View File

@@ -30,7 +30,6 @@ my $pid = fork;
die "$0: fork: $!\n" unless ( defined $pid );
if ( $pid == 0 ) { # child
close $pty;
open STDIN, "<&", $pty_slave->fileno() or die;
open STDOUT, ">&", $pty_slave->fileno() or die;
open STDERR, ">&", $pty_slave->fileno() or die;
close $pty_slave;
@@ -44,10 +43,9 @@ if ( $pid == 0 ) { # child
chomp;
if ( m{^MOSH CONNECT} ) {
if ( ( $port, $key ) = m{^MOSH CONNECT (\d+?) (.{22})} ) {
print $pty "\n~."; # Tear down SSH connection
last LINE;
} else {
die "Bad MOSH CONNECT string\n";
die "Bad MOSH CONNECT string: $_\n";
}
} else {
print "$_\n";

View File

@@ -169,6 +169,16 @@ void serve( int host_fd, const char *desired_ip )
printf( "MOSH CONNECT %d %s\n", network.port(), network.get_key().c_str() );
fflush( stdout );
/* detach from terminal */
pid_t the_pid = fork();
if ( the_pid < 0 ) {
perror( "fork" );
} else if ( the_pid > 0 ) {
_exit( 0 );
}
fprintf( stderr, "[mosh-server detached, pid=%d.]\n", (int)getpid() );
/* prepare to poll for events */
struct pollfd pollfds[ 3 ];