Portability fixes for containerd shim
Update go-runc to master with portability fixes. Subreaper only exists on Linux, and only Linux runs the shim in a mount namespace. With these changes the shim compiles on Darwin, which means the whole build compiles without errors now. Signed-off-by: Justin Cormack <justin.cormack@docker.com>
This commit is contained in:
21
vendor/github.com/containerd/go-runc/command_linux.go
generated
vendored
Normal file
21
vendor/github.com/containerd/go-runc/command_linux.go
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
package runc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/exec"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func (r *Runc) command(context context.Context, args ...string) *exec.Cmd {
|
||||
command := r.Command
|
||||
if command == "" {
|
||||
command = DefaultCommand
|
||||
}
|
||||
cmd := exec.CommandContext(context, command, append(r.args(), args...)...)
|
||||
if r.PdeathSignal != 0 {
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
Pdeathsig: r.PdeathSignal,
|
||||
}
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
16
vendor/github.com/containerd/go-runc/command_other.go
generated
vendored
Normal file
16
vendor/github.com/containerd/go-runc/command_other.go
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
// +build !linux
|
||||
|
||||
package runc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func (r *Runc) command(context context.Context, args ...string) *exec.Cmd {
|
||||
command := r.Command
|
||||
if command == "" {
|
||||
command = DefaultCommand
|
||||
}
|
||||
return exec.CommandContext(context, command, append(r.args(), args...)...)
|
||||
}
|
||||
75
vendor/github.com/containerd/go-runc/console.go
generated
vendored
75
vendor/github.com/containerd/go-runc/console.go
generated
vendored
@@ -10,7 +10,7 @@ import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/containerd/console"
|
||||
"github.com/opencontainers/runc/libcontainer/utils"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// NewConsoleSocket creates a new unix socket at the provided path to accept a
|
||||
@@ -20,13 +20,16 @@ func NewConsoleSocket(path string) (*Socket, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
l, err := net.Listen("unix", abs)
|
||||
addr, err := net.ResolveUnixAddr("unix", abs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
l, err := net.ListenUnix("unix", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Socket{
|
||||
l: l,
|
||||
path: abs,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -41,27 +44,73 @@ func NewTempConsoleSocket() (*Socket, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
l, err := net.Listen("unix", abs)
|
||||
addr, err := net.ResolveUnixAddr("unix", abs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
l, err := net.ListenUnix("unix", addr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &Socket{
|
||||
l: l,
|
||||
rmdir: true,
|
||||
path: abs,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Socket is a unix socket that accepts the pty master created by runc
|
||||
type Socket struct {
|
||||
path string
|
||||
rmdir bool
|
||||
l net.Listener
|
||||
l *net.UnixListener
|
||||
}
|
||||
|
||||
// Path returns the path to the unix socket on disk
|
||||
func (c *Socket) Path() string {
|
||||
return c.path
|
||||
return c.l.Addr().String()
|
||||
}
|
||||
|
||||
// recvFd waits for a file descriptor to be sent over the given AF_UNIX
|
||||
// socket. The file name of the remote file descriptor will be recreated
|
||||
// locally (it is sent as non-auxiliary data in the same payload).
|
||||
func recvFd(socket *net.UnixConn) (*os.File, error) {
|
||||
const MaxNameLen = 4096
|
||||
var oobSpace = unix.CmsgSpace(4)
|
||||
|
||||
name := make([]byte, MaxNameLen)
|
||||
oob := make([]byte, oobSpace)
|
||||
|
||||
n, oobn, _, _, err := socket.ReadMsgUnix(name, oob)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if n >= MaxNameLen || oobn != oobSpace {
|
||||
return nil, fmt.Errorf("recvfd: incorrect number of bytes read (n=%d oobn=%d)", n, oobn)
|
||||
}
|
||||
|
||||
// Truncate.
|
||||
name = name[:n]
|
||||
oob = oob[:oobn]
|
||||
|
||||
scms, err := unix.ParseSocketControlMessage(oob)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(scms) != 1 {
|
||||
return nil, fmt.Errorf("recvfd: number of SCMs is not 1: %d", len(scms))
|
||||
}
|
||||
scm := scms[0]
|
||||
|
||||
fds, err := unix.ParseUnixRights(&scm)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(fds) != 1 {
|
||||
return nil, fmt.Errorf("recvfd: number of fds is not 1: %d", len(fds))
|
||||
}
|
||||
fd := uintptr(fds[0])
|
||||
|
||||
return os.NewFile(fd, string(name)), nil
|
||||
}
|
||||
|
||||
// ReceiveMaster blocks until the socket receives the pty master
|
||||
@@ -71,15 +120,11 @@ func (c *Socket) ReceiveMaster() (console.Console, error) {
|
||||
return nil, err
|
||||
}
|
||||
defer conn.Close()
|
||||
unix, ok := conn.(*net.UnixConn)
|
||||
uc, ok := conn.(*net.UnixConn)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("received connection which was not a unix socket")
|
||||
}
|
||||
sock, err := unix.File()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
f, err := utils.RecvFd(sock)
|
||||
f, err := recvFd(uc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -90,7 +135,7 @@ func (c *Socket) ReceiveMaster() (console.Console, error) {
|
||||
func (c *Socket) Close() error {
|
||||
err := c.l.Close()
|
||||
if c.rmdir {
|
||||
if rerr := os.RemoveAll(filepath.Dir(c.path)); err == nil {
|
||||
if rerr := os.RemoveAll(filepath.Dir(c.Path())); err == nil {
|
||||
err = rerr
|
||||
}
|
||||
}
|
||||
|
||||
14
vendor/github.com/containerd/go-runc/runc.go
generated
vendored
14
vendor/github.com/containerd/go-runc/runc.go
generated
vendored
@@ -523,20 +523,6 @@ func (r *Runc) args() (out []string) {
|
||||
return out
|
||||
}
|
||||
|
||||
func (r *Runc) command(context context.Context, args ...string) *exec.Cmd {
|
||||
command := r.Command
|
||||
if command == "" {
|
||||
command = DefaultCommand
|
||||
}
|
||||
cmd := exec.CommandContext(context, command, append(r.args(), args...)...)
|
||||
if r.PdeathSignal != 0 {
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
Pdeathsig: r.PdeathSignal,
|
||||
}
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
// runOrError will run the provided command. If an error is
|
||||
// encountered and neither Stdout or Stderr was set the error and the
|
||||
// stderr of the command will be returned in the format of <error>:
|
||||
|
||||
Reference in New Issue
Block a user