This question already has an answer here:
Is it possible to get the name of an active user in systemd units? I guess I could parse output of
who or do something like that, but I believe there should be a native way of doing that in systemd.
I also know there is
logind which tells me a bit more information about the users, but if there were more seats, I would like to know who the single user who caused the event was, e.g. if someone wrote
systemctl suspend to only lock his session at his seat and let the computer handle all the other seats. It is probably not the best example but I hope it illustrates the problem better, I only want the one user who caused systemd units to run.
Namely I wanted to create a systemd unit that will lock the user's current session when going to sleep and right now I resorted to trying to lock all sessions. I believe this to be a bad solution and would like to know how to do this properly.