2010
02.26

Valgrind comprises a bunch of very useful tools for detecting problems with your programs. I first came across it a couple of years back and find it to be excellent. In particular I use its memory profiler, which helps you catch errors such as memory leaks and invalid accesses. In my experience these types of errors sometimes indicate logic errors, not just areas where you’ve forgotten to free some previously allocated memory — which is another reason why it is such a great tool.

I usually invoke Valgrind in a straightforward manner:

valgrind --leak-check=full --show-reachable=yes \
--log-file=/var/tmp/vg_log $YOUR_PROGRAM

These two options generally show me all I need to know.

A while back I wrote a ~2,000 line parsing library in C. Nothing too complex — it parses a configuration file on disk, stores and modifies the details in memory, only writing back to disk when explicitly told to do so by the library client. It used plenty of dynamic memory, and Valgrind was an enormous help when it came to ensuring its correctness, The library is a critical piece of a production system so it needed to be right. And in the two years since it was released there have only been 3 very small changes to the source.

Testing with exec

Sometimes the program you wish to test is actually controlled by other programs on your system, and you would like to Valgrind your program in that environment. Programs stored in /etc/init.d are an example of this.

The question becomes how does one insert Valgrind between the controlling program, and the one you wish to test? A first attempt could be to replace the program you wish to test with a bash script like this:

#!bin/bash
valgrind --leak-check=full --show-reachable=yes --log-file=/var/tmp/vg_log \
$YOUR_PROGRAM-RENAMED-TO-SOMETHING-ELSE

This way the system launches this script when it wishes to launch your program. The script in turn launches your program. The problem with this approach is that the original bash process is between the launching program and your program. Any signals sent by the system will not reach your program — and how your system responds to signals may be an important part of your testing.

How can you address this issue? A colleague at work offered this tip — use the exec call. The script now looks like this:

#!bin/bash
exec valgrind --leak-check=full --show-reachable=yes --log-file=/var/tmp/vg_log \ $YOUR_PROGRAM-RENAMED-TO-SOMETHING-ELSE

I never really appreciated the power of exec until I used it in this manner. exec causes the bash process to be replaced by the Valgrind process, and Valgrind always passes on signals it receives to the test program. The result is a perfect testing environment.

2010
02.10

I cannot praise the revision-control tool git highly enough, and often use it as a buffer between SVN and me. Much of my professional work flow involves fixing a bug here, fixing a bug there — lots and lots of small changes in many different branches. git is the perfect tool for this kind of work. And it is fast.

One of my favourite features is interacting rebasing. This allows you to re-arrange, and even delete, commits in the log. I mostly use this to squash commits together, so the log that the rest of the team sees is much easier to read. One can rebase in a couple of ways:

git rebase -i HEAD~3
git rebase -i <commit>

In the latter case <commit> is the commit you wish to keep. All commits after that one are then presented for rebasing. I like this because it is pretty quick to issue

git log
and note the commit you wish to keep, and then pass this to the command. To use the first form, one more count down commits, and that can be a little tedious at times — the example above shows how to rebase the first 3 commits. Of course, both commands are just different ways of specifying commits.

I am someone who likes to commit regularly, often when I have a small, though significant, change in place. It might even break my build, but having git between me and the corporate SVN repo allows me to do this.

I can continue to work, making commits as I go and then finally finishing the change. Instead of then pushing all those commits to the corporate repo I squash them into one working commit, so I don’t spam the company with multiple checkin messages. This is highly recommended if your work flow is similar.

Amending the latest commit message

Another favourite command of mine is:

git commit --amend

Nothing bugs me more (well, perhaps magic numbers) than a commit message I wrote, that contains a typo. The amend command allows you to quickly fix errors in your latest commit message.

2009
12.10

A colleague at work gave me the idea of storing metadata for each photo on my brother’s site inside its EXIF data. I liked this idea as I originally thought I would need another text file on disk, which described the photos. Tying data to an object by adding it to the object itself is also much more robust. The EXIF worked out pretty well, as I could read the data out using simple code like this on the backend:

<?php
$exif = exif_read_data("$main_pic",'IFD0');
echo $exif['COMMENT']['0'];
?>

But this wouldn’t work with some photos which already had metadata of various types – no data was returned by the php call. I usually set the data using the tools available with KDE, but it seems there are many types of metadata headers in JPEG photos, and some interfere with this code. I ended up using jhead, which is a handy command-line tool for manipulating EXIF data. I used it to strip all metadata from the troublesome photos before re-inserting the EXIF data I wanted. Then it all worked fine.

$ jhead -mkexif cabinet.jpg
$ jhead -ce cabinet.jpg

I suspect I may have been able to tweak the php code to deal with this issue, but in any event I like the idea of having complete control over the metadata.

2009
11.30

I am a Yahoo! Mail Plus subscriber and recently noticed that my outbound e-mail rewrote my name as Philip O&#039;Toole.

Seemingly it had been like this for weeks, but it only caught my attention when I sent an e-mail to my work account. Of course, if you’re a programmer it’s pretty obvious what is going on here. Yahoo!’s code is replacing the apostrophe in my name with the corresponding ASCII code. I tried resetting my name in the Options->General section but it didn’t help. Finally, after setting up a second free Yahoo! account, I worked out where to fix this – under Options->Account. It is there you’ve got to tweak your name settings.

Where to really fix your name in Yahoo! Mail

Where to really fix your name in Yahoo! Mail

This drove me nuts – I was even on to Yahoo! support. This might help someone else out there. I would guess that Yahoo! processed the data on their servers recently, and mangled the names while doing so.

I’ve had various problems with Yahoo! Mail over the last year – perhaps because Yahoo! seems to be a company in turmoil, and is having a hard time keeping it together.

2009
11.30
Yellow Dog Linux on the PS3

Yellow Dog Linux on the PS3

I got around to installing Yellow Dog 6.1 using a DVD of the full distro. The installation went OK, and the installer fired up in graphical mode. However it proceeded to create the swap partition almost immediately because of low-memory concerns.

When it completed YDL was quite zippy – a much, much better experience than I got from FC12. I even had audio.

I may actually use this – it depends if I can get particular media players running on it.

2009
11.28

In between bouts of Wipeout HD, I net-installed 64-bit Fedora Core 12 on my 80GB PS3. Installation with PetitBoot didn’t present any problems, though audio didn’t seem to work. However FC12 is quite slow on my PS3, so I ain’t going to use it – it seems it’s paging to disk a lot.

I knew something was up when Anaconda wouldn’t fire up the graphical installer due to insufficient memory, which made it a pain to customize the software. The other thing I noticed (at least, I think I noticed it) is that FC12 showed the same MAC addresses for both eth0 and wlan0. I actually had to tell it to get a DHCP address from wlan0 before it got network connectivity – and it then got an IP address from my wired router. It seems like FC12 had swapped them.

I might try Yellow Dog Linux next.

Wipeout HD

Wipeout 2097 looks pretty poor compared to this