From b5a34a8a941fd8d25d394f0cff7e36a80fddfd35 Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik Date: Thu, 7 Jul 2022 21:22:23 +1100 Subject: [PATCH 1/5] set os.ModePerm for unix sockets Signed-off-by: Nikita Skrynnik --- pkg/tools/grpcutils/listen_and_serve.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/tools/grpcutils/listen_and_serve.go b/pkg/tools/grpcutils/listen_and_serve.go index 375b2f118..3f8bfc8a8 100644 --- a/pkg/tools/grpcutils/listen_and_serve.go +++ b/pkg/tools/grpcutils/listen_and_serve.go @@ -21,6 +21,7 @@ package grpcutils import ( "context" + "fmt" "net" "net/url" "os" @@ -70,6 +71,13 @@ func ListenAndServe(ctx context.Context, address *url.URL, server *grpc.Server) *address = *AddressToURL(ln.Addr()) } + if network == unixScheme { + err = os.Chmod(target, os.ModePerm) + if err != nil { + errCh <- errors.Wrap(err, fmt.Sprintf("Cannot change the mode of %s", target)) + } + } + // Serve go func() { if err != nil { From b7e90cacf102e5e1fcd6f4f58b2c3e009842ebaf Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik Date: Thu, 7 Jul 2022 21:55:38 +1100 Subject: [PATCH 2/5] fix TestListenAndServe_NotExistsFolder Signed-off-by: Nikita Skrynnik --- pkg/tools/grpcutils/listen_and_serve.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/pkg/tools/grpcutils/listen_and_serve.go b/pkg/tools/grpcutils/listen_and_serve.go index 3f8bfc8a8..7b39556cb 100644 --- a/pkg/tools/grpcutils/listen_and_serve.go +++ b/pkg/tools/grpcutils/listen_and_serve.go @@ -72,9 +72,11 @@ func ListenAndServe(ctx context.Context, address *url.URL, server *grpc.Server) } if network == unixScheme { - err = os.Chmod(target, os.ModePerm) - if err != nil { - errCh <- errors.Wrap(err, fmt.Sprintf("Cannot change the mode of %s", target)) + if _, err = os.Stat(target); os.IsExist(err) { + err = os.Chmod(target, os.ModePerm) + if err != nil { + errCh <- errors.Wrap(err, fmt.Sprintf("Cannot change the mode of %s", target)) + } } } From f7250936a9962372a3275ef50e8c36130fc053ec Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik Date: Thu, 7 Jul 2022 22:00:30 +1100 Subject: [PATCH 3/5] fix linter Signed-off-by: Nikita Skrynnik --- pkg/tools/grpcutils/listen_and_serve.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/tools/grpcutils/listen_and_serve.go b/pkg/tools/grpcutils/listen_and_serve.go index 7b39556cb..b8db9f3af 100644 --- a/pkg/tools/grpcutils/listen_and_serve.go +++ b/pkg/tools/grpcutils/listen_and_serve.go @@ -2,6 +2,8 @@ // // Copyright (c) 2020-2021 Doc.ai and/or its affiliates. // +// Copyright (c) 2022 Cisco and/or its affiliates. +// // SPDX-License-Identifier: Apache-2.0 // // Licensed under the Apache License, Version 2.0 (the "License"); From 1ac4c4681f8741f74f2133859f6a012005e3a929 Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik Date: Fri, 8 Jul 2022 13:24:38 +1100 Subject: [PATCH 4/5] apply review comments Signed-off-by: Nikita Skrynnik --- pkg/tools/grpcutils/listen_and_serve.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/tools/grpcutils/listen_and_serve.go b/pkg/tools/grpcutils/listen_and_serve.go index b8db9f3af..7f75fdcb0 100644 --- a/pkg/tools/grpcutils/listen_and_serve.go +++ b/pkg/tools/grpcutils/listen_and_serve.go @@ -77,7 +77,7 @@ func ListenAndServe(ctx context.Context, address *url.URL, server *grpc.Server) if _, err = os.Stat(target); os.IsExist(err) { err = os.Chmod(target, os.ModePerm) if err != nil { - errCh <- errors.Wrap(err, fmt.Sprintf("Cannot change the mode of %s", target)) + errCh <- errors.Wrap(err, fmt.Sprintf("%v: сannot change mod", target)) } } } From 7eed14eb9f2aeb7258577b98b54a66c50b8be46f Mon Sep 17 00:00:00 2001 From: Nikita Skrynnik Date: Tue, 12 Jul 2022 14:09:35 +1100 Subject: [PATCH 5/5] apply review comments Signed-off-by: Nikita Skrynnik --- pkg/tools/grpcutils/listen_and_serve.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/tools/grpcutils/listen_and_serve.go b/pkg/tools/grpcutils/listen_and_serve.go index 7f75fdcb0..9a1b84a76 100644 --- a/pkg/tools/grpcutils/listen_and_serve.go +++ b/pkg/tools/grpcutils/listen_and_serve.go @@ -74,7 +74,7 @@ func ListenAndServe(ctx context.Context, address *url.URL, server *grpc.Server) } if network == unixScheme { - if _, err = os.Stat(target); os.IsExist(err) { + if _, err = os.Stat(target); err == nil { err = os.Chmod(target, os.ModePerm) if err != nil { errCh <- errors.Wrap(err, fmt.Sprintf("%v: сannot change mod", target))