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

add pre-exec function on exec.Command #6603

Closed
gopherbot opened this issue Oct 16, 2013 · 2 comments
Closed

add pre-exec function on exec.Command #6603

gopherbot opened this issue Oct 16, 2013 · 2 comments

Comments

@gopherbot
Copy link
Contributor

by bchesneau:

Looking at the doc it doesn't seem possible to add a pre exec function to the
`exec.Command` function like you could do in `subprocess.Popen` in Python [1]. Is anyone
aware of such implementation?  The idea is to set there some rlimit of a process and
such. 

It would be interesting to have such feature.

[1]
http://docs.python.org/2/library/subprocess.html?highlight=subprocess#subprocess.Popen
@bradfitz
Copy link
Contributor

Comment 1:

Something like Python's preexec_fn (which is Unix-only even with Python) is much
harder/racier in Go.  In general you can't do anything between fork and exec without
lots of care, especially in the presence of other threads.
For your case: you can exec a program to set the rlimit, and then have that program exec
the final binary.
It's possible we could add some rlimit-like stuff to exec.Cmd.SysProcAttr
(*syscall.SysProcAttr) but it seems unlikely.

Status changed to Unfortunate.

@gopherbot
Copy link
Contributor Author

Comment 2 by bchesneau:

I was thinking such function could be add to 
http://golang.org/src/pkg/syscall/exec_linux.go#L224
and relcace SYS_EXECVE by SYS_EXECVP (the same for bsd)  but right it seems simpler
doing the  method you propose.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
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

2 participants