diff --git a/go.mod b/go.mod index 1c5ba32..8b6a034 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,5 @@ go 1.21 require ( github.com/containerd/console v1.0.3 github.com/opencontainers/runtime-spec v1.1.0 - github.com/sirupsen/logrus v1.9.3 golang.org/x/sys v0.13.0 ) diff --git a/go.sum b/go.sum index cf78e02..3fbc3d6 100644 --- a/go.sum +++ b/go.sum @@ -1,21 +1,7 @@ github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw= github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U= -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/opencontainers/runtime-spec v1.1.0 h1:HHUyrt9mwHUjtasSbXSMvs4cyFxh+Bll4AjJ9odEGpg= github.com/opencontainers/runtime-spec v1.1.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= -github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= -github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/io_linux.go b/io_linux.go new file mode 100644 index 0000000..39ec0cb --- /dev/null +++ b/io_linux.go @@ -0,0 +1,23 @@ +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package runc + +import "golang.org/x/sys/unix" + +func chownPipe(fd, uid, gid int) error { + return unix.Fchown(fd, uid, gid) +} diff --git a/io_nolinux.go b/io_nolinux.go new file mode 100644 index 0000000..04eb062 --- /dev/null +++ b/io_nolinux.go @@ -0,0 +1,25 @@ +//go:build !linux && !windows + +/* + Copyright The containerd Authors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +*/ + +package runc + +// chownPipe is a no-op because BSD variants, including macOS, FreeBSD, +// and OpenBSD, do not support changing ownership of anonymous pipes. +func chownPipe(fd, uid, gid int) error { + return nil +} diff --git a/io_unix.go b/io_unix.go index 83e3667..76bb8d7 100644 --- a/io_unix.go +++ b/io_unix.go @@ -20,14 +20,10 @@ package runc import ( "fmt" - "runtime" - - "github.com/sirupsen/logrus" - "golang.org/x/sys/unix" ) // newPipeIO creates pipe pairs to be used with runc -func newPipeIO(uid, gid int, opts ...IOOpt) (i IO, err error) { +func newPipeIO(uid, gid int, opts ...IOOpt) (_ IO, retErr error) { option := defaultIOOption() for _, o := range opts { o(option) @@ -38,55 +34,40 @@ func newPipeIO(uid, gid int, opts ...IOOpt) (i IO, err error) { ) // cleanup in case of an error defer func() { - if err != nil { + if retErr != nil { for _, p := range pipes { - p.Close() + _ = p.Close() } } }() if option.OpenStdin { + var err error if stdin, err = newPipe(); err != nil { return nil, err } pipes = append(pipes, stdin) - if err = unix.Fchown(int(stdin.r.Fd()), uid, gid); err != nil { - // TODO: revert with proper darwin solution, skipping for now - // as darwin chown is returning EINVAL on anonymous pipe - if runtime.GOOS == "darwin" { - logrus.WithError(err).Debug("failed to chown stdin, ignored") - } else { - return nil, fmt.Errorf("failed to chown stdin: %w", err) - } + if err := chownPipe(int(stdin.r.Fd()), uid, gid); err != nil { + return nil, fmt.Errorf("failed to chown stdin: %w", err) } } if option.OpenStdout { + var err error if stdout, err = newPipe(); err != nil { return nil, err } pipes = append(pipes, stdout) - if err = unix.Fchown(int(stdout.w.Fd()), uid, gid); err != nil { - // TODO: revert with proper darwin solution, skipping for now - // as darwin chown is returning EINVAL on anonymous pipe - if runtime.GOOS == "darwin" { - logrus.WithError(err).Debug("failed to chown stdout, ignored") - } else { - return nil, fmt.Errorf("failed to chown stdout: %w", err) - } + if err := chownPipe(int(stdout.w.Fd()), uid, gid); err != nil { + return nil, fmt.Errorf("failed to chown stdout: %w", err) } } if option.OpenStderr { + var err error if stderr, err = newPipe(); err != nil { return nil, err } pipes = append(pipes, stderr) - if err = unix.Fchown(int(stderr.w.Fd()), uid, gid); err != nil { - // TODO: revert with proper darwin solution, skipping for now - // as darwin chown is returning EINVAL on anonymous pipe - if runtime.GOOS == "darwin" { - logrus.WithError(err).Debug("failed to chown stderr, ignored") - } else { - return nil, fmt.Errorf("failed to chown stderr: %w", err) - } + if err := chownPipe(int(stderr.w.Fd()), uid, gid); err != nil { + return nil, fmt.Errorf("failed to chown stderr: %w", err) } } return &pipeIO{