Showing posts with label Debian. Show all posts
Showing posts with label Debian. Show all posts

Tuesday, March 13, 2012

nodm and matchbox window manager and auto starting applications

I'm working on a project for work that is based around a live distro.  For the live distro building, I went with live-build since Debian is by far my favorite distro.  The live build was pretty easy to implement, and I'm not going to bore you with the details when there's plenty of documentation out there, especially the live-manual.  This post is all about how to get Xorg started and how to launch an application when Xorg starts up without diverting files in other packages, or having a match install anything to a users home directory.

The clear start to this task is nodm.  It'll automatically login as a user and start your xsession.  If you don't have an xsession installed, it'll fall back to the normal Debian xsession script that'll just launch an xterm.  This is simple enough, but remember that without a window manager, you're not going to get any of the standard desktop magic that the freedesktop.org window manager specification gives you.  For example, being able to call gtk_window_maximize.

To fix that problem I went with matchbox window manager.  It's very light weight window manager meant mostly for mobile devices and runs apps in full screen, thus eliminating my need to maximize the application window.  Matchbox registers itself as an alternative for x-window-manager under Debian which, in this bare bones approach will start matchbox on boot, but no apps.

Luckily, the matchbox package depends on matchbox-common and matchbox-common contains /usr/bin/matchbox-session.  This script looks for a session script and will execute it, if it doesn't find one, it'll launch matchbox-desktop and matchbox-panel in the background, and then launch matchbox-window-manager in the foreground.  The real awesomeness here, is that matchbox-session checks if there is an executable script named session in /etc/matchbox/.  What this means, is that you can easily create a package that depends on matchbox and install that file.  This fulfills all of our requirements!!  But wait, matchbox-session won't be called from nodm...

Solving that problem is actually a lot easier than you're probably thinking.  Debian's Xsession scripts give a higher priority to x-session-manager which is in the alternatives system.  So all we need to do, is to register matchbox-session as an alternative for x-session-manager.  Once this is done, our custom /etc/matchbox/session will get executed and we're good to go :)

Due to NDA's and stuff, I can't post my exact package here, but here's the jist of it.

Make sure your control file depends on "matchbox" (that's the meta package for matchbox and will pull everything in); you can probably clean it up to just matchbox-common and matchbox-window-manager, but I leave that to you.

Next create a postinst script that contains the following:

#!/bin/sh
set -e
case "$1" in
        configure)
                update-alternatives --install /usr/bin/x-session-manager \
                        x-session-manager /usr/bin/matchbox-session 50
        ;;
esac
#DEBHELPER#
and a prerm which contains the following:

#!/bin/sh
set -e
case "$1" in
        remove)
                update-alternatives --remove x-session-manager /usr/bin/matchbox-session
        ;;
esac
#DEBHELPER#
Then create your custom session script.  Mine looks something like this:

#!/bin/sh
application &
exec matchbox-window-manager
Make sure all three of those are executable, add the session script to your install file, fire off debuild  and you should be good to go.

I hope this helps other, since googling for this earlier came up pretty empty :)


Wednesday, October 19, 2011

using scan-build from clang with cmake

If you've wanted to add static analysis to your C/C++ project which uses CMake but didn't know how, then you'll want to read this.  This post is mostly a note for myself so I don't have to google it later ;)

If you're using Debian it's actually quite easy.  Just install the clang package with:
# apt-get install clang
After that's done installing, change directories into your source directory.  Now typically I use a separate build directory since it helps keep my source clean and allows me to do a build with gcc and clang from the same source directory.

Anyways, since we want to do an analysis with clang's scan-build, we're going to create a new build directory in our top level source directory.  For example:
$ mkdir build-analyze
The next commands will be need to be run from this new directory, so change into it now.
 $ cd build-analyze
 Now we need to generate our build system with cmake and compile it, but we need to point cmake to clang's ccc-analyzer.  In Debian, this program is located in /usr/share/clang/scan-build/ccc-analyzer.

$ cmake -DCMAKE_C_COMPILER=/usr/share/clang/scan-build/ccc-analyzer ..
$ scan-build make
When you're build is finished you will see two lines, like the ones shown below.
scan-build: 6 bugs found.
scan-build: Run 'scan-view /tmp/scan-build-2011-10-19-1' to examine bug reports.
As you can see, it found 6 bugs in my code.  To view the bugs, the easiest way is to run:
$ scan-view /tmp/scan-build-2011-10-19-1
This will start up a local web server, and open it in your default web browser.  From here you can review the bugs and determine how to fix them!

Hope this was helpful!