github.com/google/cadvisor@v0.49.1/devicemapper/util.go (about) 1 // Copyright 2016 Google Inc. All Rights Reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package devicemapper 16 17 import ( 18 "fmt" 19 "os" 20 "path/filepath" 21 ) 22 23 // ThinLsBinaryPresent returns the location of the thin_ls binary in the mount 24 // namespace cadvisor is running in or an error. The locations checked are: 25 // 26 // - /sbin/ 27 // - /bin/ 28 // - /usr/sbin/ 29 // - /usr/bin/ 30 // 31 // The thin_ls binary is provided by the device-mapper-persistent-data 32 // package. 33 func ThinLsBinaryPresent() (string, error) { 34 var ( 35 thinLsPath string 36 err error 37 ) 38 39 for _, path := range []string{"/sbin", "/bin", "/usr/sbin/", "/usr/bin"} { 40 // try paths for non-containerized operation 41 // note: thin_ls is most likely a symlink to pdata_tools 42 thinLsPath = filepath.Join(path, "thin_ls") 43 _, err = os.Stat(thinLsPath) 44 if err == nil { 45 return thinLsPath, nil 46 } 47 } 48 49 return "", fmt.Errorf("unable to find thin_ls binary") 50 }