Skip to content

Commit

Permalink
libpod: Move uses of unix.O_PATH to container_internal_linux.go
Browse files Browse the repository at this point in the history
The O_PATH flag is a recent addition to the open syscall and is not
present in darwin or in FreeBSD releases before 13.1. The constant is
not present in the FreeBSD version of x/sys/unix since that package
supports FreeBSD 12.3 and later.

[NO NEW TESTS NEEDED]

Signed-off-by: Doug Rabson <[email protected]>
  • Loading branch information
dfr committed Aug 17, 2022
1 parent 5d77784 commit 1572420
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions libpod/container_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1545,7 +1545,7 @@ func (c *Container) mountStorage() (_ string, deferredErr error) {

rootUID, rootGID := c.RootUID(), c.RootGID()

dirfd, err := unix.Open(mountPoint, unix.O_RDONLY|unix.O_PATH, 0)
dirfd, err := openDirectory(mountPoint)
if err != nil {
return "", fmt.Errorf("open mount point: %w", err)
}
Expand All @@ -1568,7 +1568,7 @@ func (c *Container) mountStorage() (_ string, deferredErr error) {
return "", fmt.Errorf("resolve /etc in the container: %w", err)
}

etcInTheContainerFd, err := unix.Open(etcInTheContainerPath, unix.O_RDONLY|unix.O_PATH, 0)
etcInTheContainerFd, err := openDirectory(etcInTheContainerPath)
if err != nil {
return "", fmt.Errorf("open /etc in the container: %w", err)
}
Expand Down
4 changes: 4 additions & 0 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -3249,3 +3249,7 @@ func (c *Container) setupRootlessNetwork() error {
}
return nil
}

func openDirectory(path string) (fd int, err error) {
return unix.Open(path, unix.O_RDONLY|unix.O_PATH, 0)
}
4 changes: 4 additions & 0 deletions libpod/container_internal_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,7 @@ func getLocalhostHostEntry(c *Container) etchosts.HostEntries {
func isRootlessCgroupSet(cgroup string) bool {
return false
}

func openDirectory(path string) (fd int, err error) {
return -1, errors.New("unsupported openDirectory")
}

0 comments on commit 1572420

Please sign in to comment.