Skip to content

Commit

Permalink
Implement global debug support for client
Browse files Browse the repository at this point in the history
  • Loading branch information
mikroskeem committed May 5, 2023
1 parent 83cf534 commit 85b106f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions cmd/syringe/update_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
Expand Down
21 changes: 21 additions & 0 deletions internal/dbus/syringe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 85b106f

Please sign in to comment.