Older blog entries for gdvieira (starting at number 29)

Munin and Postfix

One more in the ongoing series "patches that make the world go round". If you happen do use the excellent Munin to monitor your servers and use the Postfix plugins, you may have noticed that Munin 1.2.5 introduced a bug in the postfix_mailstats plugin. The bug report and fix is here.

Remember people: release early, release often!

Syndicated 2007-12-15 16:00:15 from Gustavo M. D. Vieira

OpenSER 1.2.2 PostgreSQL Driver Patch

I run a personal SIP server powered by OpenSER. Actually, calling something a SIP server is a bit of oversimplification as the protocol and actions associated with it are fairly complex (as far as I know, I run a SIP proxy and location server). All this to say that OpenSER uses a relational database to store its data, as do all classy enterprise software out there.

So far, so good, but when it comes to relational databases I like using PostgreSQL instead of the OpenSER default MySQL. Why? Because I know how to use it! Problem is, the last stable release of OpenSER (1.2.2) has a serious bug in the PostgreSQL driver, making it impossible to use. It's a pity no one bothered to do a brown bag release because of this issue. Not being the default database really turns you into a second class citizen. Anyway, the fix is already in the OpenSER SVN, but I will post the patch here, to those that want to stick to the released version.
diff -ru openser-1.2.2-tls.orig/modules/postgres/db_res.c openser-1.2.2-tls/modules/postgres/db_res.c
--- openser-1.2.2-tls.orig/modules/postgres/db_res.c    2007-08-16 11:23:05.000000000 -0300
+++ openser-1.2.2-tls/modules/postgres/db_res.c 2007-11-25 08:23:53.000000000 -0200
@@ -572,6 +572,7 @@
         * If this is not done, a memory leak will happen.
         */
        for (col = 0; col 

The silver lining in this was that it was quite easy to find a solution to this problem. Before OpenSER I used for some time the original SER, and I can tell you, it is almost impossible to find some help on the web. Both because SER is a lousy name to base a Google search :) and because the project isn't quite transparent as a proper open source project should be. So, congratulations to the OpenSER developers! And remember, release early, release often!

Syndicated 2007-11-25 20:03:29 from Gustavo M. D. Vieira

Really Obsolete RPMs

The version of K9Copy packaged by Livna is now newer than the one I maintained, so I'm officially taking it down.

Syndicated 2007-11-25 19:20:41 from Gustavo M. D. Vieira

Obsolete RPMs

Both OpenMSX and K9Copy now have official RPMs for Fedora. OpenMSX is part of the main distribution, just execute yum install openmsx. K9Copy is packaged by Livna, go there and install their repo.

As my version of K9Copy is newer than the one packaged by Livna, I will keep it a bit longer. When Livna catches up, I will remove it from the site. See, I actually like being obsoleted. :)

Syndicated 2007-10-05 20:57:53 from Gustavo M. D. Vieira

Emacs And Cedilla

This one is for the "unlikely bugs" section. If you use the magic combination of Emacs 22, a US keyboard and dead keys in a UTF-8 locale, the combination ' + c will give you ć instead of ç. Of course, this is a bug only if you want ç and not ć, so please forgive my ç-centrism. No offense intended to ć-using languages, whatever they may be. :)

GTK2 had this same bug about 5 years ago, and they solved it by creating the "cedilla" input method, and selecting it according to locale. Guess the Emacs guys will have to go the same route. Meanwhile, a simple workaround is to fire up Emacs in a ISO-8859-1 locale: "$ LC_ALL=pt_BR emacs" and as soon as the program opens up, select "Options|Mule|Set Language Environment|UTF-8". It isn't pretty, but as I use the US keyboard only rarely this works for me.

Syndicated 2007-10-03 17:04:44 from Gustavo M. D. Vieira

DSPAM Hash Driver Patches

I use the fantastic DSPAM SPAM filter in my mail server. I like it very much, specially when using the built-in hash-based storage, making it very fast and really easy to setup. That is, if the documentation and administration tools weren't so lacking. On the plus side, I got to know a little better the tool that keeps my email sanity and respect the developers that make it happen.

If you are an user of the hash driver, you can't rely on the provided tools to maintain your installation. The recommended way of cleaning old messages signatures doesn't work for this driver. Also, the hash-based database has to be cleaned from time to time or it will grow too big, but the tool to do it (cssclean) just doesn't work. To handle these problems, I first had to patch DSPAM so I could get a working cssclean. The main patch was created by Frank Cusack and you can get it in his aptly named message "cssclean is a redheaded stepchild" to the dspam-dev mailing list.

The second patch isn't strictly necessary (and I fear it might violate some design principle of DSPAM), but it keeps cssclean from resetting the statistics of the database. I really can't remember where I found it, so I post it here:

diff -ru dspam-3.8.0.orig/src/tools.hash_drv/cssclean.c dspam-3.8.0/src/tools.hash_drv/cssclean.c
--- dspam-3.8.0.orig/src/tools.hash_drv/cssclean.c      2006-05-27 18:00:36.000000000 -0300
+++ dspam-3.8.0/src/tools.hash_drv/cssclean.c   2007-06-27 19:18:51.000000000 -0300
@@ -167,7 +167,7 @@
     header = offset;
     filepos += sizeof(struct _hash_drv_header);
   }
