diff --git a/cnitool/cnitool.go b/cnitool/cnitool.go index 0ba91838..b2685bce 100644 --- a/cnitool/cnitool.go +++ b/cnitool/cnitool.go @@ -66,6 +66,23 @@ func main() { if netdir == "" { netdir = DefaultNetDir } + + if !filepath.IsAbs(netdir) { + var err error + netdir, err = filepath.Abs(netdir) + if err != nil { + exit(fmt.Errorf("error converting the provided CNI config path ($%s) %q to an absolute path: %s", EnvNetDir, netdir, err)) + } + } + + if stat, err := os.Stat(netdir); err == nil { + if !stat.IsDir() { + exit(fmt.Errorf("the provided CNI config path ($%s) is not a directory: %q", EnvNetDir, netdir)) + } + } else { + exit(fmt.Errorf("the provided CNI config path ($%s) does not exist: %q", EnvNetDir, netdir)) + } + netconf, err := libcni.LoadConfList(netdir, os.Args[2]) if err != nil { exit(err)