Skip to content

Commit

Permalink
Set os.ModePerm permission for unix sockets (#1320)
Browse files Browse the repository at this point in the history
* set os.ModePerm for unix sockets

Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>

* fix TestListenAndServe_NotExistsFolder

Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>

* fix linter

Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>

* apply review comments

Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>

* apply review comments

Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>
  • Loading branch information
NikitaSkrynnik authored Jul 12, 2022
1 parent 65679c0 commit aa1bc9e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/tools/grpcutils/listen_and_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -21,6 +23,7 @@ package grpcutils

import (
"context"
"fmt"
"net"
"net/url"
"os"
Expand Down Expand Up @@ -70,6 +73,15 @@ func ListenAndServe(ctx context.Context, address *url.URL, server *grpc.Server)
*address = *AddressToURL(ln.Addr())
}

if network == unixScheme {
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))
}
}
}

// Serve
go func() {
if err != nil {
Expand Down

0 comments on commit aa1bc9e

Please sign in to comment.