From 28f9cf7e4ae15bfe2e880eeff1986692ccc03a47 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Tue, 6 Mar 2012 17:24:22 -0500 Subject: [PATCH] scripts/mosh: Use fork instead of threads For better support of non-threaded Perl installations. Signed-off-by: Anders Kaseorg --- scripts/mosh | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/mosh b/scripts/mosh index eedb53a..6ca7a27 100755 --- a/scripts/mosh +++ b/scripts/mosh @@ -74,7 +74,7 @@ delete $ENV{ 'MOSH_PREDICTION_DISPLAY' }; if ( defined $fake_proxy ) { use Errno qw(EINTR); use IO::Socket::INET; - use threads; + use POSIX qw(_exit); my ( $host, $port ) = @ARGV; @@ -102,10 +102,13 @@ if ( defined $fake_proxy ) { } } - my $thr = threads->create(sub { cat $sock, \*STDOUT; $sock->shutdown( 0 ); }) - or die "$0: create thread: $!\n"; + defined( my $pid = fork ) or die "$0: fork: $!\n"; + if ( $pid == 0 ) { + cat $sock, \*STDOUT; $sock->shutdown( 0 ); + _exit 0; + } cat \*STDIN, $sock; $sock->shutdown( 1 ); - $thr->join; + waitpid $pid, 0; exit; }