From 0a382953b34cdc4c7fd98ab22eca2f04bc7bc07b Mon Sep 17 00:00:00 2001 From: "dean.lu" Date: Thu, 5 May 2022 15:29:58 +0800 Subject: [PATCH 1/2] Add "PID" and "type" fields --- host/host.go | 2 ++ host/host_darwin.go | 2 ++ host/host_freebsd.go | 2 ++ host/host_linux.go | 2 ++ host/host_openbsd.go | 2 ++ 5 files changed, 10 insertions(+) diff --git a/host/host.go b/host/host.go index 7c53e2084..355862699 100644 --- a/host/host.go +++ b/host/host.go @@ -36,6 +36,8 @@ type UserStat struct { Terminal string `json:"terminal"` Host string `json:"host"` Started int `json:"started"` + Type int `json:"type"` + Pid int `json:"pid"` } type TemperatureStat struct { diff --git a/host/host_darwin.go b/host/host_darwin.go index 2f20fc616..f3e6acf1b 100644 --- a/host/host_darwin.go +++ b/host/host_darwin.go @@ -84,6 +84,8 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) { Terminal: common.IntToString(u.Line[:]), Host: common.IntToString(u.Host[:]), Started: int(u.Tv.Sec), + Type: int(u.Type), + Pid: int(u.Pid), } ret = append(ret, user) } diff --git a/host/host_freebsd.go b/host/host_freebsd.go index 2c9aa9d0d..a4482a62d 100644 --- a/host/host_freebsd.go +++ b/host/host_freebsd.go @@ -76,6 +76,8 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) { Terminal: common.IntToString(u.Line[:]), Host: common.IntToString(u.Host[:]), Started: int(sec), + Type: int(u.Type), + Pid: int(u.Pid), } ret = append(ret, user) diff --git a/host/host_linux.go b/host/host_linux.go index 162f312be..77cd10fd9 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -116,6 +116,8 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) { Terminal: common.IntToString(u.Line[:]), Host: common.IntToString(u.Host[:]), Started: int(u.Tv.Sec), + Type: int(u.Type), + Pid: int(u.Pid), } ret = append(ret, user) } diff --git a/host/host_openbsd.go b/host/host_openbsd.go index 569de4abd..6fedb9ca2 100644 --- a/host/host_openbsd.go +++ b/host/host_openbsd.go @@ -87,6 +87,8 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) { Terminal: common.IntToString(u.Line[:]), Host: common.IntToString(u.Host[:]), Started: int(u.Time), + Type: int(u.Type), + Pid: int(u.Pid), } ret = append(ret, user) From 2ca12350f495f969d674557a0ffc64822923633f Mon Sep 17 00:00:00 2001 From: "dean.lu" Date: Wed, 11 May 2022 10:16:31 +0800 Subject: [PATCH 2/2] Add "PID" and "type" fields --- host/host_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/host/host_test.go b/host/host_test.go index 76307890d..ce2d26cad 100644 --- a/host/host_test.go +++ b/host/host_test.go @@ -114,8 +114,10 @@ func TestUserStat_String(t *testing.T) { Terminal: "term", Host: "host", Started: 100, + Pid: 0, + Type: 0, } - e := `{"user":"user","terminal":"term","host":"host","started":100}` + e := `{"user":"user","terminal":"term","host":"host","started":100,"type":0,"pid":0}` if e != fmt.Sprintf("%v", v) { t.Errorf("UserStat string is invalid: %v", v) }