diff options
| author | Ophestra Umiker <cat@ophivana.moe> | 2024-09-08 13:19:48 +0900 |
|---|---|---|
| committer | Ophestra Umiker <cat@ophivana.moe> | 2024-09-08 13:19:48 +0900 |
| commit | 83af555c9775e91990a87aff6a7afda8970b60f1 (patch) | |
| tree | b4b2cf5cfc1bc7704951fb00f1a759a8fb248a28 /internal/state/track.go | |
| parent | 60e48465423ded979dfe8cbb09b5635d6ee2802b (diff) | |
state/print: collect and output state information of all users
The -state flag now outputs state of all users. The old behaviour can be accessed via the -state-current flag, user is selected via -u.
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'internal/state/track.go')
| -rw-r--r-- | internal/state/track.go | 59 |
1 files changed, 1 insertions, 58 deletions
diff --git a/internal/state/track.go b/internal/state/track.go index 96e9353d..198abebf 100644 --- a/internal/state/track.go +++ b/internal/state/track.go @@ -3,15 +3,11 @@ package state import ( "encoding/gob" "errors" - "flag" - "fmt" "io/fs" "os" "os/exec" "path" "strconv" - "strings" - "text/tabwriter" "git.ophivana.moe/cat/fortify/internal/system" ) @@ -20,11 +16,7 @@ import ( // this and launcher should eventually be replaced by a server process var ( - stateActionEarly bool - statePath string - cleanupCandidate []string - xcbActionComplete bool - enablements *Enablements + statePath string ) type launcherState struct { @@ -35,55 +27,6 @@ type launcherState struct { Capability Enablements } -func init() { - flag.BoolVar(&stateActionEarly, "state", false, "query state value of current active launchers") -} - -func Early() { - if !stateActionEarly { - return - } - - launchers, err := readLaunchers(u.Uid) - if err != nil { - fmt.Println("Error reading launchers:", err) - os.Exit(1) - } - - stdout := tabwriter.NewWriter(os.Stdout, 0, 1, 4, ' ', 0) - if !system.V.Verbose { - _, _ = fmt.Fprintln(stdout, "\tPID\tEnablements\tLauncher\tCommand") - } else { - _, _ = fmt.Fprintln(stdout, "\tPID\tArgv") - } - - for _, state := range launchers { - enablementsDescription := strings.Builder{} - for i := Enablement(0); i < enableLength; i++ { - if state.Capability.Has(i) { - enablementsDescription.WriteString(", " + i.String()) - } - } - if enablementsDescription.Len() == 0 { - enablementsDescription.WriteString("none") - } - - if !system.V.Verbose { - _, _ = fmt.Fprintf(stdout, "\t%d\t%s\t%s\t%s\n", - state.PID, strings.TrimPrefix(enablementsDescription.String(), ", "), state.Launcher, - state.Command) - } else { - _, _ = fmt.Fprintf(stdout, "\t%d\t%s\n", - state.PID, state.Argv) - } - } - if err = stdout.Flush(); err != nil { - fmt.Println("warn: error formatting output:", err) - } - - os.Exit(0) -} - // SaveProcess called after process start, before wait func SaveProcess(uid string, cmd *exec.Cmd) error { statePath = path.Join(system.V.RunDir, uid, strconv.Itoa(cmd.Process.Pid)) |
