Categories
Uncategorized

Recalcitrant CGI problems

One of the most useful tools in my box of diagnstics is strace (aka ktrace on FreeBSD or truss on Solaris). Right now, I’ve got a Perl CGI script that’s failing and I don’t know why. It would be useful to see what it’s doing in terms of system calls that’s making it fail.

Unfortunately, that could potentially be problematic with strace. It needs to attach to a new process by starting the command line, or by attaching with the -p flag. But I don’t want to attach to Apache, it will have far too many child processes and I don’t know which one will handle my request. And there’s no convenient point for me to tell apache to run my CGI script with strace in front.

Thankfully, a small amount of Perl can make it all happen. Stick this as the first thing in the file.

BEGIN {
    local $ENV{PATH} = '/bin:/usr/bin:/usr/local/bin';
    system "strace -o strace.out.$$ -p $$ &";
    sleep 1;
}

Now, any time that I run the script, I’ll get a log of exactly what it did.

2 replies on “Recalcitrant CGI problems”

It would be even better if it actually showed me the root cause of the problem. Unfortunately, it turned out that I had suexec configured in to my apache without realising. That was stopping me dead in my tracks. :-(

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s