>1) A service monitoring logged in users, starting the user supervision tree on the first login of a user and stopping it once the user logs out from the last shell/display manager
Ah, user services. They're a complicated matter, and their exact
definition varies depending on the distro. They're very much tied to
distro policies, which is why I haven't written support for them in s6,
apart from s6-usertree-maker that may or may not be useful to you.
When you say "user services", it generally means one of these things:
A. a permanent supervision tree, belonging to a normal user, that runs
services as the user, independent from whether the user is logged in.
B. A supervision tree that starts with the first login and ends with
the last logout. This appears to be what you're working on.
C. A supervision tree that is tied to a graphical session on one seat.
That would exclude remote logins via ssh. This seems to be what the
Freedesktop people have in mind when they talk about XDG specifications.
You're not the only one working on s6-rc user services for Gentoo: see
https://skarnet.org/lists/supervision/3074.html :) You should definitely
try and coordinate with Alexis! And also with other people who hang
on the #s6 channel on oftc.net and may have more ideas to share.
>2) An elegant way of synchronizing environment variables between the users supervision tree and its services and the users login shell/compositor/...
Generally speaking, when I have a set of environment variables that
need to be shared between unrelated sets of processes, I put them in
an envdir, and source the envdir whenever the variables are needed.
One way or the other, the only reliable data sharing tool you have
across process trees is the filesystem.
>Regarding 1) the best idea I currently is to have a daemon monitoring /var/run/utmp, starting an sub-process/s6-rc service for each user appearing there and stopping this sub-process/s6-rc service once the last login instance of the user vanished from that file. Since I have very little programming experience, I wanted to as you, Bercot, whether you consider this a good idea and if you do, whether this would be worth a s6 program. Can this be achieved in a better way?
Since you're going with option B, indeed you'll need something to
detect logins, but relying on utmp is a risky business, and you don't
want to interface with PAM yourself. Having a third-party program
dedicated to that is probably the right approach; Mobin mentioned
turnstile, this looks like a promising option.
I'm not going to write such a program in the s6 suite, because all the
stuff around PAM and utmp is 1. very Linux-specific and 2. extremely
brittle and badly/underspecified. At some point, however, I intend to
take a good look at PAM and brainstorm about a replacement, because the
current situation is just holding with massive amounts of duct tape,
good
will and headaches, and this makes me fearful for the future.
In any case, be wary of the trap of using XDG_RUNTIME_DIR to host your
user supervision tree. It *looks* like the ideal place to do so, but
in case of a desktop session, it's deleted too early and you don't
have time to properly terminate your services. Other people who have
experience with running user services on a desktop will talk about this
better than me.
--
Laurent
Received on Fri Jul 05 2024 - 22:54:45 CEST