From fc1693f24eb41d0947a5b2fc8076f18417248456 Mon Sep 17 00:00:00 2001 From: John Hood Date: Wed, 22 Apr 2020 05:23:04 -0400 Subject: [PATCH] mosh.pl: Report errors on server command failure. 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 #1042, partially resolves #1005. Also relevant for #1042 and countless questions on IRC. --- scripts/mosh.pl | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/scripts/mosh.pl b/scripts/mosh.pl index 505381e72..249bbc370 100755 --- a/scripts/mosh.pl +++ b/scripts/mosh.pl @@ -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'; @@ -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 ) { @@ -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; +}