diff options
Diffstat (limited to '')
-rwxr-xr-x | app.py | 18 |
1 files changed, 17 insertions, 1 deletions
@@ -311,7 +311,10 @@ class UserInstanceStatusTaskList(Task): self.tasks = {user.name: UserInstanceStatusTask.su(user) for user in systemd_users()} else: # As a regular user, we can only query ourselves. - self.tasks = {get_current_user().name: UserInstanceStatusTask()} + self.tasks = {} + user = get_current_user() + if user_instance_active(user): + self.tasks[user.name] = UserInstanceStatusTask() def run(self): for task in self.tasks.values(): @@ -363,6 +366,19 @@ def get_current_user(): return User(entry.pw_uid, entry.pw_name) +def user_instance_active(user): + # I'm pretty sure this is the way to determine if the user instance is + # running? + # Source: https://www.freedesktop.org/software/systemd/man/user@.service.html + unit_name = f'user@{user.uid}.service' + cmd = Systemctl.system('is-active', unit_name, '--quiet') + try: + cmd.run().result() + return True + except Exception: + return False + + # A pitiful attempt to find a list of possibly-systemd-enabled users follows # (i.e. users that might be running a per-user systemd instance). # I don't know of a better way than probing /run/user/UID. |