Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add 'numFiles' option to set fd limits

  • Loading branch information...
commit 2900f01909152237ade8f23a3d0ad7f90ca1ceed 1 parent edecfb2
@bradfitz authored
View
1  config/daemon1.json
@@ -6,6 +6,7 @@
"FOO": "BAR",
"WANT_USER": ["_env", "want-${USER}"]
},
+ "numFiles": 123,
"binary": "./testdaemon",
"args": [
"--port", "8081"
View
27 exec.go
@@ -33,13 +33,14 @@ import (
// in the environment variable _RUNSIT_LAUNCH_INFO. The child then
// drops root and execs itself to be the requested process.
type LaunchRequest struct {
- Uid int // or 0 to not change
- Gid int // or 0 to not change
- Gids []int // supplemental
- Path string
- Env []string
- Argv []string // must include Path as argv[0]
- Dir string
+ Uid int // or 0 to not change
+ Gid int // or 0 to not change
+ Gids []int // supplemental
+ Path string
+ Env []string
+ Argv []string // must include Path as argv[0]
+ Dir string
+ NumFiles int // new nfile fd rlimit, or 0 to not change
}
func (lr *LaunchRequest) start(extraFiles []*os.File) (cmd *exec.Cmd, outPipe, errPipe io.ReadCloser, err error) {
@@ -120,6 +121,18 @@ func MaybeBecomeChildProcess() {
log.Fatalf("failed to chdir to %q: %v", lr.Dir, err)
}
}
+ if lr.NumFiles != 0 {
+ var lim syscall.Rlimit
+ if err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &lim); err != nil {
+ log.Fatalf("failed to get NOFILE rlimit: %v", err)
+ }
+ noFile := uint64(lr.NumFiles)
+ lim.Cur = noFile
+ lim.Max = noFile
+ if err := syscall.Setrlimit(syscall.RLIMIT_NOFILE, &lim); err != nil {
+ log.Fatalf("failed to set NOFILE rlimit: %v", err)
+ }
+ }
err = syscall.Exec(lr.Path, lr.Argv, lr.Env)
log.Fatalf("failed to exec %q: %v", lr.Path, err)
}
View
10 runsit.go
@@ -405,6 +405,7 @@ func (t *Task) updateFromConfig(jc jsonconfig.Obj) (err error) {
dir := jc.OptionalString("cwd", "")
args := jc.OptionalList("args")
groups := jc.OptionalList("groups")
+ numFiles := jc.OptionalInt("numFiles", 0)
if err := jc.Validate(); err != nil {
return t.configError("configuration error: %v", err)
}
@@ -428,10 +429,11 @@ func (t *Task) updateFromConfig(jc jsonconfig.Obj) (err error) {
argv = append(argv, args...)
lr := &LaunchRequest{
- Path: bin,
- Env: env,
- Dir: dir,
- Argv: argv,
+ Path: bin,
+ Env: env,
+ Dir: dir,
+ Argv: argv,
+ NumFiles: numFiles,
}
if runas != nil {
View
5 test/daemon/Makefile
@@ -1,5 +0,0 @@
-include $(GOROOT)/src/Make.inc
-TARG=testdaemon
-GOFILES=testdaemon.go
-include $(GOROOT)/src/Make.cmd
-
View
3  test/daemon/testdaemon.go
@@ -60,6 +60,9 @@ func statusHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "groups=%s\n", strings.TrimSpace(string(groups)))
}
+ ulimitN, _ := exec.Command("ulimit", "-n").Output()
+ fmt.Fprintf(w, "ulimit_nofiles=%s\n", strings.TrimSpace(string(ulimitN)))
+
env := os.Environ()
sort.Strings(env)
for _, env := range env {
Please sign in to comment.
Something went wrong with that request. Please try again.