From 85b106fd29de9beecf4b7a0915a0914b8411f689 Mon Sep 17 00:00:00 2001 From: Mark Vainomaa Date: Fri, 5 May 2023 11:59:27 +0300 Subject: [PATCH] Implement global debug support for client --- cmd/syringe/update_linux.go | 11 +++++++++++ internal/dbus/syringe.go | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/cmd/syringe/update_linux.go b/cmd/syringe/update_linux.go index 0ab606b..1b3ea0e 100644 --- a/cmd/syringe/update_linux.go +++ b/cmd/syringe/update_linux.go @@ -30,6 +30,17 @@ func updateEntrypoint(clictx *cli.Context) (err error) { runtime.GOMAXPROCS(1) ctx := clictx.Context + // Reconfigure logger according to debug value via dbus service + // We need dbus service to be available in update mode anyway + if debug, derr := dbus.GetGlobalDebug(ctx); derr != nil { + zap.L().Debug("unable to get global debug flag", zap.Error(err)) + } if debug && !(clictx.Bool("debug") || clictx.Bool("global-debug")) { + if err = setupLogging(true); err != nil { + return + } + zap.L().Debug("global debugging enabled") + } + if os.Getuid() != 0 && os.Geteuid() != 0 { zap.L().Error("effective uid is not 0, very likely unable to update credentials", zap.Int("uid", os.Getuid()), zap.Int("euid", os.Geteuid())) } diff --git a/internal/dbus/syringe.go b/internal/dbus/syringe.go index 3cd439d..9889cfc 100644 --- a/internal/dbus/syringe.go +++ b/internal/dbus/syringe.go @@ -33,3 +33,24 @@ func GetServiceSocketPaths(ctx context.Context) (socketPaths map[string]bool, er return } + +func GetGlobalDebug(ctx context.Context) (debug bool, err error) { + var conn *dbus.Conn + + if conn, err = dbus.ConnectSystemBus(); err != nil { + err = fmt.Errorf("failed to establish dbus connection: %w", err) + return + } + defer conn.Close() + + var globalDebugValue dbus.Variant + obj := conn.Object(intf, objPath) + err = obj.CallWithContext(ctx, "ee.zentria.syringe1.Syringe.GetGlobalDebug", 0).Store(&globalDebugValue) + if err != nil { + err = fmt.Errorf("failed to call GetGlobalDebug: %w", err) + return + } + + debug = globalDebugValue.Value().(bool) + return +}