aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/app.py
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-01-25 02:30:02 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2022-01-25 02:34:24 +0300
commit9b8f2fb8de9bd2bf1b13a84ab06e394aa9d7cb02 (patch)
tree316d32604ac502c32e1e6292213164d3dc63328b /app.py
parentapp.py: don't query user info if no users (diff)
downloadlinux-status-9b8f2fb8de9bd2bf1b13a84ab06e394aa9d7cb02.tar.gz
linux-status-9b8f2fb8de9bd2bf1b13a84ab06e394aa9d7cb02.zip
app.py: don't do systemctl --user if no user instance
Diffstat (limited to '')
-rwxr-xr-xapp.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/app.py b/app.py
index 67cdd6d..dd3edfc 100755
--- a/app.py
+++ b/app.py
@@ -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.