Archive for January, 2008

Going to PyCon 2008!

I’m very excited to be attending this year. I wanted to attend the last couple of years, but had some family matters to attend to. I’m hoping to learn a few things and run into a few people while I’m there. If you haven’t signed up already, click the badge and do so!
PyCon 2008: Chicago

Mail for ipod touch…

I downloaded the software upgrade for my ipod touch so that I could get the Mail application. Unfortunately, our mail servers use a self-signed certificate so whenever the Mail tried to verify the IMAP connection it would pop up a box asking to continue. I hit ‘continue’ and it’d sit there until several minutes later when it would time out. I logged into our mail server and watched the logs and it appears the Mail application was effectively terminating the connection after I hit continue. I decided to hit ‘cancel’ instead and then hit save again. It threw up a disclaimer saying I may not be able to receive mail, but low and behold: when I went to look at my inbox, mail was there! Yay! I’m really liking my ipod touch… too bad I can’t carry it around with me at work. :-(

My first dtrace script…

I had a misbehaving application (I believed it was connecting to the wrong port based on a preference setting), so I figured I’d give dtrace a try and see if I could capture the connect() system call. After a fair amount of tweaking, I was finally able to capture what I was looking for. Here’s the script:

#pragma D option quiet

typedef uint32_t in_addr_t;
typedef uint8_t sa_family_t;
typedef uint16_t in_port_t;

struct in_addr {
  in_addr_t s_addr;
};

struct sockaddr_in {
  uint8_t sin_len;
  sa_family_t sin_family;
  in_port_t sin_port;
  struct in_addr sin_addr;
  char sin_zero[8];
};

dtrace:::BEGIN
{
        /* print header */
        printf(”%5s %5s %-12s %4s %5s %s\n”,
            ”UID”, ”PID”, ”CMD”, ”TYPE”, ”PORT”, ”IP_SOURCE”);
}

syscall::connect:entry
/arg1/
{
        sa = (struct sockaddr_in *) copyin(
          arg1, sizeof(struct sockaddr_in));
        printf(”%5d %5d %-12s %4s %5d %d.%d.%d.%d\n”,
               uid, pid, execname, ”tcp”,
               ((sa->sin_port >> 8) | (sa->sin_port << 8)) & 0xFFFF, 
               sa->sin_addr.s_addr & 0xFF,
               (sa->sin_addr.s_addr >> 8) & 0xFF,
               (sa->sin_addr.s_addr >> 16) & 0xFF,
               sa->sin_addr.s_addr >> 24);
}

And here’s sample output from loading the Slashdot page in Safari:

:: sudo dtrace -C -s snoop-connections.d 
  UID   PID CMD          TYPE  PORT IP_SOURCE
  501 83317 Safari        tcp    80 66.35.250.150
  501 83317 Safari        tcp    80 66.35.250.150
  501 83317 Safari        tcp    80 66.35.250.55
  501 83317 Safari        tcp    80 66.35.250.55
  501 83317 Safari        tcp    80 66.35.250.55

Good idea, bad idea

Good Idea
Have a common dump file format that uses key/value pairs of the form:

key: value\n

Bad Idea
Chose not to have full paths start with a leading ‘/’, so that you end up with oddities like:

Node-path: \n

I figured I’d take a look at Bazaar again, since they’ve made so many performance improvements. So, as a starting point, I decided to see how well svn2bzr worked. So I ran it on a dump file of The Subversion Repository. After some other tweaks to the script, I managed to get to revision 26429 where it choked:

Traceback (most recent call last):
File “./svn2bzr.py”, line 1086, in
main()
File “./svn2bzr.py”, line 1079, in main
opts.prefix, opts.filter)
File “./svn2bzr.py”, line 1001, in svn2bzr
dump = Dump(dump_file)
File “./svn2bzr.py”, line 662, in __init__
self._read()
File “./svn2bzr.py”, line 900, in _read
field, value = line.split(’: ‘, 1)
ValueError: need more than 1 value to unpack
Exception exceptions.OSError: (2, ‘No such file or directory’, ‘/var/folders/9W/9WK-dXFfH2eMq+dEVqJZg++++TI/-Tmp-/tmproKrc3-saved-trees’) in > ignored

Classic sign of expecting a value to be there, only to find out it’s not. :-( Turns out the empty Node-path is technically correct, since it was the root of the repository that was modified. It got there because a merge ticket was written as a property of the root directory by SVK in r26429. However, we really should have included a leading slash in the node paths to prevent having an “empty” value. I guess hind-sight is always 20/20.