From 50127ed5f9bc89f38c7d5d1aa06b4d99229b9c64 Mon Sep 17 00:00:00 2001 From: Ophestra Date: Mon, 7 Apr 2025 21:55:07 +0900 Subject: [PATCH] fortify: print synthesised id in ps This is not the full synthesised id so it does not get too long. Signed-off-by: Ophestra --- print.go | 6 ++++-- print_test.go | 16 ++++++++-------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/print.go b/print.go index 923bd04..a1a2970 100644 --- a/print.go +++ b/print.go @@ -265,9 +265,11 @@ func printPs(output io.Writer, now time.Time, s state.Store, short, flagJSON boo as := "(No configuration information)" if e.Config != nil { as = strconv.Itoa(e.Config.Confinement.AppID) - if e.Config.ID != "" { - as += " (" + e.Config.ID + ")" + id := e.Config.ID + if id == "" { + id = "uk.gensokyo.fortify." + e.s[:8] } + as += " (" + id + ")" } t.Printf("\t%s\t%d\t%s\t%s\n", e.s[:8], e.PID, as, now.Sub(e.Time).Round(time.Second).String()) diff --git a/print_test.go b/print_test.go index b2e5998..ee9a79f 100644 --- a/print_test.go +++ b/print_test.go @@ -454,19 +454,19 @@ func Test_printPs(t *testing.T) { short, json bool want string }{ - {"no entries", make(state.Entries), false, false, ` Instance PID Application Uptime -`}, - {"no entries short", make(state.Entries), true, false, ``}, - {"nil instance", state.Entries{testID: nil}, false, false, ` Instance PID Application Uptime -`}, - {"state corruption", state.Entries{fst.ID{}: testState}, false, false, ` Instance PID Application Uptime + {"no entries", make(state.Entries), false, false, " Instance PID Application Uptime\n"}, + {"no entries short", make(state.Entries), true, false, ""}, + {"nil instance", state.Entries{testID: nil}, false, false, " Instance PID Application Uptime\n"}, + {"state corruption", state.Entries{fst.ID{}: testState}, false, false, " Instance PID Application Uptime\n"}, + + {"valid pd", state.Entries{testID: &state.State{ID: testID, PID: 1 << 8, Config: new(fst.Config), Time: testAppTime}}, false, false, ` Instance PID Application Uptime + 8e2c76b0 256 0 (uk.gensokyo.fortify.8e2c76b0) 1h2m32s `}, {"valid", state.Entries{testID: testState}, false, false, ` Instance PID Application Uptime 8e2c76b0 3735928559 9 (org.chromium.Chromium) 1h2m32s `}, - {"valid short", state.Entries{testID: testState}, true, false, `8e2c76b0 -`}, + {"valid short", state.Entries{testID: testState}, true, false, "8e2c76b0\n"}, {"valid json", state.Entries{testID: testState}, false, true, `{ "8e2c76b066dabe574cf073bdb46eb5c1": { "instance": [