github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/container/lxc/lxcutils/utils_linux.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package lxcutils 5 6 import ( 7 "bufio" 8 "os" 9 "strings" 10 11 "github.com/juju/errors" 12 ) 13 14 func runningInsideLXC() (bool, error) { 15 file, err := os.Open(initProcessCgroupFile) 16 if err != nil { 17 return false, errors.Trace(err) 18 } 19 defer file.Close() 20 21 scanner := bufio.NewScanner(file) 22 for scanner.Scan() { 23 line := scanner.Text() 24 fields := strings.Split(line, ":") 25 if len(fields) != 3 { 26 return false, errors.Errorf("malformed cgroup file") 27 } 28 if fields[2] != "/" { 29 // When running in a container the anchor point will be 30 // something other than "/". 31 return true, nil 32 } 33 } 34 if err := scanner.Err(); err != nil { 35 return false, errors.Annotate(err, "failed to read cgroup file") 36 } 37 return false, nil 38 }