#!/bin/bash

## Copyright (C) 2025 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

set -o errexit
set -o nounset
set -o errtrace
set -o pipefail

source /usr/libexec/helper-scripts/light_sleep.bsh

counter=0
while (( counter < 10 )); do
  light_sleep 1
  systemd_cgls_output="$(systemd-cgls --unit user.slice)"
  if [ "$(wc -l <<< "$systemd_cgls_output")" == '1' ]; then
    exit 0
  fi
  printf '%s\n' "WARNING: user.slice is not empty yet. Contents:"
  printf '%s\n' "$systemd_cgls_output"
done

printf '%s\n' "ERROR: user.slice not empty after 10 seconds!"
exit 1
