From 4b6fa729fff1a4305e67bab9ed50ef1711a97841 Mon Sep 17 00:00:00 2001 From: Juerd Waalboer Date: Thu, 1 Feb 2024 00:03:26 +0100 Subject: [PATCH] Better check for lost controlling terminal The eof check has to read a character. It happened to work, but it was not the right way to check this. Also added a warning for when someone does "ssh $host revbank" instead of "ssh -t $host revbank". --- revbank | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/revbank b/revbank index 8cf11ba..662df3a 100755 --- a/revbank +++ b/revbank @@ -6,6 +6,7 @@ use feature qw(signatures isa); no warnings "experimental::signatures"; use List::Util qw(uniq); +use POSIX qw(ttyname); use FindBin qw($RealBin); use lib "$RealBin/lib"; @@ -15,7 +16,7 @@ use RevBank::Messages; use RevBank::Cart; use RevBank::Prompt; -our $VERSION = "6.0.1"; +our $VERSION = "6.0.2"; our %HELP1 = ( "abort" => "Abort the current transaction", ); @@ -34,8 +35,12 @@ if (@ARGV) { @words and not ref $words[0] or die "Syntax error.\n"; push @words, @ARGV[3 .. $#ARGV] if @ARGV > 3; push @words, "help" if not @words; +} elsif (not ttyname fileno STDIN) { + warn "\e[31;1mNo controlling terminal, things will be borken!\n"; + warn "Use ssh -t (or RequestTTY in .ssh/config) for interactive sessions.\e[m\n"; } + $| = 1; my $cart = RevBank::Cart->new; @@ -110,8 +115,7 @@ OUTER: for (;;) { $prompt, \@completions, $default, $pos, $cart, \@plugins ); if (not defined $input) { - # Controlling terminal gone - exit if eof STDIN; + exit if not ttyname fileno STDIN; # Controlling terminal gone } call_hooks "input", $cart, $input, $split_input;