Wednesday, November 28, 2007

Pipe redirection screwing up exit status?

Have you ever been in a situation where you wanted to filter the output of something in bash. A first guess attempt might look something like this:

./some_command | sed "s/foo/bar/"

However, this has a significant limitation. If you were interested in the exit status, you would only get the exit status of the last command (the sed command in this case)

./some_command | sed "s/foo/bar/"
echo $? # returns exit status of sed

I learned this the hard way doing some scripting last year for a customer where I wanted to pass the output through /usr/bin/tee to log it to a file as it ran. All of a sudden everything started "working", in that all commands returned zero because I was actually getting the return code for /usr/bin/tee.

It turns up in Bash 3.0 and higher, they added an option called "pipestatus", which gives you the exit status of the first command to exit non-zero. Very helpful.

set -o pipestatus
./some_command | sed "s/foo/bar/"
echo $? # returns exit status of ./some_command

Unfortunately, it's not portable beyond bash and ksh93.

Tuesday, November 27, 2007

Thanksgiving wrapup

Went to New Jersey to celebrate Thanksgiving Day with Victoria's Aunt/Uncle/Grandmother. Was nice to see them all. Afterward we went over to Lauren and Greg's and played Scrabble. Lots of fun.

Friday had lunch with Mom and Grandma. Took it easy at Mom's the rest of the day. Leftovers Friday night with Vikki back at her Aunt's.

Went to the hospital at 5:30am on Saturday after collapsing from dehydration (gastroenteritis). Spent the next two days in bed feeling like crap. Got back to the city on Monday afternoon.

Plans to see Aunt Cyndi and hang out with Marc didn't work out after I got sick. Very annoying.

Have a release tomorrow, so spent most of the day catching up on email, fixing bugs, and dealing with documentation issues. Got home at 10:15.

Monday, November 19, 2007

Perl debugger source tracking of eval() blocks

So a few months ago I had been doing some work on the Perl DBGP stub written by ActiveState, and I had a number of problems with locating source code references properly in eval() blocks.

Was browsing the Perl delta for 5.8.8, and noticed this little one-liner:

The debugger now traces correctly execution in eval("")uated code that contains #line directives.

Now I don't know that that is a fix for the problem I slaved over for days, but we are running 5.8.7 and I do rely on #line directives to keep track of source locations in eval blocks (which is how almost all my code is compiled). Kind of makes me wonder if maybe I should get 5.8.8 and see if all my problems go away...

Sunday, November 18, 2007

Brick Township 3rd Safest city in the country

This is kind of contrary to my experiences living in Brick, but apparently it's the third safest city in the country:

http://www.cnn.com/2007/US/11/18/dangerous.cities.ap/index.html

Played with MythTV yesterday. Got my Windows XP system running and was able to successfully capture traffic off the USB bus from my Hauppauge HVR-950. Also got my Nintendo emulator running under Ubuntu. Discovered that the open source NV driver REALLY sucks at OpenGL. The X11 process was burning 100%+ of the CPU. Installing the binary driver brought it down to 4%.

Had dinner with Victoria last night at Vegetarian Paradise 2 down in the Village. Had the best chicken fingers and french fries ever (it was soy chicken). Ate the leftovers today for lunch. Yummy.

We went to the Container Store and Bed Bath and Beyond today [beware the beyond!], and I picked up some shelves for my closet. Wohoo. Met up with Leah and Brad for Indian food tonight, and played some Sequence for the first time in quite a while.

Funny Cat and Girl

http://catandgirl.com/view.php?loc=533

Friday, November 16, 2007

Profiling Perl with Compuware BoundsChecker

I finally got around to trying out the Perl core under BoundsChecker. Because Perl does not have an MSVC project file, it was a bit tougher than many Visual C++ programs.

Fortunately, BoundsChecker does support command line profiling, albeit it is nowhere as easy as their graphical interface for setting up instrumentation (as would be expected).

