blahblah has asked for the wisdom of the Perl Monks concerning the following question:

Hi all,

I've been trying to profile a suid CGI script and have been having a lot of problems. Suid programs do not allow the -d flag, which immediately eliminates Devel::DProf and Devel::Profile.
I have managed to get Devel::Profiler running, but it only outputs the subs called in main. This script calls other chunks of perl code with things like
require "modules/foo.pl";
with foo.pl having subs like a, b, and c. Unfortunately the output from Profiler doesn't even seem to know those subs exist.
As a final wrinkle, I cannot run these scripts via the commandline because they are CGIs that require complex user validation and config loading before proceeding to the main code.
Is there an approach I can take to get a usable profile without doing some major hacking and/or without tedious manual profiling?

Thanks.

Replies are listed 'Best First'.
Re: Profiling suid CGIs
by sgifford (Prior) on Mar 11, 2005 at 06:22 UTC
    Just temporarily make the script not setuid, and run it as the user it used to be setuid to. For example, if it's setuid root, su to root, remove the setuid bit, then profile as normal.

    If that's not possible because it would interfere with a running system, make a copy of the script that's not setuid.