Skip to content

Commit

Permalink
redo if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
James-Pickett committed Nov 13, 2023
1 parent 2c2393c commit b6d7b68
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions ee/consoleuser/consoleuser_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ func CurrentUids(ctx context.Context) ([]string, error) {
continue
}

output, err := exec.CommandContext(ctx, "loginctl", "show-session", s.Session, "--property=Remote", "--property=Active").Output()
output, err := exec.CommandContext(ctx,
"loginctl",
"show-session", s.Session,
"--property=Remote",
"--property=Active",
).Output()

if err != nil {
return nil, fmt.Errorf("loginctl show-session (for sessionId %s): %w", s.Session, err)
}
Expand All @@ -47,20 +53,12 @@ func CurrentUids(ctx context.Context) ([]string, error) {
// export XDG_CURRENT_DESKTOP=ubuntu:GNOME
// export XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg

// don't count ssh users as console users
// ssh: remote=yes
// local: remote=no
// rdp: remote=no
if !strings.Contains(string(output), "Remote=no") {
continue
}

// don't include inactive users
if !strings.Contains(string(output), "Active=yes") {
continue
if strings.Contains(string(output), "Remote=no") && strings.Contains(string(output), "Active=yes") {
uids = append(uids, fmt.Sprintf("%d", s.UID))
}

uids = append(uids, fmt.Sprintf("%d", s.UID))
}

return uids, nil
Expand Down

0 comments on commit b6d7b68

Please sign in to comment.