sobota, 5 października 2013

Long time, no see

lightdm-1.6.2-1 is there. And so is Xephyr 1.12.4-6.2+b2.
The latter works with the usual procedure. The former does change the procedure a bit. The patch referring to removing stale files does not apply at all. I just don't use it any more... and as far as I know there has been some activity in the lightdm project regarding removing any stale files at runtime. So now only the patch adding the "common-vt" option is required.
Below is what I applied:

diff --git a/src/lightdm.c b/src/lightdm.c
index 7f67ea7..840aee1 100644
--- a/src/lightdm.c
+++ b/src/lightdm.c
@@ -1056,6 +1056,8 @@ main (int argc, char **argv)
         config_set_boolean (config_get_instance (), "LightDM", "start-default-seat", TRUE);
     if (!config_has_key (config_get_instance (), "LightDM", "minimum-vt"))
         config_set_integer (config_get_instance (), "LightDM", "minimum-vt", 7);
+    if (!config_has_key (config_get_instance (), "LightDM", "common-vt"))
+        config_set_boolean (config_get_instance (), "LightDM", "common-vt", FALSE);
     if (!config_has_key (config_get_instance (), "LightDM", "guest-account-script"))
         config_set_string (config_get_instance (), "LightDM", "guest-account-script", "guest-account");
     if (!config_has_key (config_get_instance (), "LightDM", "greeter-user"))
diff --git a/src/vt.c b/src/vt.c
index 62839d9..810e73e 100644
--- a/src/vt.c
+++ b/src/vt.c
@@ -117,15 +117,23 @@ vt_get_min (void)
 gint
 vt_get_unused (void)
 {
+    static gint common_number = -1;
+
+    gboolean common_vt;
     gint number;

     if (getuid () != 0)
         return -1;

+    common_vt = config_get_boolean (config_get_instance (), "LightDM", "common-vt");
+    if (common_vt && common_number > 0)
+    return common_number;
+
     number = vt_get_min ();
     while (vt_is_used (number))
         number++;
 
+    common_number = number;
     return number;
 }



And it works, as of October 5th, 2013.

sobota, 25 maja 2013

lightdm 1.6.0-3

OK, the patches almost apply; below there is the new patch.
Confirmed, works.

Description: <short summary of the patch>
 Xephyr-multiseat requires that all X servers are run on the same vt.
 .
 lightdm (1.6.0-3) unstable; urgency=low
 .
   * debian/control:
     - drop valac-0.18 dependency for now since it's not available in sid
       anyway.                                                   closes: #707176
Author: Yves-Alexis Perez <corsac@debian.org>
Bug-Debian: http://bugs.debian.org/707176

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: http://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- lightdm-1.6.0.orig/src/lightdm.c
+++ lightdm-1.6.0/src/lightdm.c
@@ -974,6 +974,8 @@ main (int argc, char **argv)
         config_set_boolean (config_get_instance (), "LightDM", "start-default-seat", TRUE);
     if (!config_has_key (config_get_instance (), "LightDM", "minimum-vt"))
         config_set_integer (config_get_instance (), "LightDM", "minimum-vt", 7);
+    if (!config_has_key (config_get_instance (), "LightDM", "common-vt"))
+        config_set_boolean (config_get_instance (), "LightDM", "common-vt", FALSE);
     if (!config_has_key (config_get_instance (), "LightDM", "guest-account-script"))
         config_set_string (config_get_instance (), "LightDM", "guest-account-script", "guest-account");
     if (!config_has_key (config_get_instance (), "LightDM", "greeter-user"))
