“Elegance is not a dispensable luxury” — Edsger Wybe Dijkstra

Useful UNIX API:s

Had an interesting conversation with a buddy last night. It started out as a shift-reduce problem with Bison and ended up a ping-pong of useful UNIX API:s. We concluded that despite having worked professionally with UNIX for over a decade, it is still very satisfying finding gems like these.

Most people are unaware they existing and therefore often end up rolling their own (buggy) implementations.

SysV search.h

Mangage a simple queue:

  • insque()
  • remque()

Manage hash search table:

  • hsearch()
  • hcreate()
  • hdestroy()

Manage a binary search tree:

  • tsearch()
  • tfind()
  • tdelete()
  • twalk()
  • tdestroy()

Linear search and update:

  • lfind()
  • lsearch()

BSD sys/queue.h

This header has lots of macros for handling various forms of linked lists. The version in GLIBC is a bit behind the BSD’s, because the latter also have _safe() versions of some macros to aid the user in some tricky cases, e.g. when removing entries while iterating.

Several types of lists are supported:

  • LIST: Doubly linked list
  • SLIST: Single linked list
  • STAILQ: Single linked tail queue
  • SIMPLEQ: Simple queue
  • TAILQ: Tail queue
  • CIRCLEQ: Circular queue

Here’s a few of them:


I wrote a demo of the TAILQ API a couple of years ago.

Other Noteworthy API’s

Other functions worthy of mentioning here are:


  • bsearch()
  • qsort()


  • glob()

En Vanlig Dag På Jobbet (SWEDISH)

I vanlig ordning bashar vi DNS på jobbet, pga ofungerar hårt över VPN för de flesta. (Ja vi kör alla Linux, utom cheferna som envisas med att använda något ur gamla testamentet.) Här följer ett utdrag från vår IRC:

14:32 <n00b> Success! Äntligen fick jag ordning på DNS via guest
      wifi -> vpn -> office network. Firar med att skapa lite irc noise. :D
14:32 < rooth>n00b: Du har väl fått den distribuerade /etc/hosts filen?
14:33 < rooth> !dns paperboy
14:33 < |master|> rooth: lazyboy
14:33 < rbot> rooth: lazyboy:
14:33 < rooth> bottarna hjälper dig annars =)
14:34 <n00b> hosts file is so... "unclean" ;)
14:35 <n00b> Men bra att veta att bottar kan hjälpa. :)
14:37 < rooth>n00b: Förstår inte alls vad du menar... =)
14:37 < rooth>n00b: Det finns två skolor på bygget, dns vs hosts.
14:38 <n00b> Oh! Så jag har tydligen valt sida nu då. :D
14:40 < rooth>n00b: dns = dark-side.
14:50 < lazzer>n00b: ;-)
14:52 < rooth>n00b: s#local dns cache#/etc/hosts# =)
14:52 < moggen> hehe HOSTS.TXT revival
14:52 < moggen> var så det började en gång i tiden
14:52 < moggen> innan man uppfann DNS
14:53 < lazzer> Vi måste komma på ett bra system för att dela våra hosts-filer.
14:53 <n00b> A long time ago, in a network far far away...
14:53 <n00b> git repo for shared hosts fil, annan conf?
14:57 <n00b> Finns det någon slags share-mekanism vad gäller grundläggande test
             setup btw? Eller är det för svårt att få till generell grund conf
             för lokal test setup?
15:38 < troglobit> Åh, har ni öppnat DNS-lådan! LOL =)
15:38  * troglobit kör med hosts-fil, såklart ;)
15:40 < lazzer> troglobit: bra val ;-=
15:44 < rooth> troglobit: Jag tyckte det var dags =)
16:00 < moggen> troglobit: upptäckte när jag jobbade hemma att man får "fel" IP på
       om man inte sitter på kontors-IP... hosts ftw.
16:22 < troglobit> moggen: Härligt att se att du sållat dig till den enda sanna läran ;)
16:59 < rooth> =)
17:06 < wkz> moggen,troglobit : another one bites the dust... :)
18:12 < n00b2> Helgen är räddad vpn-dosan återfunnen
20:19 < troglobit> wkz: DNS är en kvarleva av ett döende system. Kom, anslut dig
               till oss istället, vi kämpar för rättvisa, säkerhet, och fria
               statiska /etc/hosts-uppdateringar i galaxen!
