From 21ec543d373f4245d000a1bf16356a4174510173 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Mon, 31 Oct 2022 10:37:42 +0100 Subject: [PATCH] Give user better feedback if headscale socket is unwritable Signed-off-by: Kristoffer Dalby --- cmd/headscale/cli/utils.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cmd/headscale/cli/utils.go b/cmd/headscale/cli/utils.go index ae89c4fe..c42f3c6a 100644 --- a/cmd/headscale/cli/utils.go +++ b/cmd/headscale/cli/utils.go @@ -81,6 +81,19 @@ func getHeadscaleCLIClient() (context.Context, v1.HeadscaleServiceClient, *grpc. address = cfg.UnixSocket + // Try to give the user better feedback if we cannot write to the headscale + // socket. + socket, err := os.OpenFile(cfg.UnixSocket, os.O_WRONLY, 0o666) + if err != nil { + if os.IsPermission(err) { + log.Fatal(). + Err(err). + Str("socket", cfg.UnixSocket). + Msgf("Unable to read/write to headscale socket, do you have the correct permissions?") + } + } + socket.Close() + grpcOptions = append( grpcOptions, grpc.WithTransportCredentials(insecure.NewCredentials()),