File: default_linux.go

package info (click to toggle)
golang-github-containers-common 0.56.0%2Bds1-4
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,852 kB
  • sloc: makefile: 126; sh: 62
file content (69 lines) | stat: -rw-r--r-- 1,890 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package config

import (
	"fmt"
	"os"
	"strconv"
	"strings"

	"golang.org/x/sys/unix"
)

const (
	oldMaxSize = uint64(1048576)
)

func getDefaultCgroupsMode() string {
	return "enabled"
}

// getDefaultProcessLimits returns the nproc for the current process in ulimits format
// Note that nfile sometimes cannot be set to unlimited, and the limit is hardcoded
// to (oldMaxSize) 1048576 (2^20), see: http://stackoverflow.com/a/1213069/1811501
// In rootless containers this will fail, and the process will just use its current limits
func getDefaultProcessLimits() []string {
	rlim := unix.Rlimit{Cur: oldMaxSize, Max: oldMaxSize}
	oldrlim := rlim
	// Attempt to set file limit and process limit to pid_max in OS
	dat, err := os.ReadFile("/proc/sys/kernel/pid_max")
	if err == nil {
		val := strings.TrimSuffix(string(dat), "\n")
		max, err := strconv.ParseUint(val, 10, 64)
		if err == nil {
			rlim = unix.Rlimit{Cur: max, Max: max}
		}
	}
	defaultLimits := []string{}
	if err := unix.Setrlimit(unix.RLIMIT_NPROC, &rlim); err == nil {
		defaultLimits = append(defaultLimits, fmt.Sprintf("nproc=%d:%d", rlim.Cur, rlim.Max))
	} else if err := unix.Setrlimit(unix.RLIMIT_NPROC, &oldrlim); err == nil {
		defaultLimits = append(defaultLimits, fmt.Sprintf("nproc=%d:%d", oldrlim.Cur, oldrlim.Max))
	}
	return defaultLimits
}

// getDefaultTmpDir for linux
func getDefaultTmpDir() string {
	// first check the TMPDIR env var
	if path, found := os.LookupEnv("TMPDIR"); found {
		return path
	}
	return "/var/tmp"
}

func getDefaultLockType() string {
	return "shm"
}

func getLibpodTmpDir() string {
	return "/run/libpod"
}

// getDefaultMachineVolumes returns default mounted volumes (possibly with env vars, which will be expanded)
func getDefaultMachineVolumes() []string {
	return []string{"$HOME:$HOME"}
}

func getDefaultComposeProviders() []string {
	return defaultUnixComposeProviders
}