Merge pull request #3648 from yaoyinnan/index-in-for

runtime: The index variable is initialized multiple times in for
This commit is contained in:
James O. D. Hunt
2022-02-14 12:36:46 +00:00
committed by GitHub

View File

@@ -94,10 +94,14 @@ func SetupNetworkNamespace(config *vc.NetworkConfig) error {
return nil return nil
} }
const (
netNsMountType = "nsfs"
mountTypeFieldIdx = 8
mountDestIdx = 4
)
// getNetNsFromBindMount returns the network namespace for the bind-mounted path // getNetNsFromBindMount returns the network namespace for the bind-mounted path
func getNetNsFromBindMount(nsPath string, procMountFile string) (string, error) { func getNetNsFromBindMount(nsPath string, procMountFile string) (string, error) {
netNsMountType := "nsfs"
// Resolve all symlinks in the path as the mountinfo file contains // Resolve all symlinks in the path as the mountinfo file contains
// resolved paths. // resolved paths.
nsPath, err := filepath.EvalSymlinks(nsPath) nsPath, err := filepath.EvalSymlinks(nsPath)
@@ -129,14 +133,12 @@ func getNetNsFromBindMount(nsPath string, procMountFile string) (string, error)
} }
// We check here if the mount type is a network namespace mount type, namely "nsfs" // We check here if the mount type is a network namespace mount type, namely "nsfs"
mountTypeFieldIdx := 8
if fields[mountTypeFieldIdx] != netNsMountType { if fields[mountTypeFieldIdx] != netNsMountType {
continue continue
} }
// This is the mount point/destination for the mount // This is the mount point/destination for the mount
mntDestIdx := 4 if fields[mountDestIdx] != nsPath {
if fields[mntDestIdx] != nsPath {
continue continue
} }