06 January 2013

LXDM PostLogout script to shutdown user's apps

LXDM is a bit strange in it's behaviour to not to kill your apps running when you log out. After logging out my deadbeef continues to play music and conky is still drawn on top of LXDM greeter. Look funny heh :)
I don't really like this, but I wanted DM to show list of users instead of simple prompt. Arch wiki suggests just to killall --user $USER which would also kill all your background processes they may be running (torrent, screen, etc).
Enough words - here goes the script:
$ cat /etc/lxdm/PostLogout 
#!/bin/sh
#
# Note: this is a sample and will not be run as is.

current_windows=`xlsclients -al | grep Window | cut -d' ' -f2 | sed -e 's/:$//'`
for wid in $current_windows
do
        pid=`xprop -id ${wid} _NET_WM_PID | awk -F ' = ' '{ print $2 }'`
        wmname=`xprop -id ${wid} WM_CLASS | cut -d= -f2 | cut -d, -f2 | sed -e 's/[ "]//g'`
        if [ "p${pid}" != "p" ]
        then
                echo "Killing ${wmname} (${pid})"
                kill ${pid}
        else
                echo "No PID found for ${wmname}"
        fi
done

# for some reason PID for conky cannot be determined
killall --user $USER conky
It requires xlsclients and xprop. Some apps (like conky) are special case and they don't show their PID in X11 properties of a window, so they are killed separately.

05 November 2012

Archlinux moves to systemd. My own remarks.

After notice that systemd is now default in new installations I realised that sooner or later I'll be forced to migrate disregarding whether I like this idea or not :)
After some reading I rebooted, edited kernel loading line in my Grub2 with init param pointing to systemd and booted into my Arhclinux. What was noticable that I received to GUI :) Though I was aware that systemd ignores /etc/inittab (my SLiM used to start from inittab) and I wasn't that surprised. I did sudo systemctl enable slim.service (along with couple of other services which made sense for me) and rebooted again (needed not to forget to put init kernel param in place again).
Basically everything went smooth except just a few points, which weren't clear from documentation and which made me post this writing :)

 

Here I'm talking about pure systemd installations.

 

1. systemd-sysvcompat

Documentation from Archwiki states that you must not remove this package or you won't be able to boot any more. Though this package doesn't seem to contain any things I may need now (file list for systemd-sysvcompat). And it appeared to be true - if you want to remove this package you need to do the following (instructions for Grub2 loader):
  1. edit /etc/default/grub and make sure you have init kernel param present, like this:
    GRUB_CMDLINE_LINUX_DEFAULT="init=/usr/lib/systemd/systemd"
  2. regenerate grub.cfg with
    sudo grub-mkconfig -o /boot/grub/grub.cfg
  3. now when everything went fine you could remove unnecessary things:
    sudo pacman -Rcs sysvinit-tools
    this should remove sysvinit-tools, initscripts, sysvinit and systemd-sysvcompat.

2. PCManFM doesn't show removable drives

While some other tools may show them. If not check documentation first. For me problem was that udisks daemon was inactive. So simple sudo systemctl enable udisks.service fixed this for me.

These seem to be all the troubles with systemd for me, which I find pretty painless! :) And instead of conclusion: if you want to know what else services you could enable (or disable) use systemctl list-unit-files


Update 12.01.2015

After quite some time i concluded that having a /sbin/init makes way more sense in terms of compatibility and stability then having an init= kernel option configured in a boot loader. I just switched to UEFI and had to specify init= again. This time i just symlinked systemd to /sbin/init to end up this fight:
ls -s '../lib/systemd/systemd' /usr/bin/init

24 September 2012

Using multiple input documents for XSLT transformation

I believe I'm not alone when I need to use couple of input documents for a XSLT transformation. It's rather common case to have input data from multiple sources, to process it and to return a single result. Should XSLT be an exception? Not this time.
If we look at data type mapping it obvious that we could accept and return Nodes, NodeLists, etc. We could do the same with transformer parameters as well. Here is an example:

Document doc = ...; // direct input for transformer
Document anotherDoc = ...; // second document to be passed as parameter

TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(xsl);
transformer.setParameter("anotherDoc", anotherDoc);
transformer.transform(new DOMSource(doc), new StreamResult(System.out));

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    exclude-result-prefixes="xsl">

  <xsl:param name="anotherDoc" />

  <xsl:variable name="inputDoc" select="/" />

  <xsl:template match="/">
    <xsl:apply-templates select="$anotherDoc/anotherRoot" />
  </xsl:template>


  <xsl:template match="nodeOfAnotherDoc">
    <xsl:value-of select="text()" />
    <xsl:value-of select="$inputDoc/root/@attr" />
  </xsl:template>

</xsl:stylesheet>

That's all the trick, we could operate of another document just on regular xsl:variable containing a node-set.
Just one hint: it may be useful to have a variable referencing input document root (inputDoc in example), because inside context of xsl:template that matched anotherDoc you may have trouble accessing nodes of input document.

28 June 2012

X11 session login with SLiM and no password

Basically task is to allow my mum login to home Linux-box and not to bother her with a password (or I would have to install Windoze again). At same time I want to still have access to same box with my own passworded account and to be able to login (with SLiM) to a X11 session.

I'm not going to dig into security considerations regarding passwordless users here.

So firstly let's create a user for my mum and deprive it a password:
# useradd -m -U username
# passwd -d username

Explanation:
-m force home directory creation
-U automatically creates a group with same name as username and assigns it as primary group for new user
passwd -d removes password from given account

Now you should be able to login with new user into physical terminal session. Though this depends on PAM configuration in your distro (I'm using ArchLinux). You won't be able to su to this user or login into SLiM yet.
To allow SLiM login you with empty password you need to edit /etc/pam.d/slim:
find
auth    required    pam_unix.so
and change to
auth    required    pam_unix.so nullok

That's it. Same instructions should apply to any login manager, not only SLiM.

12 June 2012

Debugging SSL traffic with socat

Often when developing a client for a remote service using HTTPS (or any SSL-tunneled protocol) it difficult to dig into the data being transferred over the network. That is the case for me and here is another cheat sheet for me:

# socat -v TCP-LISTEN:443,reuseaddr,debug,fork OPENSSL:remote.host.com:443,verify=0

This sets up a SSL tunnel, accepting non-encrypted traffic from one side, encrypting it and passing to remote host.
Then you should use localhost:443 as a connection endpoint from your piece of software and watch all the traffic being sent :)
For detail on socat option take a look at documentation.