--- lightdm-1.6.0.orig/src/xserver-local.c
+++ lightdm-1.6.0/src/xserver-local.c
@@ -318,9 +318,13 @@ got_signal_cb (Process *process, int sig
 static void
 stopped_cb (Process *process, XServerLocal *server)
 {
+    guint display_number;
+    gchar *path;
+
     g_debug ("X server stopped");

-    xserver_local_release_display_number (xserver_get_display_number (XSERVER (server)));
+    display_number = xserver_get_display_number (XSERVER (server));
+    xserver_local_release_display_number (display_number);
  
     if (xserver_get_authority (XSERVER (server)) && server->priv->authority_file)
     {
@@ -345,6 +349,10 @@ stopped_cb (Process *process, XServerLoc
         plymouth_quit (FALSE);
     }

+    path = g_strdup_printf ("/tmp/.X%d-lock", display_number);
+    g_unlink (path);
+    g_free (path);
+
     DISPLAY_SERVER_CLASS (xserver_local_parent_class)->stop (DISPLAY_SERVER (server));
 }

--- lightdm-1.6.0.orig/src/vt.c
+++ lightdm-1.6.0/src/vt.c
@@ -125,15 +125,23 @@ vt_get_min (void)
 gint
 vt_get_unused (void)
 {
+    static gint common_number = -1;
+
+    gboolean common_vt;
     gint number;

     if (getuid () != 0)
         return -1;

+    common_vt = config_get_boolean (config_get_instance (), "LightDM", "common-vt");
+    if (common_vt && common_number > 0)
+    return common_number;
+
     number = vt_get_min ();
     while (vt_is_used (number))
         number++;
 
+    common_number = number;
     return number;
 }

czwartek, 16 maja 2013

Jessie is here!

The king has died, long live the king! Wheezy is released to be the next, rock-solid stable Debian. And so it is time to move to the new testing.

Jessie is here, with ligthdm 1.2.3-1. The usual patches do apply, although with some fuzz, but "patch" still handles this ok.

Confirmed, works.

środa, 27 lutego 2013

Another dist-upgrade

Debian wheezy as of 27th February 2013 with udev 175-7.1 works.

However, my Xephyr-seat-X scripts sometimes do not function correctly: it turns out, that when the Xephyr is run, there is no DISPLAY :0. I solved the problem twofold: 1) I added a "sleep 5" before Xephyr is invoked and 2) used "Option" "NoLogo" "true" entry in my xorg.conf's "Device" section for nvidia.
I think that drawing a logo and keeping it visible for some time creates some delays, so probably it is better not to draw it.

wtorek, 20 listopada 2012

poniedziałek, 5 listopada 2012

Another upgrade

This time it is lightdm: the latest version in wheezy is 1.2.2-4.
The same procedure is still valid: apply the two patches, rebuild and voila.

środa, 24 października 2012

Still + 1

The latest Wheezy update as of this writing still contains a buggy Xephyr, version xorg-server-1.12.4. The patch

http://patchwork.freedesktop.org/patch/12146/

still needs to be applied. But Xephyr needs to be recompiled with -enable-kdrive-evdev anyway for our purposes, so applying this one-liner won't hurt. Other than that, it works fine.

poniedziałek, 8 października 2012

Too much patch will kill you

In the recent Debian wheezy there is a new Xephyr which has broken options parsing due to a mismerged patch. The bug is fixed by Keith Packard, I will post more soon.


http://lists.debian.org/debian-x/2012/10/msg00071.html


http://patchwork.freedesktop.org/patch/12146/

Looks like the patch is not going to make it soon to Wheezy, so there you go, you can use the patch from freedesktop.

poniedziałek, 24 września 2012

helper-functions

. /etc/default/multiseat

#
# private implementation of get_sect
#
# get given section's contents from the given config file
#
# $1 filename
# $2 section number
#
__get_sect()
{
    cat $1 | awk -v sect=$2 '
    BEGIN {
        SECT="^\\[" sect "\\]"
        NEXT_SECT="^\\[" (sect + 1) "\\]"
    }
    $0 ~ SECT, $0 ~ NEXT_SECT {
        if ($0 ~ SECT)
            next;
        if ($0 ~ NEXT_SECT)
            next;
        if (substr($1, 1, 1) == "#")
            next;
        print
    }
    '
}