Change the CC and LINK32 lines in Win32/Makefile to refer to "nmcl" and "nmlink" instead of "cl" and "link":

#
# Programs to compile, build .lib files and link
#
#BUILDOPT = $(BUILDOPT)
#CC = cl
CC = nmcl /NMtxOn
#LINK32 = link
LINK32 = nmlink /NMtxOn
LIB32 = $(LINK32) -lib
RSC = rc

Note that in the above case, I also added "/NMtxOn" to enable performance profiling as opposed to error checking. If you are just interested in errors, you can exclude that option (but be sure to exclude it for both CC and LINK32 or else you get some nasty errors).

Also uncovered a edge case where Perl does not build XS modules properly if using BoundsChecker. This is related to the way ExtUtils determines which compiler you are using. Because BoundsChecker relies on wrapping "cl.exe" around its own binary (called nmcl.exe), changing the CC directive in the makefile interferes with the compiler detection in Perl. Unfortunately, this manifests itself not as an error in determining the compiler but rather as a failure to setup EXTRALIBS and LDLOADLIBS properly.

The fix is to add a update lib/ExtUtils/LibList/Kid.pm to treat both cl.exe and nmcl.exe as being Visual C++.

diff.exe -u Kid.pm.orig Kid.pm
--- Kid.pm.orig 2005-10-21 07:44:36.000000000 -0400
+++ Kid.pm 2007-11-16 11:03:42.664799500 -0500
@@ -227,7 +227,7 @@
return ("", "", "", "", ($give_libs ? [] : ())) unless $potential_libs;

my $cc = $Config{cc};
- my $VC = $cc =~ /^cl/i;
+ my $VC = $cc =~ /^cl/i || $cc =~ /^nmcl/i;
my $BC = $cc =~ /^bcc/i;
my $GC = $cc =~ /^gcc/i;
my $so = $Config{'so'};

Once I did the above, I was able to generate profiles for Perl:

"c:\program files\compuware\devpartner studio\analysis\dpanalysis.exe" /perf /O c:\perl\bin\foo.dpprf /EXCLUDE_SYSTEM_DLLS /p perl foo.pl

Note that if you do not include the "/EXCLUDE_SYSTEM_DLLS", you will get errors saying "Unable to locate winsock library!"

To do error checking I used:

"c:\program files\compuware\devpartner studio\boundschecker\bc.exe" /b foo3.DPbcl perl foo.pl


Here is a pretty snapshot of a performance profile (click on it to expand):

Wednesday, November 14, 2007

XO laptop commercial on Fox 5

Saw a commercial last night on network television for the Give One, Get One program that is running for the next couple of weeks.

For those of you not familiar with the One Laptop Per Child project, it's an MIT initiative started a few years ago by Nicholas Negroponte. It's also been otherwise referred to as the "$100 laptop" since that is the target price point. The program is targeted at providing children in third world nations with the tools necessary to stop being third world nations.

On the technical side, it's a really cool piece of hardware. While it's slow in performance compared to typical laptops, it's a ruggedly designed piece of hardware with Wifi and mesh networking, a display you can read in broad daylight, flash memory in place of a hard drive (so no disk crashes), and it's entirely open source (Linux based kernel even with open source firmware). It also supports various ways to provide power as opposed to a power cord, including a hand-crank and a solar panel.

In a number of ways, it's better than laptops you can buy commercially.

The program running for the next couple of weeks is an opportunity to buy two laptops, one of which is sent to you and the other is sent to a child in a developing nation. It's also includes a free year of T-Mobile Wifi hotspot access, which in and of itself would normally cost $29.99 per month. So if you were thinking of getting T-Mobile for $360 for the first year, it's not too far off to spend $399 and get a free laptop to go with it (oh yeah, and get a laptop to someone who **actually** needs one).

Monday, November 12, 2007

Sunday, November 11, 2007

Pic of the day 2007-11-11



Vikki crushed me at scrabble. She lead off on her first turn with "succulent" for 94 points (triple word score plus a bingo). Doh.

