From f6bb7384add66f39aa7accec49187d10cc8662a2 Mon Sep 17 00:00:00 2001 From: Jamie Cameron Date: Fri, 13 Jun 2008 18:29:44 +0000 Subject: [PATCH] Turn off echoing of commands run via ptys, if we can --- proc/proc-lib.pl | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/proc/proc-lib.pl b/proc/proc-lib.pl index 698e3f89c..6e5767ee7 100644 --- a/proc/proc-lib.pl +++ b/proc/proc-lib.pl @@ -273,16 +273,22 @@ if (!$@) { if (!$ptyfh) { &error("Failed to create new PTY with IO::Pty"); } - local $ttyfh = $ptyfh->slave(); - local $tty = $ptyfh->ttyname(); local $pid = fork(); if (!$pid) { + local $ttyfh = $ptyfh->slave(); + local $tty = $ptyfh->ttyname(); if (defined(&close_controlling_pty)) { &close_controlling_pty(); } setsid(); # create a new session group $ptyfh->make_slave_controlling_terminal(); + # Turn off echoing, if we can + eval "use IO::Stty"; + if (!$@) { + IO::Stty::stty($ttyfh, 'raw', '-echo'); + } + close(STDIN); close(STDOUT); close(STDERR); untie(*STDIN); untie(*STDOUT); untie(*STDERR); if ($_[1]) { @@ -290,10 +296,11 @@ if (!$@) { ($>, $<) = ($_[1], $_[1]); } - open(STDIN, "<$tty"); - open(STDOUT, ">$tty"); - open(STDERR, ">&STDOUT"); - close($ptyfh); + close($ptyfh); # Used by other side only + open(STDIN, "<&".fileno($ttyfh)); + open(STDOUT, ">&".fileno($ttyfh)); + open(STDERR, ">&".fileno($ttyfh)); + close($ttyfh); # Already dup'd exec($cmd); print "Exec failed : $!\n"; exit 1; @@ -323,6 +330,12 @@ else { open($ttyfh, "+<$tty") || &error("Failed to open $tty : $!"); } + # Turn off echoing, if we can + eval "use IO::Stty"; + if (!$@) { + IO::Stty::stty($ttyfh, 'raw', '-echo'); + } + if (defined(&open_controlling_pty)) { &open_controlling_pty($ptyfh, $ttyfh, $pty, $tty); }