#
# private implementation of get_conf
#
# get given key's contents from the given section
# from the given config file
#
# does not work for tables in the config file
#
# $1 filename
# $2 section name
# $3 key name
#
__get_conf()
{
    __get_sect $1 $2 | awk -F"=" -v key=$3 '
    BEGIN {
        KEY=key
    }
    $1==KEY {
        print substr($0, index($0, "=") + 1)
    }
    '
}

#
# private implementation of get_num_seats
#
# get number of seats from the default config file
#
# $1 filename
#
__get_num_seats()
{
    cat $1 | awk '
    BEGIN {
        count=0
    }
    /^\[[0-9]*\]/ {count++}
    END {
        print count - 1
    }
    '
}

#
# get given section's contents from the default config file
#
# $1 section name
#
get_sect()
{
    __get_sect $CONFIG $1
}

#
# private implementation of get_table
#
# $1 filename
# $2 section number
# $3 table name
# $4 size/entry switch [-size => size, <number> for entry]
#
__get_table()
{
    SIZE=0;
    ENTRY=-1

    if [ $4 == "-size" ];
    then
        SIZE=1;
    else
        ENTRY=$4
    fi

    RESULT=`__get_sect $1 $2 | awk -v table=$3 -v get_size=$SIZE -v entry=$ENTRY '
    BEGIN {
        print BEGIn
        TABLE=table "\\\=" "\\\("
        GET_SIZE=get_size
        ENTRY=entry
        size=0
    }
    $0 ~ TABLE, /^\)/ {
        if ($0 ~ TABLE)
            next;
        if ($0 ~ /^\)/)
            next;
        if (substr($1, 1, 1) == "#")
            next;
        if (get_size == 0 && size == entry){
                print
                exit
        }
        size++;
    }
    END {
        if (get_size)
            print size;
    }
    '`
    RESULT=`echo $RESULT | sed 's/^[ \t]*//g'`

    echo $RESULT
}

#
# get given key's contents from the given section
# from the default config file
#
# does not work for tables in the config file
#
# $1 section name
# $2 key name
#
get_conf()
{
    __get_conf $CONFIG $1 $2
}

#
# get number of seats from the default config file
#
get_num_seats()
{
    __get_num_seats $CONFIG
}

#
# get size of a given table in the given section of the config file or
# get specified entry of the table
#
# $1 section number
# $2 table name
# $3 size/entry switch [-size => size, <number> for entry]
#
get_table()
{
    __get_table $CONFIG $1 $2 $3
}

Escape characters alive forever

The multiseat config is never managed once and for ever...

I wanted the scripts to be as little dependent as possible, so for parsing the multiseat.conf file I used only bash&sed&awk, no fancy tools like python. The helper-functions have been written in the mawk dialect of awk, and the awk found in Debian used to be mawk. Alas, no longer. So there are two options to consider: modify the helper-functions, so that mawk is used explicitly instead of awk (and make sure mawk is installed), or modify the helper-functions to speak gnu awk found in Debian now. I chose the second option. In fact only some escaping craziness differs. Instead of one backslash now two or three (!) are required here and there. You can find the new script here.

czwartek, 23 sierpnia 2012

Multiseat - final thoughts (so far)

Now I am happily running an up-to-date Debian Wheezy. However, some precautions must be made when upgrading. I wrote such a script:


#!/bin/bash

SENSITIVE="wmctrl xserver-xephyr lightdm policykit"

PACKAGES=`apt-get --dry-run dist-upgrade | awk '/^The following packages will be upgraded:/,/^[1-9]./' | tail -n +2 | head -n -1`

echo "Searching sensitive packages:"
echo
echo $SENSITIVE
echo
echo "in:"
echo
echo $PACKAGES
echo

FOUND=0

for i in $SENSITIVE; do
    echo $PACKAGES | grep $i 2>&1 >/dev/null && echo Found: $i && FOUND=1
done

if [ $FOUND -eq 0 ]; then
echo No sensitive packages found in upgrade.
fi

