[Spice-devel] [systemd-devel] systemd -> consolekit, spice-vdagent questions

Lennart Poettering lennart at poettering.net
Mon Sep 19 18:28:56 PDT 2011


On Wed, 14.09.11 16:26, Hans de Goede (hdegoede at redhat.com) wrote:

> Hi,
> 
> The spice guest agent for Linux consists of a system level
> process (a daemon) and a per session process (started for
> each active xsession).
> 
> Currently the linux spice-vdagent is using ConsoleKit to
> figure out (for the first seat, it assumes a vm is single seat):
> 
> 1) Which session is active (including notification of when this changes)
> 2) Which session each session agent process belongs too
> 
> It needs this to figure out to which session agent process to send
> copy/paste requests for copy paste between the active session in
> the guest and the client.
> 
> I've not really searched all that well I must admit, and surprisingly,
> I've thus been unable to find low level docs of how this all works
> in the systemd replaces consolekit world.
> 
> Currently the spice-vdagent makes the following dbus calls, to achieve
> the 2 items above:
> 
> 1) org.freedesktop.ConsoleKit.Seat -> GetActiveSession
> 2) org.freedesktop.ConsoleKit.Manager -> GetSessionForUnixProcess
> 
> And it listens to the org.freedesktop.ConsoleKit.Seat -> ActiveSessionChanged
> signal.
> 
> What are the equivalents for these now ?

You can either do this via D-Bus (as noted). However, I recommend to use
the simple C API instead when all you are interested in are simple
checks and notifications. This helps keeping our stack thin and is
actually much easier to use for you:

http://cgit.freedesktop.org/systemd/tree/src/sd-login.h

There's no comprehensive documentaiton available about that API since it
is still very new. However, the comments in the header file should cover
most what you need. To be more precise, use something like this:

<snip>
char *session;

r = sd_seat_get_active("seat0", &session, NULL);
if (r < 0)
        printf("failed: %s\n", strerror(-r));
else  {
        printf("Woopie! %s\n", session);
        free(session);
}
</snip>

And:

<snip>
char *session;

r = sd_pid_get_session(pid, &session);
if (r < 0)
        printf("failed: %s\n", strerror(-r));
else  {
        printf("Woopie! %s\n", session);
        free(session);
}
</snip>

Dead easy, cheap, and synchronous.

For the session change notification use:

<snip>
sd_login_monitor *monitor;

r = sd_login_monitor_new("session", &monitor);
fd = sd_login_monitor_get_fd(monitor);

for (;;) {
        /* wait for some kind of event on fd */
        poll(...);
        sd_login_monitor_flush(monitor);

        /* Read changed data ... */
        sd_seat_get_active("seat0", ....);
}
</snip>

I am sure you can interpolate the necessary error checking from the
earlier examples...

Lennart

-- 
Lennart Poettering - Red Hat, Inc.


More information about the Spice-devel mailing list