Use environment variable to convey prediction display preference

This commit is contained in:
Keith Winstein
2012-02-13 06:07:26 -05:00
parent f6d8b4cb38
commit 309e38d889
2 changed files with 32 additions and 13 deletions
+25 -4
View File
@@ -26,7 +26,8 @@ $|=1;
my $client = 'mosh-client'; my $client = 'mosh-client';
my $server = 'mosh-server'; my $server = 'mosh-server';
my $predict = 'adaptive';
my $predict = undef;
my $usage = my $usage =
qq{Usage: $0 [options] [user@]host qq{Usage: $0 [options] [user@]host
@@ -40,6 +41,17 @@ qq{Usage: $0 [options] [user@]host
Please report bugs to mosh-devel\@mit.edu. Please report bugs to mosh-devel\@mit.edu.
Mosh home page: http://mosh.mit.edu\n}; Mosh home page: http://mosh.mit.edu\n};
sub predict_check {
my ( $predict, $env_set ) = @_;
if ( not exists { adaptive => 0, always => 0, never => 0 }->{ $predict } ) {
my $explanation = $env_set ? " (MOSH_PREDICTION_DISPLAY in environment)" : "";
print STDERR qq{$0: Unknown mode \"$predict\"$explanation.\n\n};
die $usage;
}
}
GetOptions( 'client=s' => \$client, GetOptions( 'client=s' => \$client,
'server=s' => \$server, 'server=s' => \$server,
'predict=s' => \$predict, 'predict=s' => \$predict,
@@ -47,10 +59,18 @@ GetOptions( 'client=s' => \$client,
'n' => sub { $predict = 'never' }, 'n' => sub { $predict = 'never' },
'fake-proxy!' => \my $fake_proxy ) or die $usage; 'fake-proxy!' => \my $fake_proxy ) or die $usage;
if ( not exists { adaptive => 0, always => 0, never => 0 }->{ $predict } ) { if ( defined $predict ) {
die $usage; predict_check( $predict, 0 );
} elsif ( defined $ENV{ 'MOSH_PREDICTION_DISPLAY' } ) {
$predict = $ENV{ 'MOSH_PREDICTION_DISPLAY' };
predict_check( $predict, 1 );
} else {
$predict = 'adaptive';
predict_check( $predict, 0 );
} }
delete $ENV{ 'MOSH_PREDICTION_DISPLAY' };
if ( defined $fake_proxy ) { if ( defined $fake_proxy ) {
use Errno qw(EINTR); use Errno qw(EINTR);
use IO::Socket::INET; use IO::Socket::INET;
@@ -137,5 +157,6 @@ if ( $pid == 0 ) { # child
# Now start real mosh client # Now start real mosh client
$ENV{ 'MOSH_KEY' } = $key; $ENV{ 'MOSH_KEY' } = $key;
exec {$client} ($client, $ip, $port, $predict); $ENV{ 'MOSH_PREDICTION_DISPLAY' } = $predict;
exec {$client} ($client, $ip, $port);
} }
+7 -9
View File
@@ -23,7 +23,7 @@
#include "crypto.h" #include "crypto.h"
void usage( const char *argv0 ) { void usage( const char *argv0 ) {
fprintf( stderr, "Usage: %s IP PORT [always|never|adaptive]\n", argv0 ); fprintf( stderr, "Usage: %s IP PORT\n", argv0 );
} }
int main( int argc, char *argv[] ) int main( int argc, char *argv[] )
@@ -32,14 +32,8 @@ int main( int argc, char *argv[] )
char *ip; char *ip;
int port; int port;
char *predict_mode = NULL; if ( argc != 3 ) {
usage( argv[ 0 ] );
if ( argc == 4 ) {
predict_mode = argv[ 3 ];
} else if ( argc == 3 ) {
/* do nothing */
} else {
usage( argv[ 0 ]);
exit( 1 ); exit( 1 );
} }
@@ -53,6 +47,10 @@ int main( int argc, char *argv[] )
exit( 1 ); exit( 1 );
} }
/* Read prediction preference */
char *predict_mode = getenv( "MOSH_PREDICTION_DISPLAY" );
/* can be NULL */
char *key = strdup( env_key ); char *key = strdup( env_key );
if ( key == NULL ) { if ( key == NULL ) {
perror( "strdup" ); perror( "strdup" );