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 $server = 'mosh-server';
my $predict = 'adaptive';
my $predict = undef;
my $usage =
qq{Usage: $0 [options] [user@]host
@@ -40,6 +41,17 @@ qq{Usage: $0 [options] [user@]host
Please report bugs to mosh-devel\@mit.edu.
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,
'server=s' => \$server,
'predict=s' => \$predict,
@@ -47,10 +59,18 @@ GetOptions( 'client=s' => \$client,
'n' => sub { $predict = 'never' },
'fake-proxy!' => \my $fake_proxy ) or die $usage;
if ( not exists { adaptive => 0, always => 0, never => 0 }->{ $predict } ) {
die $usage;
if ( defined $predict ) {
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 ) {
use Errno qw(EINTR);
use IO::Socket::INET;
@@ -137,5 +157,6 @@ if ( $pid == 0 ) { # child
# Now start real mosh client
$ENV{ 'MOSH_KEY' } = $key;
exec {$client} ($client, $ip, $port, $predict);
$ENV{ 'MOSH_PREDICTION_DISPLAY' } = $predict;
exec {$client} ($client, $ip, $port);
}
+6 -8
View File
@@ -23,7 +23,7 @@
#include "crypto.h"
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[] )
@@ -32,13 +32,7 @@ int main( int argc, char *argv[] )
char *ip;
int port;
char *predict_mode = NULL;
if ( argc == 4 ) {
predict_mode = argv[ 3 ];
} else if ( argc == 3 ) {
/* do nothing */
} else {
if ( argc != 3 ) {
usage( argv[ 0 ] );
exit( 1 );
}
@@ -53,6 +47,10 @@ int main( int argc, char *argv[] )
exit( 1 );
}
/* Read prediction preference */
char *predict_mode = getenv( "MOSH_PREDICTION_DISPLAY" );
/* can be NULL */
char *key = strdup( env_key );
if ( key == NULL ) {
perror( "strdup" );