diff options
Diffstat (limited to 'ui/build/rbe.go')
| -rw-r--r-- | ui/build/rbe.go | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/ui/build/rbe.go b/ui/build/rbe.go index 0a0f95628..d4d380f98 100644 --- a/ui/build/rbe.go +++ b/ui/build/rbe.go @@ -16,9 +16,11 @@ package build import ( "fmt" + "math" "os" "path/filepath" "runtime" + "strconv" "strings" "android/soong/remoteexec" @@ -210,3 +212,26 @@ func PrintOutDirWarning(ctx Context, config Config) { fmt.Fprintln(ctx.Writer, "") } } + +// ulimit returns ulimit result for |opt|. +// if the resource is unlimited, it returns math.MaxInt32 so that a caller do +// not need special handling of the returned value. +// +// Note that since go syscall package do not have RLIMIT_NPROC constant, +// we use bash ulimit instead. +func ulimitOrFatal(ctx Context, config Config, opt string) int { + commandText := fmt.Sprintf("ulimit %s", opt) + cmd := Command(ctx, config, commandText, "bash", "-c", commandText) + output := strings.TrimRight(string(cmd.CombinedOutputOrFatal()), "\n") + ctx.Verbose(output + "\n") + ctx.Verbose("done\n") + + if output == "unlimited" { + return math.MaxInt32 + } + num, err := strconv.Atoi(output) + if err != nil { + ctx.Fatalf("ulimit returned unexpected value: %s: %v\n", opt, err) + } + return num +} |