-
+  bcopy (old.header, new.header, sizeof(struct _hash_drv_header));
   _hash_drv_close(&new);
   _hash_drv_close(&old);
   rename(newfile, filename);

Finally, I run the following script monthly using cron:

# Clean hashes and signatures.
for u in /var/lib/dspam/data/*/*.css; do
    /usr/bin/cssclean $u
done
find /var/lib/dspam/data -name *sig -type f -mtime +30 -exec rm -f {} \;

Probably you will have to adapt it to the file locations of your DSPAM installation.

Syndicated 2007-10-02 20:19:26 from Gustavo M. D. Vieira

K9Copy 1.1.3 RPM

I've updated my RPM package for K9Copy to the 1.1.3 release. Get it here.

Syndicated 2007-08-29 14:46:47 from Gustavo M. D. Vieira

High Resolution Timer in Java 5

Last week I needed to generate (somewhat) high-frequency recurring events in Java for my thesis work. Nothing like real time, just call a method from 10 to 1000 times per second, but I want to able to tune it so it can run at a precise frequency in this interval. Should be easy, right? In theory it is: discover the period of recurrence, do the action, sleep the remaining time until the next occurrence. For example: if I want to generate 500 events per second and my action takes 200µs, then my period is 2ms and I must sleep 1800µs between executions.

So, I need microsecond precision for the sleep. It is widely known that this is impossible in Java 1.4 without some native code. Fortunately, in Java 5 it's pretty easy to get nanosecond precision and this blog entry is very, very informative. Briefly, if you want to measure a time delta with nanosecond precision use System.nanoTime(), if you want to schedule a (possibly recurring) event with the same precision use the ScheduledThreadPoolExecutor class. I ended up using the former for my code.

But now, the weird part. Along with System.nanoTime(), Java 5 introduced the Object.wait(millis, nanos) and Thread.sleep(millis, nanos) methods for high resolution sleeps. Take a look at the source code for the implementation of these methods here (gotta love free software!). See. These methods just round up or down the millisecond argument using the nanosecond argument and call the millisecond only version of the methods. It took me some time and a bit of frustration to notice this. Annoying. You might be wondering: how the heck is ScheduledThreadPoolExecutor implemented then? The answer is another sleep method introduced in Java 5: LockSupport.parkNanos. This one actually works, as it uses a different native implementation.

Syndicated 2007-08-28 14:47:33 from Gustavo M. D. Vieira

Jaitime.org Fedora Core 6 Image Fix

My VPS provider uses Xen and the distro images from Jailtime.org. Recently I installed a fresh Fedora Core 6 image (as they don't have a Fedora 7 image) and found a very subtle bug.

In the tweaks section of the FC6 image at Jailtime.org it is said:

To resolve tls issues, issued the following commands (*):
  # cp /lib/i686/nosegneg/lib* /lib/i686/
  # ldconfig

The problem with this hack is that when you upgrade your glibc, the copied files will remain and will conflict with the new updated files. This is not theoretical, right now if you download and run the image, then execute yum upgrade your VM is hosed. End result, segmentation faults all around and you VM won't boot anymore.

To avoid the problem, remove all files copied into /lib/i686:

# rm -f /lib/i686/libpthread* /lib/i686/libc* /lib/i686/libm* \
        /lib/i686/librt* /lib/i686/libthread_db*

The alternative to fix TLS problems is proposed on the Jailtime.org site itself:

An alternative to the tweak above is to use the following commands:
  # echo "hwcap 0 nosegneg" > /etc/ld.so.conf.d/libc6-xen.conf
  # ldconfig

But it came with the cryptic warning that "This alternative did not work in the jailtime image however". Well, it does work with the Jailtime.org image.

By the way, after this issue was solved, I was able not only to update FC6, but to upgrade to F7 using Yum. The only extra step necessary is to make sure in the newly installed /etc/rc.d/rc.sysinit has the /sbin/start_udev line is commented out. Also, for some strange reason, the libgcc and libstdc++ packages have a higher version number in FC6 than in F7, so you will have to update these two by hand. Besides that, just follow this procedure.

Syndicated 2007-07-24 16:47:33 from Gustavo M. D. Vieira

Philips MCM108 Remote Bug

Recently I bought a Philips MCM108 compact stereo. It's a simple device, that works really well as an alarm clock. But it got a UI bug that's really annoying. The remote, for some bizarre reason, operates in a mode oriented fashion. That is, it only sends CD commands when you are in "CD mode". Problem is, you can enter "CD mode" from the main device itself, obviously without authorization from the remote. The end result is that you believe you remote is broken because you can't change albums, stop or start CD play. The solution? Every time the remote becomes catatonic, press the CD button to remember it of its sole purpose in life.

Syndicated 2007-07-02 22:13:22 from Gustavo M. D. Vieira

20 older entries...

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!