Skip to content

Commit

Permalink
mosh.pl: Report errors on server command failure.
Browse files Browse the repository at this point in the history
I think this will help with the papercut of "Did not find mosh server
startup message".  This message confuses people; often the real
problem is that the command to start the remote mosh-server failed
somehow.

Fixes mobile-shell#1042, partially resolves mobile-shell#1005.

Also relevant for mobile-shell#1042 and countless questions on IRC.
  • Loading branch information
cgull committed Oct 27, 2022
1 parent 4839ba4 commit fc1693f
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions scripts/mosh.pl
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,7 @@ sub predict_check {
$userhost = "$user$ip";
}

# Construct exec arguments.

# Construct server exec arguments.
my @sshopts = ( '-n' );
if ($ssh_pty) {
push @sshopts, '-tt';
Expand Down Expand Up @@ -450,8 +449,13 @@ sub predict_check {
print "$_\n";
}
}
waitpid $pid, 0;
close $pipe;
if ( not close $pipe ) {
if ( $! == 0 ) {
die_on_exitstatus($?, "server command", shell_quote(@exec_argv));
} else {
die("$0: error closing server pipe: $!\n")
}
}

if ( not defined $ip ) {
if ( defined $sship ) {
Expand Down Expand Up @@ -546,3 +550,20 @@ sub resolvename {
}
return @res;
}

sub die_on_exitstatus {
my ($exitstatus, $what_command, $exec_string) = @_;

if (POSIX::WIFSIGNALED($exitstatus)) {
my $termsig = POSIX::WTERMSIG($exitstatus);
die("$0: $what_command exited on signal $termsig: $exec_string\n" );
}
if (!POSIX::WIFEXITED($exitstatus)) {
die("$0: $what_command unexpectedly terminated with exit status $exitstatus: $exec_string\n");
}
my $exitcode = POSIX::WEXITSTATUS($exitstatus);
if ($exitcode != 0) {
die("$0: $what_command failed with exitstatus $exitcode: $exec_string\n");
}
return;
}

0 comments on commit fc1693f

Please sign in to comment.