MCPcopy Index your code
hub / github.com/syncthing/syncthing / runningInContainer

Function runningInContainer

lib/api/api_test.go:1830–1846  ·  view source on GitHub ↗

runningInContainer returns true if we are inside Docker or LXC. It might be prone to false negatives if things change in the future, but likely not false positives.

()

Source from the content-addressed store, hash-verified

1828// be prone to false negatives if things change in the future, but likely
1829// not false positives.
1830func runningInContainer() bool {
1831 if !build.IsLinux {
1832 return false
1833 }
1834
1835 bs, err := os.ReadFile("/proc/1/cgroup")
1836 if err != nil {
1837 return false
1838 }
1839 if bytes.Contains(bs, []byte("/docker/")) {
1840 return true
1841 }
1842 if bytes.Contains(bs, []byte("/lxc/")) {
1843 return true
1844 }
1845 return false
1846}

Callers 1

TestHostCheckFunction · 0.85

Calls 1

ContainsMethod · 0.80

Tested by

no test coverage detected