From 81f4f07ed76ce10ff58981d60d517ae5f905ad1b Mon Sep 17 00:00:00 2001 From: Mahmood Ali Date: Mon, 1 Apr 2019 15:56:43 -0400 Subject: [PATCH] rename fifo methods for clarity --- client/lib/fifo/fifo_test.go | 8 ++++---- client/lib/fifo/fifo_unix.go | 8 ++++---- client/lib/fifo/fifo_windows.go | 6 +++--- client/logmon/logmon.go | 2 +- client/logmon/logmon_test.go | 14 +++++++------- drivers/docker/docklog/docker_logger.go | 4 ++-- drivers/mock/handle.go | 4 ++-- drivers/shared/executor/executor.go | 4 ++-- 8 files changed, 25 insertions(+), 25 deletions(-) diff --git a/client/lib/fifo/fifo_test.go b/client/lib/fifo/fifo_test.go index 05d678563..632fbbffc 100644 --- a/client/lib/fifo/fifo_test.go +++ b/client/lib/fifo/fifo_test.go @@ -31,7 +31,7 @@ func TestFIFO(t *testing.T) { path = filepath.Join(dir, "fifo") } - readerOpenFn, err := New(path) + readerOpenFn, err := CreateAndRead(path) require.NoError(err) var reader io.ReadCloser @@ -60,7 +60,7 @@ func TestFIFO(t *testing.T) { assert.NoError(t, err) }() - writer, err := Open(path) + writer, err := OpenWriter(path) require.NoError(err) for _, b := range toWrite { n, err := writer.Write(b) @@ -94,7 +94,7 @@ func TestWriteClose(t *testing.T) { path = filepath.Join(dir, "fifo") } - readerOpenFn, err := New(path) + readerOpenFn, err := CreateAndRead(path) require.NoError(err) var reader io.ReadCloser @@ -114,7 +114,7 @@ func TestWriteClose(t *testing.T) { assert.NoError(t, err) }() - writer, err := Open(path) + writer, err := OpenWriter(path) require.NoError(err) var count int diff --git a/client/lib/fifo/fifo_unix.go b/client/lib/fifo/fifo_unix.go index 47188a9bd..4d902fb03 100644 --- a/client/lib/fifo/fifo_unix.go +++ b/client/lib/fifo/fifo_unix.go @@ -10,12 +10,12 @@ import ( "golang.org/x/sys/unix" ) -// New creates a fifo at the given path, and returns an open function for reading. +// CreateAndRead creates a fifo at the given path, and returns an open function for reading. // The fifo must not exist already, or that it's already a fifo file // // It returns a reader open function that may block until a writer opens // so it's advised to run it in a goroutine different from reader goroutine -func New(path string) (func() (io.ReadCloser, error), error) { +func CreateAndRead(path string) (func() (io.ReadCloser, error), error) { // create first if err := mkfifo(path, 0600); err != nil && !os.IsExist(err) { return nil, fmt.Errorf("error creating fifo %v: %v", path, err) @@ -28,8 +28,8 @@ func New(path string) (func() (io.ReadCloser, error), error) { return openFn, nil } -// Open opens a fifo file for reading, assuming it already exists, returns io.WriteCloser -func Open(path string) (io.WriteCloser, error) { +// OpenWriter opens a fifo file for writer, assuming it already exists, returns io.WriteCloser +func OpenWriter(path string) (io.WriteCloser, error) { return os.OpenFile(path, unix.O_WRONLY, os.ModeNamedPipe) } diff --git a/client/lib/fifo/fifo_windows.go b/client/lib/fifo/fifo_windows.go index b717dba4b..24d9c1e42 100644 --- a/client/lib/fifo/fifo_windows.go +++ b/client/lib/fifo/fifo_windows.go @@ -67,9 +67,9 @@ func (f *winFIFO) Close() error { return f.listener.Close() } -// New creates a fifo at the given path and returns an io.ReadCloser open for it. +// CreateAndRead creates a fifo at the given path and returns an io.ReadCloser open for it. // The fifo must not already exist -func New(path string) (func() (io.ReadCloser, error), error) { +func CreateAndRead(path string) (func() (io.ReadCloser, error), error) { l, err := winio.ListenPipe(path, &winio.PipeConfig{ InputBufferSize: PipeBufferSize, OutputBufferSize: PipeBufferSize, @@ -88,7 +88,7 @@ func New(path string) (func() (io.ReadCloser, error), error) { } // OpenWriter opens a fifo that already exists and returns an io.WriteCloser for it -func Open(path string) (io.WriteCloser, error) { +func OpenWriter(path string) (io.WriteCloser, error) { return winio.DialPipe(path, nil) } diff --git a/client/logmon/logmon.go b/client/logmon/logmon.go index a248dcf27..74a13631d 100644 --- a/client/logmon/logmon.go +++ b/client/logmon/logmon.go @@ -199,7 +199,7 @@ func (l *logRotatorWrapper) isRunning() bool { // processOutWriter to attach to the stdout or stderr of a process. func newLogRotatorWrapper(path string, logger hclog.Logger, rotator *logging.FileRotator) (*logRotatorWrapper, error) { logger.Info("opening fifo", "path", path) - fifoOpenFn, err := fifo.New(path) + fifoOpenFn, err := fifo.CreateAndRead(path) if err != nil { return nil, fmt.Errorf("failed to create fifo for extracting logs: %v", err) } diff --git a/client/logmon/logmon_test.go b/client/logmon/logmon_test.go index 1692e7a08..609b3db6e 100644 --- a/client/logmon/logmon_test.go +++ b/client/logmon/logmon_test.go @@ -37,7 +37,7 @@ func TestLogmon_Start_rotate(t *testing.T) { lm := NewLogMon(testlog.HCLogger(t)) require.NoError(lm.Start(cfg)) - stdout, err := fifo.Open(stdoutFifoPath) + stdout, err := fifo.OpenWriter(stdoutFifoPath) require.NoError(err) // Write enough bytes such that the log is rotated @@ -92,9 +92,9 @@ func TestLogmon_Start_restart(t *testing.T) { require.True(ok) require.NoError(lm.Start(cfg)) - stdout, err := fifo.Open(stdoutFifoPath) + stdout, err := fifo.OpenWriter(stdoutFifoPath) require.NoError(err) - stderr, err := fifo.Open(stderrFifoPath) + stderr, err := fifo.OpenWriter(stderrFifoPath) require.NoError(err) // Write a string and assert it was written to the file @@ -122,9 +122,9 @@ func TestLogmon_Start_restart(t *testing.T) { require.NoError(err) }) - stdout, err = fifo.Open(stdoutFifoPath) + stdout, err = fifo.OpenWriter(stdoutFifoPath) require.NoError(err) - stderr, err = fifo.Open(stderrFifoPath) + stderr, err = fifo.OpenWriter(stderrFifoPath) require.NoError(err) _, err = stdout.Write([]byte("te")) @@ -143,9 +143,9 @@ func TestLogmon_Start_restart(t *testing.T) { // Start logmon again and assert that it appended to the file require.NoError(lm.Start(cfg)) - stdout, err = fifo.Open(stdoutFifoPath) + stdout, err = fifo.OpenWriter(stdoutFifoPath) require.NoError(err) - stderr, err = fifo.Open(stderrFifoPath) + stderr, err = fifo.OpenWriter(stderrFifoPath) require.NoError(err) _, err = stdout.Write([]byte("st\n")) diff --git a/drivers/docker/docklog/docker_logger.go b/drivers/docker/docklog/docker_logger.go index 3d1e83dfd..0567a5e5f 100644 --- a/drivers/docker/docklog/docker_logger.go +++ b/drivers/docker/docklog/docker_logger.go @@ -71,14 +71,14 @@ func (d *dockerLogger) Start(opts *StartOpts) error { } if d.stdout == nil { - stdout, err := fifo.Open(opts.Stdout) + stdout, err := fifo.OpenWriter(opts.Stdout) if err != nil { return fmt.Errorf("failed to open fifo for path %s: %v", opts.Stdout, err) } d.stdout = stdout } if d.stderr == nil { - stderr, err := fifo.Open(opts.Stderr) + stderr, err := fifo.OpenWriter(opts.Stderr) if err != nil { return fmt.Errorf("failed to open fifo for path %s: %v", opts.Stdout, err) } diff --git a/drivers/mock/handle.go b/drivers/mock/handle.go index 81d204d9d..7940a6283 100644 --- a/drivers/mock/handle.go +++ b/drivers/mock/handle.go @@ -125,13 +125,13 @@ func (h *taskHandle) run() { } func (h *taskHandle) handleLogging(errCh chan<- error) { - stdout, err := fifo.Open(h.taskConfig.StdoutPath) + stdout, err := fifo.OpenWriter(h.taskConfig.StdoutPath) if err != nil { h.logger.Error("failed to write to stdout", "error", err) errCh <- err return } - stderr, err := fifo.Open(h.taskConfig.StderrPath) + stderr, err := fifo.OpenWriter(h.taskConfig.StderrPath) if err != nil { h.logger.Error("failed to write to stderr", "error", err) errCh <- err diff --git a/drivers/shared/executor/executor.go b/drivers/shared/executor/executor.go index 2bd32dc48..ced883f58 100644 --- a/drivers/shared/executor/executor.go +++ b/drivers/shared/executor/executor.go @@ -148,7 +148,7 @@ func (nopCloser) Close() error { return nil } func (c *ExecCommand) Stdout() (io.WriteCloser, error) { if c.stdout == nil { if c.StdoutPath != "" { - f, err := fifo.Open(c.StdoutPath) + f, err := fifo.OpenWriter(c.StdoutPath) if err != nil { return nil, fmt.Errorf("failed to create stdout: %v", err) } @@ -164,7 +164,7 @@ func (c *ExecCommand) Stdout() (io.WriteCloser, error) { func (c *ExecCommand) Stderr() (io.WriteCloser, error) { if c.stderr == nil { if c.StderrPath != "" { - f, err := fifo.Open(c.StderrPath) + f, err := fifo.OpenWriter(c.StderrPath) if err != nil { return nil, fmt.Errorf("failed to create stderr: %v", err) }