Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

syscall: add mechanism to steal the controlling terminal from a different session group on Linux #20454

Closed
devimc opened this issue May 22, 2017 · 8 comments
Labels
FeatureRequest FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@devimc
Copy link
Contributor

devimc commented May 22, 2017

What version of Go are you using (go version)?

go version devel +5e79787 Mon May 22 13:44:12 2017 +0000 linux/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/X/gopath/"
GORACE=""
GOROOT="/home/X/gopath/src/github.com/golang/go-linux-amd64-bootstrap"
GOTOOLDIR="/home/X/gopath/src/github.com/golang/go-linux-amd64-bootstrap/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build111441286=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"

What did you do?

cmd := exec.Command(config.Path)
cmd.Env = os.Environ()
f, err = os.OpenFile(params.Console, os.O_RDWR, 0660)
if err != nil {
	return -1, err
}
cmd.Stdin = f
cmd.Stdout = f
cmd.Stderr = f
cmd.SysProcAttr = &syscall.SysProcAttr{
	// Create Session
	Setsid: true,
	// Set Controlling terminal to Ctty
	Setctty: true,
	Ctty:    int(f.Fd()),
}
if err := cmd.Start(); err != nil {
	return -1, err
}

What did you expect to see?

A processes running using the assigned terminal

What did you see instead?

fork/exec X: operation not permitted

Solution

Allow spawned processes steal the terminal

@devimc
Copy link
Contributor Author

devimc commented May 22, 2017

proposed fix devimc@559e40c

@bradfitz bradfitz changed the title fork/exec operation not permitted syscall: add mechanism to steal the controlling terminal from a different session group on Linux May 22, 2017
@bradfitz bradfitz added this to the Go1.10 milestone May 22, 2017
@bradfitz bradfitz added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label May 22, 2017
@bradfitz
Copy link
Contributor

To @ianlancetaylor for decision.

@devimc, we can't review code outside of Gerrit, which enforces that a CLA has been submitted. See https://golang.org/doc/contribute.html

But you can wait until Ian decides whether this is something we want.

@devimc
Copy link
Contributor Author

devimc commented May 22, 2017

@bradfitz great! thanks

@ianlancetaylor
Copy link
Contributor

Being able to steal the controlling TTY makes sense.

I think the only thing that really needs to be decided is whether we should always steal the TTY, or whether we should have a new field in syscall.SysProcAttr saying whether to steal the TTY. My inclination is to always steal the TTY if possible--that is, always pass 1 as the argument to TIOCSCTTY.

@devimc
Copy link
Contributor Author

devimc commented May 26, 2017

I think we can't always pass 1 as the argument to TIOCSCTTY because if the process has not the capability to steal the tty (CAP_SYS_ADMIN) this call will fail, for that reason I think the best way to address this is allowing user/developer to decide when steal or not a tty

@ianlancetaylor
Copy link
Contributor

As far as I can see in the Linux kernel sources, the argument to TIOCSCTTY is only checked if the tty is already the controlling terminal of some other session. Do you see something else?

@gopherbot
Copy link

CL https://golang.org/cl/44343 mentions this issue.

@devimc
Copy link
Contributor Author

devimc commented May 30, 2017

Hi @ianlancetaylor you're right, I sent a PR https://golang.org/cl/44343
thanks

@golang golang locked and limited conversation to collaborators May 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

4 participants