the djb way


the syncdir fix

Version: syncdir-1.0
Download: syncdir-1.0.tar.gz
MD5 (syncdir-1.0.tar.gz) = cd640b49fbfd7037f3b74921b67f7409
Build type: manual
Other: GPL

In the section on pre-installation preparation, we noted the specific filesystem characteristics necessary for qmail's queue in /var/qmail/queue. There we mentioned that a stock qmail installation isn't completely safe on current Linux filesystems.

Linux makes a great qmail platform, though, and there are several ways to make sure that system calls to link() are fsync()'ed to disk immediately. One effective and reliable solution is to use Bruce Guenter's "Synchronous Directory Library", called syncdir.

This is what we refer to as the syncdir fix for qmail.

First, snag the syncdir tarball from the link above into a local repository (right-click, wget, whatever). For the purposes of this procedure, we will show the source archive saved in /usr/local/djb/dist-other.

Unpack the syncdir archive into the build directory:

# cd /usr/local/djb/build
# tar -xzvf ../dist-other/syncdir-1.0.tar.gz

Change into the syncdir-1.0 directory and build the syncdir library with GNU make:

# cd syncdir-1.0
# make

Now, copy the static library named libsyncdir.a into the unpacked qmail source tree:

# cp libsyncdir.a ../qmail-1.03/

Change into the qmail source directory, and edit the file named

# cd ../qmail-1.03
# vi

Edit the second line of the file to look like this (text to be added is shown below in bold):

echo 'main="$1"; shift'
echo exec "$LD" '-o "$main" "$main".o ${1+"$@"} -L. -lsyncdir'

If building qmail for the first time, apply the patches you need as described earlier on the installation page. Linux systems will surely require the errno patch:

# patch -p1 < ../../patches/qmail-1.03.errno.patch

Then build (or rebuild) qmail:

# make

The usual compiler messages will tumble down the screen. When it's done, your syncdir-enabled qmail binaries are ready to install.

If you are already running qmail services, shut them down first:

# svc -d /service/qmail-*

Then install (or reinstall) qmail:

# make setup check

Now you are ready to install your qmail services. If they are already configured, go ahead and start (or restart) them now:

# svc -u /service/qmail-*

In the event of untimely power failure or other disaster, your qmail queue on Linux should now be more resistant to data loss due to unexpected shutdowns. Of course, this is only but one of the many pieces that go into creating a reliable qmail service. Don't forget to consider other stuff like hardware quality, redundant disk arrays, and battery-backed power supplies.

bsd notes

BSD users (that is, FreeBSD, OpenBSD, etc.) may also want to apply the syncdir fix. Who knows why you would want to, but it seems like it should at least be harmless.

For qmail servers in real life, of course, best not to mess around: DON'T DO THIS. At least not until we get some more definitive and informed opinion around here. (It would be nice to know, for instance, if syncdir enables the safe use of "soft updates" on the /var/qmail/queue partition.)

If you want to try it out anyway, just follow the procedure described above, with the following modifications.

First, edit the syncdir.c source file and change the line with the syscall.h include from:

#include <syscall.h>


#include <sys/syscall.h>

Then, use GNU make --usually invoked as gmake-- instead of BSD make to build the syncdir library.

The rest of the steps are the same as above.

Do you have any experience with syncdir on BSD? Please let us know:

Copyright © 2004 Wayne Marshall.
All rights reserved.

Last edit 2004.01.14, wcm.