From 79463c18b953d4bfc840b7b308de52de18ea3fa8 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Fri, 15 Mar 2024 00:29:08 +0300 Subject: [PATCH] main: move root and node UUID checks to setup(): to prevent log messages on 'hvpn-node --help' Signed-off-by: HeshamTB --- cmd/hvpn-node/hvpn-node.go | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/cmd/hvpn-node/hvpn-node.go b/cmd/hvpn-node/hvpn-node.go index 2663292..815bee6 100644 --- a/cmd/hvpn-node/hvpn-node.go +++ b/cmd/hvpn-node/hvpn-node.go @@ -40,21 +40,9 @@ func main() { // TODO: Define error exit codes slog.SetLogLoggerLevel(slog.LevelDebug) - uid := os.Getuid() - if uid == -1 { - slog.Warn("Running on windows! whatrr u doing?") - } else if uid == 0 { - slog.Warn("Running as root! avoid running as root by setting CAP_NET_ADMIN") - } - uuid, err := hvpnnode3.InitNodeUUID() - if err != nil { - slog.Error(err.Error()) - os.Exit(-1) - } - slog.Info("Node UUID: " + uuid.String()) app := createCliApp() - err = app.Run(os.Args) + err := app.Run(os.Args) if err != nil { slog.Error(err.Error()) os.Exit(1) @@ -195,6 +183,19 @@ func createCliApp() *cli.App { func setup() error { slog.Debug("Starting setup()") + uid := os.Getuid() + if uid == -1 { + slog.Warn("Running on windows! whatrr u doing?") + } else if uid == 0 { + slog.Warn("Running as root! avoid running as root by setting CAP_NET_ADMIN") + } + uuid, err := hvpnnode3.InitNodeUUID() + if err != nil { + slog.Error(err.Error()) + os.Exit(-1) + } + slog.Info("Node UUID: " + uuid.String()) + privKeyFile, err := os.Open(PrivateKeyPath) if err != nil { return cli.Exit(err, 1)