host_linux: Skip everything that isn't a normal process.

host_darwin does the same filtering. Not doing this gives us some rather strange
entries that likely aren't what we want.

Before:
    {"user":"reboot","terminal":"~","host":"3.10.0-327.4.5.el7.x86_64","started":1454378260}
    {"user":"LOGIN","terminal":"ttyS0","host":"","started":1454378270}
    {"user":"LOGIN","terminal":"tty1","host":"","started":1454378270}
    {"user":"runlevel","terminal":"~","host":"3.10.0-327.4.5.el7.x86_64","started":1454378276}
    {"user":"root","terminal":"pts/0","host":"vpn","started":1454404513}

After:
    {"user":"root","terminal":"pts/0","host":"vpn","started":1454404513}
This commit is contained in:
Robin Burchell 2016-02-02 10:51:15 +01:00
parent 9d8191d6a6
commit 3fc7bc1ef7
1 changed files with 6 additions and 0 deletions

View File

@ -26,6 +26,9 @@ type LSB struct {
Description string
}
// from utmp.h
const USER_PROCESS = 7
func HostInfo() (*HostInfoStat, error) {
ret := &HostInfoStat{
OS: runtime.GOOS,
@ -120,6 +123,9 @@ func Users() ([]UserStat, error) {
if err != nil {
continue
}
if u.Type != USER_PROCESS {
continue
}
user := UserStat{
User: common.IntToString(u.User[:]),
Terminal: common.IntToString(u.Line[:]),