The script can be run after apt-get update to see if any of the packages enumerated in "SENSITIVE" are to be upgraded this time. If yes, care must be taken.

Policy kit needs a paragraph of its own. At this moment Debian Wheezy comes with policykit-1 version 0.105. This is the last version in which the actions' permissions are customized using .pkla files. From 0.106 on (0.107 is the latest now) the format and naming of the directories and files has changed.

Another thing is systemd, which one day can become The Right Way of doing things.

USB in multiseat

Here is how I configured my machine in order for users @ multiseat can mount USB drives.

First of all, in modern Debian distributions there is polkit-1. The policy kit infrastructure consists of, among others, a D-BUS service org.freedesktop.PolicyKit1 implemented as /usr/lib/policykit-1/polkitd. The service is used on behalf of user applications wanting to talk to privileged processes, the latter being described by so called actions stored in /usr/share/polkit-1/actions/. Policy kit's job is either to grant permission for an application to talk to a privileged process, or not. Each action, apart from the service it describes, provides default permissions for different kinds of sessions: active sessions, inactive sessions and any kind of sessions. For example, org.freedesktop.udisks.policy file contains descriptions of a number of actions related to disks (like mount/unmount and such).

It turns out, that of the n + 1 X sessions (Xinerama + n seats), only the Xinerama session happens to be ACTIVE. All other sessions, started through Xephyrs, are PASSIVE. And by default PASSIVE sessions are not allowed to mount USB drives, which is expressed by <allow_inactive>no</allow_inactive> in org.freedesktop.udisks.policy. Nor are they allowed to suspend the machine, see org.freedesktop.upower.policy. In different places advice can be found to edit .policy files. Don't! It is not the right way to do it. Instead, create files in /etc/polkit-1/localauthority/50-local.d/. I use the following two:

10-org.freedesktop.upower.pkla:
[Suspend/hibernate permissions]
Identity=unix-group:power
Action=org.freedesktop.upower.suspend
ResultAny=yes
ResultInactive=yes
ResultActive=yes

20-org.freedesktop.udisks.pkla:
[Storage Permissions]
Identity=unix-group:storage
Action=org.freedesktop.udisks.change;org.freedesktop.udisks.drive-detach;org.freedesktop.udisks.drive-eject;org.freedesktop.udisks.filesystem-mount;org.freedesktop.udisks.filesystem-unmount-others
ResultAny=yes
ResultInactive=yes
ResultActive=yes

In order for this setup to work, the users in question must belong to groups power and storage.


I handle mounting USB drives manually, that is, in a file manager drives show up automatically after plugging in, but one of the users (each time it can be a different user) must explicitly mount them for him/herself. In LXDE's pcmanfm->Edit->Preferences->Volume management "Mount removable media automatically when they are inserted" and "Mount mountable volumes automatically on program startup" are unchecked. In other words, the multiseat users must collaborate to decide who mounts the newly inserted USB drive. If it were to happen automatically, the user whose file manager mounts the drive first wins the race. And race is not what we want here.

As you might have noticed, I use LXDE. Gnome-3 looks to heavy. And besides, with Xephyr's lack of GLX support, only the classic appearance is available, so I choose the lighter alternative.

Debian Wheezy - on hard disk

I just wanted to let you know that as of today, 23rd August 2012, I am using the most up-to-date Debian Wheezy with lightdm and LXDE, installed to the hard disk of my computer. It just works.

sobota, 18 sierpnia 2012

Xephyr

Remember me complaining I was not Keith Packard?

I am still not ;P

But I am kind of closer to a good solution with an up-to-date Xephyr.

You know, at my Faculty of Electronics and Information Technology I in fact learnt just one thing, everything else follows from that: "It works better when turned on" (a small addendum to it is that "computerization of a mess makes a bigger mess"). And this (not being turned on) is the very reason of Wheezy's Xephyr not handling evdev protocol.

So how can it be turned on? Fortunately, it is fairly simple: do apt-get source xserver-xephyr, then apt-get buid-dep xserver-xephyr, and then edit xorg-server-<some numbers>/debian/rules: after --enable-kdrive \ add a new line which reads --enable-kdrive-evdev \.

