From 0c78dacbc5c8b1c02ae3f7e30be5ed170bee4d4b Mon Sep 17 00:00:00 2001 From: Phil Estes Date: Wed, 25 Mar 2020 10:42:52 -0400 Subject: [PATCH] Move isFifo from process/io to sys/ and make public Make "IsFifo" a public function for use by other parts of containerd codebase. Signed-off-by: Phil Estes --- pkg/process/io.go | 19 ++----------------- sys/filesys.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 17 deletions(-) create mode 100644 sys/filesys.go diff --git a/pkg/process/io.go b/pkg/process/io.go index 28a94a5ec..d315f44ea 100644 --- a/pkg/process/io.go +++ b/pkg/process/io.go @@ -33,6 +33,7 @@ import ( "github.com/containerd/containerd/log" "github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/pkg/stdio" + "github.com/containerd/containerd/sys" "github.com/containerd/fifo" runc "github.com/containerd/go-runc" "github.com/pkg/errors" @@ -174,7 +175,7 @@ func copyPipes(ctx context.Context, rio runc.IO, stdin, stdout, stderr string, w }, }, } { - ok, err := isFifo(i.name) + ok, err := sys.IsFifo(i.name) if err != nil { return err } @@ -240,22 +241,6 @@ func (c *countingWriteCloser) Close() error { return c.WriteCloser.Close() } -// isFifo checks if a file is a fifo -// if the file does not exist then it returns false -func isFifo(path string) (bool, error) { - stat, err := os.Stat(path) - if err != nil { - if os.IsNotExist(err) { - return false, nil - } - return false, err - } - if stat.Mode()&os.ModeNamedPipe == os.ModeNamedPipe { - return true, nil - } - return false, nil -} - // NewBinaryIO runs a custom binary process for pluggable shim logging func NewBinaryIO(ctx context.Context, id string, uri *url.URL) (runc.IO, error) { ns, err := namespaces.NamespaceRequired(ctx) diff --git a/sys/filesys.go b/sys/filesys.go new file mode 100644 index 000000000..825d21d19 --- /dev/null +++ b/sys/filesys.go @@ -0,0 +1,35 @@ +/* + 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 sys + +import "os" + +// IsFifo checks if a file is a (named pipe) fifo +// if the file does not exist then it returns false +func IsFifo(path string) (bool, error) { + stat, err := os.Stat(path) + if err != nil { + if os.IsNotExist(err) { + return false, nil + } + return false, err + } + if stat.Mode()&os.ModeNamedPipe == os.ModeNamedPipe { + return true, nil + } + return false, nil +}