I might be wrong, but using "exec" directly in CGI script is not very good idea. The "exec" simply replaces current binary with new binary, it does not terminate the process, so the Web server shall wait for this new binary to finish its work, and that might be undesirable.
The appropriate way would be to do fork then exit the parent and do exec in the child. Ideally, the child should also call POSIX::setsid, to detach itself away from Web server, otherwise it could be killed by the server.
Forking also makes possible to pass your password over the pipe. Something like the following could
do the trick
my $chld = fork(); # I wan't the CGI to end quickly
die "Can't fork: $!\n" if(!definded $chld);
exit(0) if $chld; # CGI ends here
POSIX::setsid(); # start new session
$chld = open(CHLD, "|-"); # this does another fork internally
die "Can't fork: $!\n" if(!definded $chld);
if($chld == 0)
{
# this does the same as ">/dev/null 2>&1" in shell
close(STDOUT);
open(STDOUT, ">/dev/null");
close(STDERR);
open(STDERR, ">&STDOUT");
# avoid parsing of the arguments by shell, especially if $Trigger_
+Job
# or $Captured_User_Name contain some dangerous stuff
exec './processor.pl', '-j', $Trigger_Job, '-u', $Captured_User_Na
+me;
}
select(CHLD); # make CHLD my default output
$| = 1; # enable autoflushing
print $Captured_Password; # output captured password
close(CHLD); # wait for child to finish it's work
The code above is not tested. Read more about processes groups and sessions to
understand why the switch of session might be good.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.