nsutil: wrap error that comes from the syscall so caller can do errors.As (#24480)

User of `nsutil` library should be able to do the following and for it
to work:

```
  var errno syscall.Errno
   if errors.As(err, &errno) {
       if errno == unix.EBUSY { ... }
   }
```

This commit fixes that issue.
This commit is contained in:
Gabi
2024-11-19 03:24:49 -06:00
committed by GitHub
parent 6be9a50626
commit 89c3d69d79

View File

@@ -133,11 +133,11 @@ func UnmountNS(nsPath string) error {
// Only unmount if it's been bind-mounted (don't touch namespaces in /proc...)
if strings.HasPrefix(nsPath, NetNSRunDir) {
if err := unix.Unmount(nsPath, 0); err != nil {
return fmt.Errorf("failed to unmount NS: at %s: %v", nsPath, err)
return fmt.Errorf("failed to unmount NS: at %s: %w", nsPath, err)
}
if err := os.Remove(nsPath); err != nil {
return fmt.Errorf("failed to remove ns path %s: %v", nsPath, err)
return fmt.Errorf("failed to remove ns path %s: %w", nsPath, err)
}
}