From e301e165ac3bd591a2c8b52dcc5bdd2b0ef68191 Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Wed, 26 Jun 2019 17:09:14 +0000 Subject: Revert "syscall: use Ctty before fd shuffle" This reverts commit 103b5b66921b351f8db4fc6e83bf147b1a0d7580. Reason for revert: Breaks valid existing programs. Updates #29458 Change-Id: I7ace4ae404cf2a8b0e15e646663c50115f74b758 Reviewed-on: https://go-review.googlesource.com/c/go/+/183939 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Greg Thelen Reviewed-by: Ian Lance Taylor --- src/syscall/exec_libc.go | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'src/syscall/exec_libc.go') diff --git a/src/syscall/exec_libc.go b/src/syscall/exec_libc.go index 11cd2bb9f3..0133139000 100644 --- a/src/syscall/exec_libc.go +++ b/src/syscall/exec_libc.go @@ -180,27 +180,6 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr } } - // Detach fd 0 from tty - if sys.Noctty { - err1 = ioctl(0, uintptr(TIOCNOTTY), 0) - if err1 != 0 { - goto childerror - } - } - - // Set the controlling TTY to Ctty - if sys.Setctty { - // On AIX, TIOCSCTTY is undefined - if TIOCSCTTY == 0 { - err1 = ENOSYS - goto childerror - } - err1 = ioctl(uintptr(sys.Ctty), uintptr(TIOCSCTTY), 0) - if err1 != 0 { - goto childerror - } - } - // Pass 1: look for fd[i] < i and move those up above len(fd) // so that pass 2 won't stomp on an fd it needs later. if pipe < nextfd { @@ -261,6 +240,27 @@ func forkAndExecInChild(argv0 *byte, argv, envv []*byte, chroot, dir *byte, attr close(uintptr(i)) } + // Detach fd 0 from tty + if sys.Noctty { + err1 = ioctl(0, uintptr(TIOCNOTTY), 0) + if err1 != 0 { + goto childerror + } + } + + // Set the controlling TTY to Ctty + if sys.Setctty { + // On AIX, TIOCSCTTY is undefined + if TIOCSCTTY == 0 { + err1 = ENOSYS + goto childerror + } + err1 = ioctl(uintptr(sys.Ctty), uintptr(TIOCSCTTY), 0) + if err1 != 0 { + goto childerror + } + } + // Time to exec. err1 = execve( uintptr(unsafe.Pointer(argv0)), -- cgit v1.3