Skip to content

Commit 00b3688

Browse files
committed
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 mobile-shell#1042, partially resolves mobile-shell#1005. Also relevant for mobile-shell#1042 and countless questions on IRC.
1 parent f39e1cc commit 00b3688

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

scripts/mosh.pl

+25-4
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,7 @@ sub predict_check {
350350
$userhost = "$user$ip";
351351
}
352352

353-
# Construct exec arguments.
354-
353+
# Construct server exec arguments.
355354
my @sshopts = ( '-n' );
356355
if ($ssh_pty) {
357356
push @sshopts, '-tt';
@@ -450,8 +449,13 @@ sub predict_check {
450449
print "$_\n";
451450
}
452451
}
453-
waitpid $pid, 0;
454-
close $pipe;
452+
if ( not close $pipe ) {
453+
if ( $! == 0 ) {
454+
die_on_exitstatus($?, "server command", shell_quote(@exec_argv));
455+
} else {
456+
die("$0: error closing server pipe: $!\n")
457+
}
458+
}
455459

456460
if ( not defined $ip ) {
457461
if ( defined $sship ) {
@@ -546,3 +550,20 @@ sub resolvename {
546550
}
547551
return @res;
548552
}
553+
554+
sub die_on_exitstatus {
555+
my ($exitstatus, $what_command, $exec_string) = @_;
556+
557+
if (POSIX::WIFSIGNALED($exitstatus)) {
558+
my $termsig = POSIX::WTERMSIG($exitstatus);
559+
die("$0: $what_command exited on signal $termsig: $exec_string\n" );
560+
}
561+
if (!POSIX::WIFEXITED($exitstatus)) {
562+
die("$0: $what_command unexpectedly terminated with exit status $exitstatus: $exec_string\n");
563+
}
564+
my $exitcode = POSIX::WEXITSTATUS($exitstatus);
565+
if ($exitcode != 0) {
566+
die("$0: $what_command failed with exitstatus $exitcode: $exec_string\n");
567+
}
568+
return;
569+
}

0 commit comments

Comments
 (0)