Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions host/host_aix.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package host

import (
"context"
"strconv"
"strings"

"github.com/shirou/gopsutil/v4/internal/common"
Expand Down Expand Up @@ -54,20 +53,19 @@ func UsersWithContext(ctx context.Context) ([]UserStat, error) {
hf := strings.Fields(lines[1]) // headers
for l := 2; l < len(lines); l++ {
v := strings.Fields(lines[l]) // values
if len(v) == 0 || v[0] == "-" {
continue
}
us := &UserStat{}
for i, header := range hf {
// We're done in any of these use cases
if i >= len(v) || v[0] == "-" {
if i >= len(v) {
break
}

if t, err := strconv.ParseFloat(v[i], 64); err == nil {
switch header {
case `User`:
us.User = strconv.FormatFloat(t, 'f', 1, 64)
case `tty`:
us.Terminal = strconv.FormatFloat(t, 'f', 1, 64)
}
switch header {
case "User":
us.User = v[i]
case "tty":
us.Terminal = v[i]
}
}

Expand Down