29
Jan 09

gethostbyname_r()

Okay, so I can’t really go into too much of the big picture since this is from the day job, but I can certainly tear into gethostbyname_r() a bit.

For part of what we’re doing, we’re sending a RADIUS message using the freeradius project’s radius client library. So, nice and simple (after you’ve done some setup):
[cc escaped=”true” lang=”c”]result = rc_acct(rh, 0, send);[/cc]
Easy enough, right? So it fails. Specifically, it segfaults and since it’s in a multithreaded server, it’s a pain to track down. And I mean a pain. Hours of fun with DDD, gdb, nana and finally printf() lead to here:
[cc escaped=”true” lang=”c”]res = gethostbyname_r(hostname, &hostbuf, tmphostbuf, hostbuflen, &hp, &herr)[/cc]
Ah. gethostbyname_r(), the glibc2-reentrant thread-safe version of gethostbyname(). Except that it’s deprecated, and has the unique property of working differently on just about every machine out there.

And of course, in my machine, and the server, it’s going nuts. Not because of a dodgy parameter or anything like that, though that took a while to confirm, it’s going nuts because of the way /etc/nsswitch.conf is written:

hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4

That’s the standard way to write nsswitch.conf in ubuntu – it first checks the  /etc/hosts file, then uses the avahi daemon, then the DNS system.

Only that’s not good enough for gethostbyname_r(). Grrr. So after a full day bug-chasing through two codebases, the fix is to change a configuration file to this:

#hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4
hosts:          dns files

What a waste of a day! Gah!

I’m going to rewrite the radius-client library to use getaddrinfo() over the next while. I already have to make some changes to it to cope with other things, I may as well help here too I guess. But for today, I console myself by printing out that page of source code and reaching for the matches…


27
Jan 09

Nokia E71

At the moment, I use a Sony Ericcson k750i as my phone. It’s solid, has good reception and audio and battery life. It has an easy-to-use camera with a flash which is important for me because that’s how I record and store whiteboard sessions. It has bluetooth for file transfer (of the whiteboard photos) and hands-free headsets (it’s illegal in Ireland to drive while using a mobile phone, so the headset – and the voice recognition dialing – are quite useful). It has an FM radio and an MP3 player for when I’m on the train. I’ve got Opera Mini installed on it so I can even check my email and websites, though writing anything with T9 is something a sane person only takes on in extremis. It’s even red 😀 It’s been a very good phone for me and I have almost no complaints about it.


Sony Ericsson k750i

Sony Ericsson k750i

But it’s time for a change.

Continue reading →


23
Jan 09

Nominated