From ab33d5ec89c848f5394505889e0ae1845bec1e81 Mon Sep 17 00:00:00 2001 From: fG! Date: Sun, 13 Dec 2020 00:34:27 +0000 Subject: [PATCH] Fix wrong user count There are empty entries in OpenBSD's utmp that have a line and time entry but no user logged in (the entry is "cleared" after user logs out but not totally as expected in the code here). Current checks are insufficient so check if Name field is empty and skip in that case. --- host/host_openbsd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/host/host_openbsd.go b/host/host_openbsd.go index cfac1e9..4b9b04b 100644 --- a/host/host_openbsd.go +++ b/host/host_openbsd.go @@ -78,7 +78,7 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) { var u Utmp br := bytes.NewReader(b) err := binary.Read(br, binary.LittleEndian, &u) - if err != nil || u.Time == 0 { + if err != nil || u.Time == 0 || u.Name[0] == 0 { continue } user := UserStat{