Skip to content

proposal: os/exec: add an API to exec over the current process #18148

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

Closed
bcmills opened this issue Dec 1, 2016 · 6 comments
Closed

proposal: os/exec: add an API to exec over the current process #18148

bcmills opened this issue Dec 1, 2016 · 6 comments

Comments

@bcmills
Copy link
Contributor

bcmills commented Dec 1, 2016

Go programs cannot currently call syscall.Exec safely (see #18146).

However, it is sometimes useful for a Go program to be able to execute some other command without retaining resources (such as memory) for a Go program that has no further work to do. syscall.Exec, although error-prone in Go, is the usual way to do that on a Unix-like platform.

If we can find a way to implement portable Exec-like functionality compatible with the Go runtime, it would be nice to have an API for that as part of the standard library (perhaps in the os/exec package). If it cannot be done portably, perhaps we could add something to x/sys/unix?

@bcmills bcmills changed the title proposal: os/exec: add an API to exec a new program over the current process proposal: os/exec: add an API to exec over the current process Dec 1, 2016
@bradfitz
Copy link
Contributor

bradfitz commented Dec 1, 2016

x/sys/unix sounds preferable.

@ianlancetaylor
Copy link
Contributor

If we can find a way to implement it portably, then depending on what we do, we should consider simply doing that in syscall.Exec.

But perhaps it would be enough to simply retry EGAIN errors on pthread_create in runtime/cgo.

@kevinburke
Copy link
Contributor

(FWIW I tried to use syscall.Exec recently and found it pretty confusing as someone who has previously typed exec in the terminal, but never used the execve syscall, in terms of how it expected arguments (setting PATH in the 3rd argument won't matter for finding the executable), so I think there is some potential for a usability gain in addition to fixing the underlying correctness problem. See for example https://go-review.googlesource.com/#/c/29121/2)

@bradfitz bradfitz added this to the Proposal milestone Dec 5, 2016
@rsc
Copy link
Contributor

rsc commented Dec 5, 2016

It's not possible to do portably, right? The concept doesn't exist in Windows, and it's not allowed in multithreaded (= all Go) programs on macOS. That's why there's only syscall.Exec.

It seems like if syscall.Exec has bugs, they should be fixed (like #18146, which Ian is fixing). But it's in syscall precisely because it's not portable.

@rsc
Copy link
Contributor

rsc commented Dec 12, 2016

It sounds like we should decline this proposal. Objections?

@bcmills
Copy link
Contributor Author

bcmills commented Dec 12, 2016

I'm ok with declining.

@golang golang locked and limited conversation to collaborators Dec 12, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants