linux: Wrap error with contextual message
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
parent
171759a233
commit
33598cc5d3
@ -20,6 +20,7 @@ import (
|
||||
"github.com/containerd/fifo"
|
||||
runc "github.com/containerd/go-runc"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type execProcess struct {
|
||||
@ -59,13 +60,13 @@ func newExecProcess(context context.Context, path string, r *shimapi.ExecRequest
|
||||
)
|
||||
if r.Terminal {
|
||||
if socket, err = runc.NewConsoleSocket(filepath.Join(path, "pty.sock")); err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "failed to create runc console socket")
|
||||
}
|
||||
defer os.Remove(socket.Path())
|
||||
} else {
|
||||
// TODO: get uid/gid
|
||||
if io, err = runc.NewPipeIO(0, 0); err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "failed to create runc io pipes")
|
||||
}
|
||||
e.io = io
|
||||
}
|
||||
@ -90,7 +91,7 @@ func newExecProcess(context context.Context, path string, r *shimapi.ExecRequest
|
||||
if r.Stdin != "" {
|
||||
sc, err := fifo.OpenFifo(context, r.Stdin, syscall.O_WRONLY|syscall.O_NONBLOCK, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrapf(err, "failed to open stdin fifo %s", r.Stdin)
|
||||
}
|
||||
e.closers = append(e.closers, sc)
|
||||
e.stdin = sc
|
||||
@ -99,21 +100,21 @@ func newExecProcess(context context.Context, path string, r *shimapi.ExecRequest
|
||||
if socket != nil {
|
||||
console, err := socket.ReceiveMaster()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "failed to retrieve console master")
|
||||
}
|
||||
e.console = console
|
||||
if err := copyConsole(context, console, r.Stdin, r.Stdout, r.Stderr, &e.WaitGroup, ©WaitGroup); err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "failed to start console copy")
|
||||
}
|
||||
} else {
|
||||
if err := copyPipes(context, io, r.Stdin, r.Stdout, r.Stderr, &e.WaitGroup, ©WaitGroup); err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "failed to start io pipe copy")
|
||||
}
|
||||
}
|
||||
copyWaitGroup.Wait()
|
||||
pid, err := runc.ReadPidFile(opts.PidFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "failed to retrieve runc exec pid")
|
||||
}
|
||||
e.pid = pid
|
||||
return e, nil
|
||||
|
@ -21,6 +21,7 @@ import (
|
||||
"github.com/containerd/containerd/mount"
|
||||
"github.com/containerd/fifo"
|
||||
runc "github.com/containerd/go-runc"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
type initProcess struct {
|
||||
@ -57,7 +58,7 @@ func newInitProcess(context context.Context, path, namespace string, r *shimapi.
|
||||
Options: rm.Options,
|
||||
}
|
||||
if err := m.Mount(filepath.Join(path, "rootfs")); err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrapf(err, "failed to mount rootfs component %v", m)
|
||||
}
|
||||
}
|
||||
runtime := &runc.Runc{
|
||||
@ -83,13 +84,13 @@ func newInitProcess(context context.Context, path, namespace string, r *shimapi.
|
||||
)
|
||||
if r.Terminal {
|
||||
if socket, err = runc.NewConsoleSocket(filepath.Join(path, "pty.sock")); err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "failed to create runc console socket")
|
||||
}
|
||||
defer os.Remove(socket.Path())
|
||||
} else {
|
||||
// TODO: get uid/gid
|
||||
if io, err = runc.NewPipeIO(0, 0); err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "failed to create runc io pipes")
|
||||
}
|
||||
p.io = io
|
||||
}
|
||||
@ -126,7 +127,7 @@ func newInitProcess(context context.Context, path, namespace string, r *shimapi.
|
||||
if r.Stdin != "" {
|
||||
sc, err := fifo.OpenFifo(context, r.Stdin, syscall.O_WRONLY|syscall.O_NONBLOCK, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrapf(err, "failed to open stdin fifo %s", r.Stdin)
|
||||
}
|
||||
p.stdin = sc
|
||||
p.closers = append(p.closers, sc)
|
||||
@ -135,22 +136,22 @@ func newInitProcess(context context.Context, path, namespace string, r *shimapi.
|
||||
if socket != nil {
|
||||
console, err := socket.ReceiveMaster()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "failed to retrieve console master")
|
||||
}
|
||||
p.console = console
|
||||
if err := copyConsole(context, console, r.Stdin, r.Stdout, r.Stderr, &p.WaitGroup, ©WaitGroup); err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "failed to start console copy")
|
||||
}
|
||||
} else {
|
||||
if err := copyPipes(context, io, r.Stdin, r.Stdout, r.Stderr, &p.WaitGroup, ©WaitGroup); err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "failed to start io pipe copy")
|
||||
}
|
||||
}
|
||||
|
||||
copyWaitGroup.Wait()
|
||||
pid, err := runc.ReadPidFile(pidFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "failed to retrieve runc container pid")
|
||||
}
|
||||
p.pid = pid
|
||||
return p, nil
|
||||
|
@ -23,6 +23,7 @@ import (
|
||||
protobuf "github.com/gogo/protobuf/types"
|
||||
google_protobuf "github.com/golang/protobuf/ptypes/empty"
|
||||
specs "github.com/opencontainers/image-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
@ -129,7 +130,7 @@ func (s *Service) Create(ctx context.Context, r *api.CreateRequest) (*api.Create
|
||||
}
|
||||
c, err := runtime.Create(ctx, r.ContainerID, opts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, errors.Wrap(err, "runtime create failed")
|
||||
}
|
||||
state, err := c.State(ctx)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user