[systemd-devel] Howto detect a session start (and end) with systemd?

David Herrmann dh.herrmann at googlemail.com
Wed Jun 27 07:21:32 PDT 2012


Hi Stef

On Mon, Jun 25, 2012 at 11:27 AM, Stef Bon <stefbon at gmail.com> wrote:
> Hi,
>
> I'm working on a construction which creates "workspaces" for a user
> when he/she logs in.
>
> These workspaces are directories with vritual directories managed by a
> FUSE fs, with access to mountable resources like harddisks, usb
> sticks, cdroms but also network services like smb shares.
>
> In practice this will mean for example the creation of the maps
>
> Devices
>
> and
>
> Network
>
> in the homedir of the user, and access to local block devices is able
> when accessing Devices, and a browseable network map is created in
> Network. The first type of workspace works, but still in alpha, more
> testing is required, and currently working on the network map enabling
> the detection of smb workgroups, servers and shares on the fly.
>
> Mounting is done by the automounter, using for example mount.cifs for
> the smb shares, and contents is redirected to the location where the
> resource is available in the workspace by the FUSE fs.
>
> This construction does not depend on any gui or desktop environment,
> like KDE or Gnome, and works on filesystem level. Anyone - also when
> loging in from text console - can use this.
>
> Now this works already very good. I've one program (fuse-workspace)
> which watches the sessions starts and ends. I've made this work by
> adding the pam module pam_script to the relevant pam files, and make
> that module run scripts which maintain a usersessions file.
> Fuse-workspace watches that file for changes.
> This works, and I'm keeping this for a "always working fallback", but
> I would like to know how to do this with systemd, since this is doing
> that also, and doing things double is never a good thing on systems
> with systemd installed.
>
> For example: is watching the directory /run/systemd/sessions by
> inotify a good idea? (inotify is already used).

You can use the sd-login library. It does basically the same as you
suggested. It watches the right directories for changes and notifies
you. However, it also has some handy helpers to list all sessions so
you can refresh your session-list every time the directory changes.
See sd-login.h for more information.

Regards
David


More information about the systemd-devel mailing list