Skip to content

Commit

Permalink
Merge pull request #3270 from kolyshkin/wrap-err
Browse files Browse the repository at this point in the history
libct: wrap more unix errors
  • Loading branch information
thaJeztah authored Nov 14, 2021
2 parents f247ad2 + 7563a8f commit 7c219d8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
11 changes: 6 additions & 5 deletions libcontainer/init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"net"
"os"
"strconv"
"strings"
"unsafe"

Expand Down Expand Up @@ -377,7 +378,7 @@ func setupUser(config *initConfig) error {
if allowSupGroups {
suppGroups := append(execUser.Sgids, addGroups...)
if err := unix.Setgroups(suppGroups); err != nil {
return err
return &os.SyscallError{Syscall: "setgroups", Err: err}
}
}

Expand All @@ -403,7 +404,7 @@ func setupUser(config *initConfig) error {
func fixStdioPermissions(config *initConfig, u *user.ExecUser) error {
var null unix.Stat_t
if err := unix.Stat("/dev/null", &null); err != nil {
return err
return &os.PathError{Op: "stat", Path: "/dev/null", Err: err}
}
for _, fd := range []uintptr{
os.Stdin.Fd(),
Expand All @@ -412,7 +413,7 @@ func fixStdioPermissions(config *initConfig, u *user.ExecUser) error {
} {
var s unix.Stat_t
if err := unix.Fstat(int(fd), &s); err != nil {
return err
return &os.PathError{Op: "fstat", Path: "fd " + strconv.Itoa(int(fd)), Err: err}
}

// Skip chown of /dev/null if it was used as one of the STDIO fds.
Expand All @@ -438,7 +439,7 @@ func fixStdioPermissions(config *initConfig, u *user.ExecUser) error {
if err == unix.EINVAL || err == unix.EPERM {
continue
}
return err
return &os.PathError{Op: "fchown", Path: "fd " + strconv.Itoa(int(fd)), Err: err}
}
}
return nil
Expand Down Expand Up @@ -518,7 +519,7 @@ func isWaitable(pid int) (bool, error) {
si := &siginfo{}
_, _, e := unix.Syscall6(unix.SYS_WAITID, _P_PID, uintptr(pid), uintptr(unsafe.Pointer(si)), unix.WEXITED|unix.WNOWAIT|unix.WNOHANG, 0, 0)
if e != 0 {
return false, os.NewSyscallError("waitid", e)
return false, &os.SyscallError{Syscall: "waitid", Err: e}
}

return si.si_pid != 0, nil
Expand Down
2 changes: 1 addition & 1 deletion libcontainer/process_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ func (p *Process) InitializeIO(rootuid, rootgid int) (i *IO, err error) {
// change ownership of the pipes in case we are in a user namespace
for _, fd := range fds {
if err := unix.Fchown(int(fd), rootuid, rootgid); err != nil {
return nil, err
return nil, &os.PathError{Op: "fchown", Path: "fd " + strconv.Itoa(int(fd)), Err: err}
}
}
return i, nil
Expand Down
10 changes: 5 additions & 5 deletions libcontainer/rootfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ func reOpenDevNull() error {
}
for fd := 0; fd < 3; fd++ {
if err := unix.Fstat(fd, &stat); err != nil {
return err
return &os.PathError{Op: "fstat", Path: "fd " + strconv.Itoa(fd), Err: err}
}
if stat.Rdev == devNullStat.Rdev {
// Close and re-open the fd.
Expand Down Expand Up @@ -709,9 +709,9 @@ func createDeviceNode(rootfs string, node *devices.Device, bind bool) error {
return bindMountDeviceNode(rootfs, dest, node)
}
if err := mknodDevice(dest, node); err != nil {
if os.IsExist(err) {
if errors.Is(err, os.ErrExist) {
return nil
} else if os.IsPermission(err) {
} else if errors.Is(err, os.ErrPermission) {
return bindMountDeviceNode(rootfs, dest, node)
}
return err
Expand All @@ -736,9 +736,9 @@ func mknodDevice(dest string, node *devices.Device) error {
return err
}
if err := unix.Mknod(dest, uint32(fileMode), int(dev)); err != nil {
return err
return &os.PathError{Op: "mknod", Path: dest, Err: err}
}
return unix.Chown(dest, int(node.Uid), int(node.Gid))
return os.Chown(dest, int(node.Uid), int(node.Gid))
}

// Get the parent mount point of directory passed in as argument. Also return
Expand Down

0 comments on commit 7c219d8

Please sign in to comment.