Friday, November 9, 2007

Deja vu

So I got a report of a crash today that I tracked down to the Perl interpreter memory allocator:


void* VMem::Malloc(size_t size)
{
2808308A push esi
2808308B mov esi,ecx
#ifdef _USE_LINKED_LIST
GetLock();
2808308D mov eax,dword ptr [esi]
2808308F push edi
28083090 call dword ptr [eax+0Ch]
PMEMORY_BLOCK_HEADER ptr = (PMEMORY_BLOCK_HEADER)m_pmalloc(size+sizeof(MEMORY_BLOCK_HEADER));
28083093 mov eax,dword ptr [esp+0Ch]
28083097 add eax,0Ch
2808309A push eax
2808309B call dword ptr [esi+34h]
2808309E mov edi,eax
LinkBlock(ptr);
280830A0 lea eax,[esi+4]
280830A3 pop ecx
280830A4 mov ecx,dword ptr [eax]
280830A6 mov dword ptr [eax],edi
280830A8 mov dword ptr [edi],ecx
280830AA mov dword ptr [edi+4],eax
280830AD mov dword ptr [edi+8],esi
280830B0 mov dword ptr [ecx+4],edi
FreeLock();
280830B3 mov eax,dword ptr [esi]
280830B5 mov ecx,esi
280830B7 call dword ptr [eax+10h]
return (ptr+1);
280830BA lea eax,[edi+0Ch]
280830BD pop edi
280830BE pop esi
#else
return m_pmalloc(size);
#endif

}

EAX = 012C18DC EBX = 01FFFFFB ECX = 21264468 EDX = 0000000A
ESI = 012C18D8 EDI = 00000000 EIP = 280830A8 ESP = 0271DC70
EBP = 0271DCA4 EFL = 00000246

And as I'm looking at this, I'm thinking to myself, "doesn't this look familiar?". So I did a search, and came up with the following:

http://rt.perl.org/rt3//Public/Bug/Display.html?id=42648

Then it occurred to me, "oh yeah, it's familiar because I ran across this seven months ago and submitted a patch to Perl core for it." It turns up though that I never checked it in to my own company's source code repository.

So as Dan put it, "You fixed it for everyone in the universe except for us."

Doh.

Wednesday, November 7, 2007

Pic of the day 2007-11-07



Me, Patrick, Joe, and Packy getting some Thai food at 23rd and 7th...

Tuesday, November 6, 2007

Pic of the day 2007-11-06



This is the coat rack I bought for the office today after spending a couple of years getting my coat caught under the wheels of my chair... Bed Bath and Beyond $39.95.

Monday, November 5, 2007

Pic of the day 2007-11-04



This one goes out to the scamsters at Liberty Names of America....

Today I received an "invoice" informing me that my domain name was going to expire and offering me the opportunity to renew. Except Liberty Names isn't my registrar. What a scam. Not only are they trying to steal customers who don't know any better from other registrars, but they are charging three times the price that you could get from GoDaddy.com ($29.00 per year as opposed to GoDaddy's $9.95).

Obviously it dupes lots of people.

Better Business Bureau entry on them:
http://search.buffalo.bbb.org/codbrep.html?ID=17003127

Note to self: double check my transfer lock.

Sunday, November 4, 2007

Pic of the day 2007-11-04



Victoria's cat, Marilyn.

Halloween party pictures

Finally uploaded the pictures from the halloween party I went to last week with Victoria:



Just click on the image above to see the full gallery...

Friday, November 2, 2007

Pic of the day 2007-11-02



This is the really cool mug that Vikki bought for me from FAO Schwarz two weekends ago.

Thursday, November 1, 2007

Pic of the day 2007-11-01



So you might be asking yourself, why dedicate today's picture to Newsweek? Maybe it's because nine year old girls in gas masks are cute. Maybe it's because I like peanut butter sandwiches. Or maybe it's because I'm wondering why I am still getting Newsweek when my subscription expired two months ago...