Low-life init.d

Description

I'm running some daemons on my workstation as my login user (as opposed to root), such as lirccd and phoned (see index.html), and although I didn't like to start them manually every time I rebooted my workstation, I couldn't think of a good, clean, fast, easy and system consistent mechanism of letting users start programs at system boot up.

Therefore, I left out the fast and easy parts and made a complete system for such things. (Sure, it's pretty small, so it was pretty fast and easy, but not quite as small as I originally had in mind)

Its function is that all regular files in /etc/rc.d/userinit.d are executed as the UID and GID of the file itself, doing all the standard login stuff. All the user's auxiliary groups are added as well, but the new process' primary GID will be that of the file.

I recommend installing it like this (on a RedHat system, check your system to see if modification is needed before proceeding):

gcc -O2 -g -o userinit userinit.c
cp userinit /etc/rc.d
mkdir /etc/rc.d/userinit.d
chmod 1775 /etc/rc.d/userinit.d
chown root:users /etc/rc.d/userinit.d
echo '(cd /etc/rc.d; ./userinit userinit.d)' >>/etc/rc.d/rc.local

I think it's all secure, but since my system is single-user, I haven't done any exhaustive tests, so don't rely on it.

If you look at the code more closely, you can see that I wrote this in bed... Like the S_ISREG(st.st_mode) || S_ISLNK(st.st_mode) part when I called stat (as opposed to lstat). I remember that a faint thought flew through my brain saying "Do you really need if to check a file is a symlink when you stat it... that seems strange...", but I was too sleepy to think more about it. At least it works (kind of). =)

Files

Valid XHTML 1.1! Valid CSS! This site attempts not to be broken.
Author: Fredrik Tolf <fredrik@dolda2000.com>
Last changed: Wed Sep 22 05:13:56 2004