mirror of
https://github.com/fleetdm/fleet
synced 2026-05-20 15:38:39 +00:00
> 📜 Related issue: https://github.com/fleetdm/fleet/issues/14698 # Checklist for submitter If some of the following don't apply, delete the relevant line. <!-- Note that API documentation changes are now addressed by the product design team. --> - [x] Changes file added for user-visible changes in `changes/` or `orbit/changes/`. See [Changes files](https://fleetdm.com/docs/contributing/committing-changes#changes-files) for more information. - [x] Manual QA for all new/changed functionality - For Orbit and Fleet Desktop changes: - [x] Manual QA must be performed in the three main OSs, macOS, Windows and Linux. - [x] Auto-update manual QA, from released version of component to new version (see [tools/tuf/test](../tools/tuf/test/README.md)).
30 lines
665 B
Go
30 lines
665 B
Go
//go:build darwin
|
|
// +build darwin
|
|
|
|
package user
|
|
|
|
import (
|
|
"errors"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
// IsUserLoggedInViaGui returns whether or not a user is logged into the machine via the GUI.
|
|
func IsUserLoggedInViaGui() (bool, error) {
|
|
output, err := exec.Command("/usr/bin/stat", "-f", "%Su", "/dev/console").Output()
|
|
if err != nil {
|
|
var ee *exec.ExitError
|
|
if errors.As(err, &ee) && len(ee.Stderr) > 0 {
|
|
return false, errors.Join(err, errors.New(string(ee.Stderr)))
|
|
}
|
|
|
|
return false, err
|
|
}
|
|
|
|
// If no user is logged in via GUI, the command line returns "root".
|
|
if strings.TrimSpace(string(output)) == "root" {
|
|
return false, nil
|
|
}
|
|
|
|
return true, nil
|
|
}
|