From 55bb348d5f49b3089b3475e20ee04a81f676e803 Mon Sep 17 00:00:00 2001 From: Ophestra Umiker Date: Fri, 18 Oct 2024 22:25:09 +0900 Subject: [PATCH] state: store launch method instead of launcher path Launcher path is constant for each launch method on the same system. Signed-off-by: Ophestra Umiker --- internal/app/seal.go | 9 +++++++-- internal/app/start.go | 2 +- internal/state/print.go | 4 ++-- internal/state/state.go | 4 ++-- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/internal/app/seal.go b/internal/app/seal.go index f8031b7..9fd6dfb 100644 --- a/internal/app/seal.go +++ b/internal/app/seal.go @@ -21,6 +21,11 @@ const ( LaunchMethodMachineCtl ) +var method = [...]string{ + LaunchMethodSudo: "sudo", + LaunchMethodMachineCtl: "systemd", +} + var ( ErrConfig = errors.New("no configuration to seal") ErrUser = errors.New("unknown user") @@ -65,7 +70,7 @@ func (a *app) Seal(config *Config) error { // parses launch method text and looks up tool path switch config.Method { - case "sudo": + case method[LaunchMethodSudo]: seal.launchOption = LaunchMethodSudo if sudoPath, err := exec.LookPath("sudo"); err != nil { return fmsg.WrapError(ErrSudo, @@ -73,7 +78,7 @@ func (a *app) Seal(config *Config) error { } else { seal.toolPath = sudoPath } - case "systemd": + case method[LaunchMethodMachineCtl]: seal.launchOption = LaunchMethodMachineCtl if !internal.SdBootedV { return fmsg.WrapError(ErrSystemd, diff --git a/internal/app/start.go b/internal/app/start.go index ff65c0d..a0d2906 100644 --- a/internal/app/start.go +++ b/internal/app/start.go @@ -94,7 +94,7 @@ func (a *app) Start() error { PID: a.cmd.Process.Pid, Command: a.seal.command, Capability: a.seal.et, - Launcher: a.seal.toolPath, + Method: method[a.seal.launchOption], Argv: a.cmd.Args, Time: startTime, } diff --git a/internal/state/print.go b/internal/state/print.go index fbd0110..9859cb7 100644 --- a/internal/state/print.go +++ b/internal/state/print.go @@ -68,7 +68,7 @@ func (s *simpleStore) mustPrintLauncherState(w **tabwriter.Writer, now time.Time // write header when initialising if !verbose.Get() { - _, _ = fmt.Fprintln(*w, "\tUID\tPID\tUptime\tEnablements\tLauncher\tCommand") + _, _ = fmt.Fprintln(*w, "\tUID\tPID\tUptime\tEnablements\tMethod\tCommand") } else { // argv is emitted in body when verbose _, _ = fmt.Fprintln(*w, "\tUID\tPID\tArgv") @@ -98,7 +98,7 @@ func (s *simpleStore) mustPrintLauncherState(w **tabwriter.Writer, now time.Time if !verbose.Get() { _, _ = fmt.Fprintf(*w, "\t%s\t%d\t%s\t%s\t%s\t%s\n", - s.path[len(s.path)-1], state.PID, now.Sub(state.Time).Round(time.Second).String(), strings.TrimPrefix(ets.String(), ", "), state.Launcher, + s.path[len(s.path)-1], state.PID, now.Sub(state.Time).Round(time.Second).String(), strings.TrimPrefix(ets.String(), ", "), state.Method, state.Command) } else { // emit argv instead when verbose diff --git a/internal/state/state.go b/internal/state/state.go index bc2be69..dde43f7 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -33,8 +33,8 @@ type State struct { // capability enablements applied to child Capability system.Enablements - // resolved launcher path - Launcher string + // user switch method + Method string // full argv whe launching Argv []string // process start time