Archive for August, 2005

APR Hello World

Posted on August 17, 2005, under apache, general.

I went googling for a “Hello World” for the Apache Portable Runtime library, trying to track down a presentation Paul Querna gave at ApacheConEU and was surprised to find that I not only didn’t find his presentation, but couldn’t find any obvious “Hello World” example on-line.

Tracking down Paul’s presentation wasn’t hard, but to try and help anyone else who Google’s for it, here’s the code, taken directly from Paul’s presentation:

#include "apr.h"
#include "apr_file_io.h"
#include <stdlib.h>  /* For atexit() */

int main(int argc, char *argv[])
   apr_pool_t *p;
   apr_file_t *fp;
   apr_pool_create(&p, NULL);
   apr_file_open_stdout(&fp, p);
   apr_file_printf(fp, "Hello World" APR_EOL_STR);
   return 0;

While I’m posting it, I might aswell fill in the only blank for total newcomers to APR. Once configured, built and installed, APR will install the apr-1-config utility into $prefix/bin/. This utility tells you the exact arguments you need to use for compiling, linking and so on. For example, to compile helloworld.c;

gcc `apr-1-config --includes  \
    --cflags --cppflags --link-ld --libs`        \
    -o helloworld helloworld.c

Once compiled, you’ll have to make sure that is in your LD_LIBRARY_PATH or in one of the directories has been configured to automatically search for libraries. That’s it.

colmmacc@lasaire:~$ ./helloworld
Hello World

If you write C, and you have portability requirements, it might be worth taking a good look at APR. It provides a lot of reliable abstractions for aiding portability, from simple things like a portable getopt to unified file-system and networking layer API’s. It saves me a lot of effort.

Dirvish, mod_ftp, mod_cache

Posted on August 17, 2005, under apache, general.

After an accident with mutt yesterday, I finally got around to setting up proper backups for loughan, the server this blog (amongst other things) is hosted on. With some help (or rather config stealing) from Brian Scanlan, we now have snapshot-like backups using dirvish, which means we can recover from stupid user mistakes aswell as cope with disk failures.

Its configuration format is truly bizarre, but once you get over it it’s a powerful backup tool which will maintain snapshots efficiently (using hard-links). Highly recommended, especially when you don’t have the budget for a real backup/restore system.

In other news, mod_ftp is progressing and incubation should start soon. Although mod_ftpd is out there, mod_ftp is coming from Covalent and has a lot of real-world deployment and features. It will probably be running on within a few days of incubation.

My own little plan is to make caching and proxying working, which will mean that we can cache often requested files as we do for HTTP, but also that in the future we can build a front-end load-balanced cluster serving HTTP and FTP but retrieve content via HTTP, acting as reverse proxies. Probably not all that useful to the general world, but I’ll be making it work.

To that end, I’ve been looking through


in httpd’s trunk and cleaning it up. It’s surprising just how many boundary cases you can find when you start testing things thouroughly.

All of this means that the graceful stop work has been put on the backburner a little. I have the worker MPM in a state where it will stop gracefully, but it keeps a hold on the Listening TCP port, which won’t do. I’d like the port to be immediately free, just like sshd does with its graceful stop. I have a tingling suspicion that win32 is going to be an awkward case.