From 6a5809e7c43d0eba5c5d4450cfa5b9a8b5d3a0e1 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Fri, 12 Nov 2021 11:54:50 +0100 Subject: [PATCH] slightly improved error handling for wwclient --- internal/app/wwclient/root.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/app/wwclient/root.go b/internal/app/wwclient/root.go index f62ced4f..3efbae5d 100644 --- a/internal/app/wwclient/root.go +++ b/internal/app/wwclient/root.go @@ -47,6 +47,11 @@ func GetRootCommand() *cobra.Command { } func CobraRunE(cmd *cobra.Command, args []string) error { + conf, err := warewulfconf.New() + if err != nil { + return err + } + if util.IsFile(PIDFile) { return errors.New("wwclient is already running") } @@ -72,22 +77,18 @@ func CobraRunE(cmd *cobra.Command, args []string) error { err := os.MkdirAll("/warewulf/wwclient-test", 0755) if err != nil { wwlog.Printf(wwlog.ERROR, "failed to create dir: %s", err) + _ = os.Remove(PIDFile) os.Exit(1) } err = os.Chdir("/warewulf/wwclient-test") if err != nil { wwlog.Printf(wwlog.ERROR, "failed to change dir: %s", err) + _ = os.Remove(PIDFile) os.Exit(1) } } - conf, err := warewulfconf.New() - if err != nil { - wwlog.Printf(wwlog.ERROR, "Could not get Warewulf configuration: %s\n", err) - os.Exit(1) - } - localTCPAddr := net.TCPAddr{} if conf.Warewulf.Secure { // Setup local port to something privileged (<1024)