Then dpkg-buildpackage -uc -us, after some 15 minutes the build stopped with an error regarding libGL; however in xorg-server-1.12.3/debian/xserver-xephyr/usr/bin/Xephyr there was a new Xephyr binary. I tested it and it works ok!

I know that this is a kind of a poor man's solution: the package should build nicely to the end. It is desired to at least know and understand why the build stops and whether it should worry us. Nevertheless, it seems that Xephyr should not be a showstopper for the multiseat config, that is, we are not forced to use a binary from an ancient distribution.

Configuration of ligthdm 1.2

The configuration is pretty similar to that of lightdm 1.0. The changes are indicated in red.

/
|
+-/etc
|  |
|  +-/default
|  |  |
|  |  +-multiseat
|  |
|  +-/lightdm
|  |  |
|  |  +-lightdm.conf
|  |
|  +-/X11
|  |  |
|  |  +-xorg.conf
|  |
|  +-/init.d
|  |  |
|  |  +-multiseat
|  |
|  +-/udev
|  |  |
|  |  +-/rules.d
|  |     |
|  |     +-00-multiseat.rules
|  |
|  +-/multiseat
|     |
|     +-multiseat.conf
|     |
|     +-/scripts
|        |
|        +-helper-functions
|        |
|        +-match-and-name
|        |
|        +-multiseat-greeter-1
|        |
|        +-multiseat-greeter-<n>
|        |
|        +-fake-greeter
|        |
|        +-Xephyr-seat-1
|        |
|        +-Xephyr-seat-<n>
+-/usr
    |
    +-/share
       |
       +-/xgreeters
          |
          +-multiseat-greeter-1.desktop
          |
          +-multiseat-greeter-<n>.desktop
          |
          +-xinerama.desktop

The lithdm.conf is different than in lightdm 1.0, because it explicitly specifies a distinct xserver-command for each seat, the same with greeter-session.

The xserver-command for the seat <n> references its corresponding Xephyr-seat-<n> script, which, in turn, has its seat number hardcoded. The greeter-session for the seat <n> references its corresponding multiseat-greeter-<n>.desktop file, which has a hardcoded reference to its corresponding multiseat-greeter-<n>, which in, turn, has its seat number hardcoded.

The /etc/init.d/multiseat is changed now because it has a LSB-style header, making it suitable for a dependency-based boot. To create appropriate symlinks call

$ update-rc.d multiseat defaults


Multiseat setup - multiseat-greeter-1.desktop

[Desktop Entry]
Name=LightDM GTK+ Greeter
Comment=This runs the GTK+ greeter, it should only be run from LightDM
Exec=/etc/multiseat/scripts/multiseat-greeter-1
Type=Application
X-Ubuntu-Gettext-Domain=lightdm

Multiseat setup - multiseat-greeter-1

#!/bin/bash
#
#multiseat wrapper around ligthdm greeter in order to position 1 Xephyr instance
#
. /etc/multiseat/scripts/helper-functions

PRIMARY=`get_conf 0 PRIMARY`
SEAT=1

if [ $SEAT != $PRIMARY ]; then
    XEP=`XAUTHORITY=/var/run/lightdm/root/:0 xwininfo -root -children -display :0 | grep "Xephyr on :$SEAT" --max-count=1`;
    XEPHYR_WIN_ID=`echo ${XEP} | cut -d' ' -f1`;
    DISPLACEMENT=`get_conf $SEAT DISPLACEMENT`
    DISPLAY=:0 XAUTHORITY=/var/run/lightdm/root/:0 wmctrl 2>&1 -v -i -r ${XEPHYR_WIN_ID} -e 0,${DISPLACEMENT},-1,-1;
fi

XAUTHORITY=/var/run/lightdm/root/:$SEAT
DISPLAY=:$SEAT
exec /usr/sbin/lightdm-gtk-greeter