Watching long processes through CGI

After slamming my head against a wall for a few hours Friday trying to implement: Watching long processes through CGI

I gave up and left the office. The thing that was really frustrating was that it appeared to be working, and then suddenly, it didn't. And when I even went back and ran Randall's code without any modification, it still didn't work. I was stumped.

Fast forward 12 hours, after some food, some sleep and more searching on google. Here's a clue: It is possible that the original article was written for apache 1.x, not apache 2.x. Anyway, I found a post on where someone was having a similar problem, and they indicated that explicitly closing STDERR and STDIN, as well as STDOUT let the script work as intended.

So here is my diff against the listing in Randall's original article from 2002.

--- col39.listing.txt   2015-03-21 02:01:08.260866239 -0500
+++ /usr/lib/cgi-bin/session_test.cgi  2015-03-21 03:03:34.656454963 -0500
@@ -34,6 +34,8 @@
    print redirect(self_url());
    } elsif (defined $pid) {    # child does
    close STDOUT;             # so parent can go on
+      close STDERR;
+      close STDIN;
    unless (open F, "-|") {
        open STDERR, ">&=1";
        exec "/usr/sbin/traceroute", $host;

Hopefully this saves some other poor schmuck from leaving a bloody dent in their desktop.