Menu

#23 Multiple CGI instances won't die

open
nobody
boa (32)
5
2004-05-07
2004-05-07
No

We had the following problem with BOA & CGI scripts:

When the user presses refresh repeatedly on a CGI
script, after 3 clicks the cgi scripts won't respond.
Furthermore, the CGI scripts won't die, they remain in
the process list even after timeout.

While debugging the problem, it was noticed that the
newly created cgi scripts inherit the file descriptors
of the boa process. Thus, when the boa closes its end
of the pipe, the end of the pipe remains open with
another cgi process (even though it has no use of it).
Thus the first cgi process does not see closed pipe but
tries to print the results to stdout.

The fact that the following cgi requests won't work is
probably due to the implementation of the cgi script.
Nevertheless, setting the close-on-exec flag of the
boa's cgi input file descriptor fixes the problem:

/* NPH, GUNZIP, etc... all go straight to the fd */
if (!use_pipes)
return 0;

close(pipes[1]);
// FIX begin
/* JuL: Set the close-on-exec on the file so
that the following
cgi scripts won't inherit the file descriptor */
if (fcntl(pipes[0], F_SETFD, FD_CLOEXEC) == -1) {
log_error_time();
perror("fd - close on exec");
}
// FIX end
req->data_fd = pipes[0];

req->status = PIPE_READ;

Greetings,

Juha Lemmetti

Discussion


Log in to post a comment.