From 8b50f0305621928a5a6950a444b96f92aadd056f Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Mon, 9 Dec 2019 12:21:45 -0800 Subject: [PATCH] Only log min and max port when connecting via TCP; move port determination inside of the TCP function --- packer/plugin/server.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/packer/plugin/server.go b/packer/plugin/server.go index 0efefb7e5..749875b75 100644 --- a/packer/plugin/server.go +++ b/packer/plugin/server.go @@ -51,20 +51,7 @@ func Server() (*packrpc.Server, error) { runtime.GOMAXPROCS(runtime.NumCPU()) } - minPort, err := strconv.ParseInt(os.Getenv("PACKER_PLUGIN_MIN_PORT"), 10, 32) - if err != nil { - return nil, err - } - - maxPort, err := strconv.ParseInt(os.Getenv("PACKER_PLUGIN_MAX_PORT"), 10, 32) - if err != nil { - return nil, err - } - - log.Printf("Plugin minimum port: %d\n", minPort) - log.Printf("Plugin maximum port: %d\n", maxPort) - - listener, err := serverListener(minPort, maxPort) + listener, err := serverListener() if err != nil { return nil, err } @@ -104,15 +91,28 @@ func Server() (*packrpc.Server, error) { return packrpc.NewServer(conn) } -func serverListener(minPort, maxPort int64) (net.Listener, error) { +func serverListener() (net.Listener, error) { if runtime.GOOS == "windows" { - return serverListener_tcp(minPort, maxPort) + return serverListener_tcp() } return serverListener_unix() } -func serverListener_tcp(minPort, maxPort int64) (net.Listener, error) { +func serverListener_tcp() (net.Listener, error) { + minPort, err := strconv.ParseInt(os.Getenv("PACKER_PLUGIN_MIN_PORT"), 10, 32) + if err != nil { + return nil, err + } + + maxPort, err := strconv.ParseInt(os.Getenv("PACKER_PLUGIN_MAX_PORT"), 10, 32) + if err != nil { + return nil, err + } + + log.Printf("Plugin minimum port: %d/%d\n", minPort) + log.Printf("Plugin maximum port: %d/%d\n", maxPort) + for port := minPort; port <= maxPort; port++ { address := fmt.Sprintf("127.0.0.1:%d", port) listener, err := net.Listen("tcp", address)