On Ubuntu at least up to 24.04, systemd doesn't use this new --json flag -- I think at this point, the older flag will be much more widely supported in our userbase. So I have defaulted to trying with the older flag first, and falling back to the newer flag in case of error. Eventually we will want to swap the order that we try the flags in.
Confirmed --json=short output is compatible with what we previously expected (session, uid, user, seat all present):
Notes on setting up a test environment
I set up an arch VM in Google Cloud to test this -- here are the steps.
I used a base image from [this project](https://github.com/GoogleCloudPlatform/compute-archlinux-image-builder) and created a VM:
```
gcloud compute instances create --image-project=arch-linux-gce --image-family=arch --project
```
I SSHed to the VM and got it updated via [these instructions](https://wiki.archlinux.org/title/Pacman/Package_signing#Upgrade_system_regularly)
```
pacman -Sy --needed archlinux-keyring && pacman -Su
```
Validated that it's adequately updated via `loginctl --version` and `loginctl list-sessions --no-legend --no-pager --json=short`.
I stopped the VM, enabled `display device`, and restarted the VM – I think this is what got me a `Remote=no Active=yes` session to be able to get a desktop process going.
I uploaded launcher binary from this PR's artifacts to VM; I uploaded osqueryd binary [from the releases](https://github.com/osquery/osquery/releases) to the VM; `chmod +x` both.
I made a root dir for testing, then ran launcher and let it start up:
```
sudo ./launcher --hostname --root_directory --osqueryd_path --transport jsonrpc --enroll_secret
```
In another window, I confirmed I saw the launcher desktop process eventually -- `ps -eaf | grep launcher`. There were some errors (e.g. no tray is running, so we get errors about no tray running), but seeing the desktop process running should be enough to prove this fix.
The output flag for
loginctl list-sessions
has changed in more recent versions of systemd: https://www.freedesktop.org/software/systemd/man/latest/loginctl.html#Session%20CommandsOn Ubuntu at least up to 24.04, systemd doesn't use this new
--json
flag -- I think at this point, the older flag will be much more widely supported in our userbase. So I have defaulted to trying with the older flag first, and falling back to the newer flag in case of error. Eventually we will want to swap the order that we try the flags in.Confirmed
--json=short
output is compatible with what we previously expected (session, uid, user, seat all present):Relates to https://github.com/kolide/launcher/issues/1758
Notes on setting up a test environment
I set up an arch VM in Google Cloud to test this -- here are the steps. I used a base image from [this project](https://github.com/GoogleCloudPlatform/compute-archlinux-image-builder) and created a VM: ``` gcloud compute instances create