Personal restarters and ctrun(1)

(I know I need to wrap up the cal(1) contest. I also need to finish about three smf(5) blog entries. I am also mostly keeping up with the forum/list/newsgroup traffic on smf(5). I also have a few more bugfixes to get into Solaris 10 first. But a small dispatch seems necessary.)

One of the neat things about GNOME is that it provides restarter operations for specified applications—your application references a bad address and dies, it gets restarted. I’m pretty attached to ion, however, and don’t really need all of the GNOME environment all the time. But I do want restart for a couple of applications in my session.

For instance, I wrote a little C program, osdclock, using libxosd that displays the date, the time, and those of my mail folders containing new mail. It looks like this:

Upper right-hand screenshot

Occasionally, and for reasons I lack the time to debug, new ion workspaces will obscure the on-screen display. Rather than write code into osdclock to call exec(2) (of itself) on a received signal, it’s easier to use the new commands associated with the contracts subsystem of Solaris 10, specifically the ctrun(1) command. By adding the invocation

/usr/bin/ctrun -r 0 -o noorphan -f signal,hwerr $HOME/bin/osdclock &

to my .xinitrc file, I get an osdclock that is restarted from any fatal external signal (or an uninterceptable hardware error of some kind), but is not restarted if a core file is generated (from a software error) or if the ctrun process is itself killed (like on session exit). So I avoid a home directory filled with core files. (You are using coreadm(1M) to have a meaningful core dump pattern, right?)

Since the cause of restart is ctrun‘s awareness of the process contract becoming empty, this same ctrun invocation could be used with an application that prefers to daemonize, like a personal web proxy. It could also be used to set up a restartable group of processes, like an application suite or widget collection. (ctrun has some other interesting options, and is a versatile lightweight restarter on its own—try it out.)

Having applications always available leads to predictable computing, but I think a more dramatic way to express it in this medium (but imagine appropriate stormy weather sound effects) would be

<mad_scientist>Restarters, restarters everywhere! <mad_scientist>