From 6cd04c131c487ce93896c74005d193a1ab1ce673 Mon Sep 17 00:00:00 2001 From: Ilia Ross Date: Sat, 29 Nov 2025 22:19:02 +0200 Subject: [PATCH] Fix to steal if needed and don't fail unless term wanted #2595 --- 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 41823cdf3..14be79216 100755 --- a/proc/proc-lib.pl +++ b/proc/proc-lib.pl @@ -321,12 +321,25 @@ elsif (defined &linux_openpty && if (defined(&close_controlling_pty)) { &close_controlling_pty(); } - setsid(); # create new session group - my $ctty_arg = 0; # must be writable scalar - ioctl($ttyfh, $TIOCSCTTY, $ctty_arg) # controlling tty - or &error("TIOCSCTTY failed: $!"); - # Child must not hold the master end - close($ptyfh); + my $need_ctty = $ENV{'TERM'} ? 1 : 0; + setsid() # create new session group + or do { + # don't fail, just log it if we have a terminal + &error_stderr("setsid failed: $!") + if ($need_ctty); + }; + close($ptyfh); # child must not hold master + my $ctty_arg = 0; # try normal attach + ioctl($ttyfh, $TIOCSCTTY, $ctty_arg) or do { + $ctty_arg = 1; # try force attach + ioctl($ttyfh, $TIOCSCTTY, $ctty_arg) + or do { + # don't fail, just log it if we have a + # terminal + &error_stderr("TIOCSCTTY failed: $!") + if ($need_ctty); + } + }; # Turn off echoing, if we can eval "use IO::Stty";