MCPcopy
hub / github.com/opencontainers/runc / WriteSysctls

Function WriteSysctls

internal/sys/sysctl_linux.go:25–50  ·  view source on GitHub ↗

WriteSysctls sets the given sysctls to the requested values.

(sysctls map[string]string)

Source from the content-addressed store, hash-verified

23
24// WriteSysctls sets the given sysctls to the requested values.
25func WriteSysctls(sysctls map[string]string) error {
26 // We are going to write multiple sysctls, which require writing to an
27 // unmasked procfs which is not going to be cached. To avoid creating a new
28 // procfs instance for each one, just allocate one handle for all of them.
29 proc, err := procfs.OpenUnsafeProcRoot()
30 if err != nil {
31 return err
32 }
33 defer proc.Close()
34
35 for key, value := range sysctls {
36 keyPath := strings.ReplaceAll(key, ".", "/")
37
38 sysctlFile, err := procfsOpenRoot(proc, "sys/"+keyPath, unix.O_WRONLY|unix.O_TRUNC|unix.O_CLOEXEC)
39 if err != nil {
40 return fmt.Errorf("open sysctl %s file: %w", key, err)
41 }
42 defer sysctlFile.Close()
43
44 _, err = sysctlFile.WriteString(value)
45 if err != nil {
46 return fmt.Errorf("failed to write sysctl %s = %q: %w", key, value, err)
47 }
48 }
49 return nil
50}

Callers 1

InitMethod · 0.92

Calls 2

procfsOpenRootFunction · 0.85
CloseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…