From d7deba03a2c966d3cb940ca619b2b5c07a9c2411 Mon Sep 17 00:00:00 2001 From: Ian Campbell Date: Wed, 24 May 2017 15:24:44 +0100 Subject: [PATCH] prepareStdio: use named return for err This avoids issues with the various deferred error handlers in the event that `err` is shadowed or named differently, which this function currently avoids but which is an easy trap to fall into. Since named return values are all or nothing we need to name the waitGroup too and adjust the code to suite. Thanks to Aaron Lehmann for the suggestion, see also https://github.com/docker/swarmkit/pull/1965#discussion_r118137410 Signed-off-by: Ian Campbell --- cmd/ctr/utils_unix.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/ctr/utils_unix.go b/cmd/ctr/utils_unix.go index e3d98a57e..b7430af52 100644 --- a/cmd/ctr/utils_unix.go +++ b/cmd/ctr/utils_unix.go @@ -21,8 +21,8 @@ import ( "google.golang.org/grpc/grpclog" ) -func prepareStdio(stdin, stdout, stderr string, console bool) (*sync.WaitGroup, error) { - var wg sync.WaitGroup +func prepareStdio(stdin, stdout, stderr string, console bool) (wg *sync.WaitGroup, err error) { + wg = &sync.WaitGroup{} ctx := gocontext.Background() f, err := fifo.OpenFifo(ctx, stdin, syscall.O_WRONLY|syscall.O_CREAT|syscall.O_NONBLOCK, 0700) @@ -73,7 +73,7 @@ func prepareStdio(stdin, stdout, stderr string, console bool) (*sync.WaitGroup, }(f) } - return &wg, nil + return wg, nil } func getGRPCConnection(context *cli.Context) (*grpc.ClientConn, error) {