Pages

Thursday, September 27, 2007

Wednesday, August 29, 2007

Set Term Title

On MacOSX, the bundled Terminal app won't change the window title as you ssh/telnet, which becomes an issue if you are telnetting to several servers. Of course you could use the prompt to differentiate the connections, but I generally prefer smaller prompts.

To work around, add this to your remote .bashrc

if [ -n "$PS1" ]; then
echo -n -e "\033]0;`hostname`\007"
fi

The PS1 check is just to ensure that in non-interactive sessions (such as the one started by rsync), the echo doesn't corrupts the stream.

Wednesday, April 11, 2007

dbx for gdb users

As an old time gdb fan, I keep getting lost with all the different debuggers i have to deal with for userspace/kernelspace debugging (adb, kdb, kwdb, mdb, dbx). So I thought I would put some working tips for my own reference in this blog post about using dbx

dbx has a gdb mode. It supports most gdb commands. To turn it on, at the dbx prompt, type this

(dbx) gdb on

And as usual, this can be automated by creating a .dbxrc and putting 'gdb on' there.

Now all the gdb commands such as c, b, i can be used.

If you want to step over a few lines of code without recompiling, use cont at

(dbx) cont at 221

will continue the program at line 221, skipping all the code between current line and 221.

r doesn't works for run though, and thats because its already set as an alias to something else.

(dbx) alias
[='\['
alias='kalias'
commands='paged-commands'
echo='kprint'
functions='typeset -f'
help='paged-help'
integer='typeset -i'
lo='loadobject'
nohup='nohup '
pp='prettyprint'
pwd='kprint -r "$PWD"'
r='fc -e -'
sh='sh-cmd'
suspend='kill -STOP $$'
type='whence -v'

But if you wish, you can redefine it to run

(dbx) alias r run

(And to make this permanent, put it in .dbxinit)

dbx also supports histories, accessed as usual using history and !!.

Conditional breakpoints are also supported. To set one, first set a normal breakpoint, e.g.

(dbx) b code.c:2197
(dbx) i b
[1] stop at "code.c":2197
and then make it conditional
(dbx) cond 1 'codePtr->id==12'

(dbx) cond
That's it, for this post.

Wednesday, January 17, 2007

Zen and the art of iCal sync

It appears that the creative zen vision supports the ics format for storing events and tasks, which is version 2.0 of the vCalendar format. This is good news, since I can now sync my google and iCal calendars to the player, without the need to boot into Windows. All that is needed is
  1. Export the ics file from the application (iCal, Mozilla or Google Calendar)
  2. Send the ics to the zen using mtp-sendfile
    $mtp-sendfile ~/Home.ics Home.ics (The second argument is destination filename)
Thats it. Events and tasks would appear in Zen. I even wrote an appleScript to automate this, which i would soon be posting here.

Sunday, January 14, 2007

Creative Zen Vision on Mac (Darwin)

Unfortunately for us, inspite of Zen Vision M being a great device, it doesn't appears as a USB Mass Storage Device. If it would have, we could have simply accessed it as a USB hard-disk in just about any OS without any pain. But then, Creative choose to use MTP instead, maybe because of their special relationship with Microsoft (and then got stabbed in the back when MS released Zune).

Here is some interesting news on MTP from wikipedia, though

Media Transfer Protocol is a set of custom extensions to the Picture Transfer Protocol (PTP) devised by Microsoft, to allow the protocol to be used for devices other than digital cameras, for example digital audio players such as MP3 players, and other portable media devices, for example portable video players.

The USB Implementers Forum device working group is presently working on standardizing MTP as a fully fledged Universal Serial Bus (USB) device class. When that process is complete, MTP will be a USB device class peer to USB mass storage device class, USB Video Class, and so on.

Since that standardisation would take some time, and I suddenly had some free time on hand on fine sunday morning, I decided to try and see what we can still get to work on darwin.

To begin with, I downloaded the libmtp library from sourceforge, which fortunately enough supports mac already and didn't needed any porting, except for an iconv issue. The problem with libiconv is (which is , btw, a library for converting from one charecter set encoding to the other) that there are simply too many versions floating around. So while libmtp compiles and installs fine, any of the example programs won't run, failing with missing symbols.

That was easily fixed though, by adding -liconv to the Makefile in the examples directory in the libmtp sources. (Search for LIBS = -lusb and append -liconv). With this change, running mtp-detect (which installs in /usr/local/bin) gives this output


Autodetected device "Creative Zen Vision:M" (VID=041e,PID=413e) is known.
Connected to MTP device.
USB low-level info:
bcdUSB: 512
bDeviceClass: 255
bDeviceSubClass: 0
bDeviceProtocol: 0
idVendor: 041e
idProduct: 413e
IN endpoint maxpacket: 512 bytes
OUT endpoint maxpacket: 512 bytes
Device flags: 0x00000000
Device info:
Manufacturer: Creative Technology Ltd
Model: Creative Zen Vision:M
Device version: 1.30.02_0.00.16
Serial number: 00023C02FB1FE532E960B05763D234C3
Vendor extension ID: 0x00000006
Vendor extension description: microsoft.com: 1.0;microsoft.com/WMPPD: 10.0;mi
crosoft.com/WMDRMPD: 10.1;
Supported operations:
1001: get device info
1002: Open session
1003: Close session
...
...


Quite a lot of it actually, but here is the more relevant part


3009: MP3
de99: AudioWAVECodec
de9a: AudioBitRate
dc46: Artist
dc89: Duration
dc8b: Track
dc8c: Genre
dc99: OriginalReleaseDate
dc9a: AlbumName
de93: SampleRate
de94: NumberOfChannels
de95: AudioBitDepth
dc91: UseCount
dc8a: Rating
d901: BuyFlag
dc01: StorageID
dc0b: ParentObject
dc02: ObjectFormat
dc04: ObjectSize
dc07: ObjectFileName
dc41: PersistantUniqueObjectIdentifier
dc4f: NonConsumable
dc44: Name
b901: WMA
...
3008: MS Wave
ba05: Abstract Audio Video Playlist
ba01: Abstract Multimedia Album
ba03: Abstract Audio Album
3801: JPEG
300a: MS AVI
300c: ASF
b982: MP4
300b: MPEG
b981: WMV
bb83: vCard3
be03: vCalendar2
3000: Undefined Type
3001: Association/Directory
b802: Firmware


Quite a few formats there.

Unix 101 - Tip

Here's the first post for the new year.

You have a program that creates a file, writes to it and deletes it later. You want to read that file before its deleted. How do you do that? I have been through such situations in the past, and my crude solution often involved writing a shell script that would keep polling for the existence of the file and then copy it, if it exists. Now here is the Unix way of doing this (I found this in imake faq)

Lets say the name of the transient file is xyz. This is what you do

$ touch fake
$ ln fake xyz

Now run the program that creates xyz. When it tries to remove it, since a hard link exists, it wouldn't be able to do so, and you can access the file afterwards !!

Reminds me of the dead.letter and sendmail exploit. Hard links are fun :))