20:19 < wkz> troglobit: NEVER!
20:20 < troglobit> wkz: *Feel* the power of the dark side!
20:20 < wkz> troglobit: LOL
20:20 < troglobit> wkz: :-D

Some names have been changed to protect the innocent, the rest are Sith Lords or Jedi Knights.

Awesome: Changing Next/Prev Tune in Spotify

Back to using the Awesome WM in Ubuntu. This time I’m setting up everything from scratch and first up is fixing keybindings to control my main music player: Spotify!

Edit your ~/.config/awesome/rc.lua with Emacs (obviously). If you do not have an rc file, simply copy the system /etc/xdb/awesome/rc.lua:

globalkeys = awful.util.table.join(globalkeys,
           awful.key({}, "XF86AudioRaiseVolume", function () awful.util.spawn("amixer -D pulse sset Master 5%+", false) end),
       awful.key({}, "XF86AudioLowerVolume", function () awful.util.spawn("amixer -D pulse sset Master 5%-", false) end),
       awful.key({}, "XF86AudioMute", function() awful.util.spawn('amixer -D pulse sset Master 1+ toggle') end),
       awful.key({ }, "XF86AudioNext", function () awful.util.spawn("dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next")end),
       awful.key({ }, "XF86AudioPrev", function () awful.util.spawn("dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous")end),
       awful.key({ }, "XF86AudioPlay", function () awful.util.spawn("dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause")end),
       awful.key({ }, "XF86AudioStop", function () awful.util.spawn("dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop")end))

That’s it.

Stray Puppies

Sometimes I just cannot help myself. It’s like finding a stray puppy, or abandonded kitten …

… I recently decided to adopt mini-snmpd since the original upstream site had passed into the great beyond. At this point in my life almost everyone I know can tell you I have no warm fuzzy feels for SNMP, at all. So why did I even consider this to begin with?!

Well, I have to confess that there are certain things that SNMP can be really useful for. Most of it is remote monitoring, and since I work with embedded systems a lot, SNMP can be quite a handy tool.

I first ran into mini-snmpd when I created TroglOS, by forking miniroot, and what struck me immediately was how small and simple it was. The code was also in reasonably good shape, so it had passed my initial quality control. Suddenly one day I could no longer download it when building TroglOS, so I had to do something!

My plans for mini-snmpd are quite humble. I’m currently cleaning it up a bit, adding configure script for all optional features, testing portability to FreeBSD and integrating (good) patches from various sources scattered around the web.

I will not add lots of new features, but as always I’m your humble patch monkey, so if you submit a pull reqeust at GitHub it’ll probably be merged and put into a release.


Summer of Code 2015

Summer is now slowly fading away, and what a summer it has been here in Sweden! For someone who isn’t a fan of the summer heat it has been an awesome time for brain work, and in my case work on my open source projects! :-)

Due to my not really taking much vacation previous years I had saved up for ten weeks (10) this year! It was really worth it, and for the first time in many years I actually feel rested.

So what’s new? Well, this summer I’ve released a major upgrade to pimd, which received PIM-SSM and full IGMPv3 support! Inadyn has seen two releases, one feature release with support for Windows and improved support for custom DDNS providers, and one bugfix release (today). My own FTP/TFTP server uftpd has also got a bit of an overhaul to improve both concurrency and improved support for various popular clients (Firefox and wget) – I released v1.9 of uftpd as a birthday present to myself! ;-)

I’ve done some other minor work as well, on the “new” netcalc, IPv6 and IPv4 subnet calculator, as well as watchdogd and finit. The latter two have however not seen any releases yet, but both have major v2.0 releases with lots of very interesting features that are going to be revealed soon!

For watchdogd several big improvements to system monitoring (loadavg, file descriptors, RAM) as well as a very advanced process monitoring (instrumentation) API is being added. Finit however is the crown in making, it is being converted to support multiple instances of services and to be a fully event driven. I’m extremely excited about Finit!

Oh, and don’t worry … I did manage to get some actual real downtime on the beach as well! ;-)

