Strace CGI Scripts
Imagine the following scenario: After a software upgrade, your CGI programs no longer work. Unfortunately, the program is only available in compiled form and the log it writes is not sufficient to solve the problem.
How about debugging the program with strace?
strace traces system calls and signals and allows you
to easily find out if some file or library is missing.
Using a simple wrapper script, you can strace the CGI program as if it was started by the web server. This ensures that the program runs exactly in the environment where the problem comes up.
Rename your original binary from program to
program.orig and store the following
wrapper script as program:
#!/bin/sh /usr/bin/strace -f -o /tmp/strace.$$ bash -c "exec -a $0 $0.orig \"$@\""
The output of strace will end up in the file
/tmp/strace.$$. exec -a replaces
argv[0] with the original name of your program. Like
this, your program is started exactly as it would be without the
wrapper script.
History
- 20050905 First version of this document.