HowTo: Using -lite With a GIT-based Application

Years ago while looking for a fast init replacement for work, I found Finit. Originally written by Claudio Matsuoka to act as a drop-in replacement for the Asus EeePC fastinit, “gaps filled with frog DNA …”

Until I found Finit I had always been in awe of those venturing into the realm of PID 1. However, learning from the simplicity of Claudio’s code I realized that although PID 1 at times is indistinguishable from magic, it is really not that hard to master. My version of Finit is available on GitHub.

The code is open sourced under the very liberal MIT/X11 license, and much of its frog DNA has proven very useful to me over the years. This blog post is about how that frog DNA can help you fill gaps in your projects …

HowTo: Push to Multiple GIT Repos With One Command

So, now that I have setup as a backup GIT repo to, I needed a simple way of always pushing to both repos – best way for me is to always hook into my regular work flow, otherwise I’d just forget. The git-remote(1) man page describes the new set-url --add sub-command:

git remote set-url --add origin

Now, with a simple git push followed by git push --tags I had now pushed to both the GitHub repo as well as my own server!

HowTo: Apache With Gitweb on Debian 8.1

I’m posting this in case anyone else gets stuck setting up Apache with Gitweb. Also as a reminder to myself in case I ever need to set up this all over again.

  1. You have all your eggs in one basket (GitHub), and
  2. You really like that shiny basket, but
  3. You know you’re clumsy and usually drop baskets yourself.
  4. You are wise (yes you are!) and realize you need another basket, so
  5. You set up a server and a domain yourself …

OK. Let’s start simple, since you are already running the latest Debian you fire up the command line and install the basics:

sudo apt-get install gitweb apache2

So it’ll complain, you’ll clarify your request and soon all required packages are on your server. Now what?

Debian has already set up http://localhost/gitweb for you, and if you have a domain already you should go ahead and edit the master file for that:

editor /etc/apache2/sites-available/000-default.conf
service apache2 reload

If you want to use that for your gitweb needs, then you’re done!

Inetd Support in Finit v1.12

A steady flow of features, and releases, is key to keeping any project alive. Recently I ticked off another item in the Finit TODO list …

Finit v1.12 now comes with a built-in inetd! You no longer need an external inetd daemon to launch services on demand.

The good news doesn’t stop there, this little inetd actually supports a poor man’s tcpwrappers!

inetd ssh/tcp          nowait [2345] /sbin/dropbear -i -R -F
inetd ssh@eth0:222/tcp nowait [2345] /sbin/dropbear -i -R -F

With these two lines in your /etc/finit.conf you tell finit to launch the Dropbear SSH server on demand on port 22 (default ssh/tcp port in /etc/services) on all interfaces except on eth0, which in your case is the Internet (WAN) interface, here you want SSH to run on port 222. Actually, you don’t want port 22 open at all on eth0 … so finit takes care of this for you! Seriously, it just works, no need for messing about with that nasty old iptables anymore!

The original UNIX inetd super server supported many protocols internally, some of which may seem a bit odd today, and some have been superseded by more modern protocols.

Finit currently only supports one internal/built-in standard service, time. It is built as a plugin to serve as an example of how you can extend Finit yourself. The time service can be called either as UDP or TCP. To prevent security issues, the time protocol is disabled by default. To enable it you need two things:

  1. The plugin (built by default)
  2. An inetd time ... line in /etc/finit.conf

Assuming you’ve installed the default set of plugins, the following two lines can be added:

inetd time/udp   wait [2345] internal
inetd time/tcp nowait [2345] internal

This can be very useful for testing the inetd capabilities, your network connection, or simply to get the time to a client where NTP for some reason does not work, or is blocked. For instance, you could have a GPS setup on your server and distribute time to clients with the time protocol.

To use it you need an rdate client. Users of rdate in BusyBox may need to be reminded that it only supports TCP.

$ rdate -pu
Sat Mar  7 08:48:58 CET 2015

For more info on Finit and its features, see the README.

Enjoy! ツ

Finit v1.11 Released!

Update 2015-03-09: This release has unfortunately been yanked due to serious regressions in launching background processes. It has been replaced by v1.12