CGI-SpeedyCGI
view release on metacpan or search on metacpan
src/speedy_main.c view on Meta::CPAN
}
}
}
/* See if the backend exited */
else if (got_sig || speedy_poll_isset(&pi, sig_pipes[0], SPEEDY_POLLIN))
{
char c;
/* See if backend exited and if so, get status */
speedy_file_set_state(FS_CORRUPT);
backend_exited =
speedy_frontend_collect_status(fslotnum, exit_on_sig, exit_val);
speedy_file_set_state(FS_OPEN);
/* Exit & EOF? If so, no need to continue */
if (backend_exited && my_copydone(&CB_OUT) && my_copydone(&CB_ERR))
break;
/* Ack signal */
got_sig = 0;
read(sig_pipes[0], &c, 1);
if (backend_exited) {
/* Don't need sig any more */
signal(SIGUSR1, SIG_IGN);
/* Continue until no more data from socket */
stop_sock_reads = 1;
for (i = 0; i < NUMFDS; ++i)
read_stopped[i] = 0;
speedy_poll_reset(&pi);
for (i = 1; i < NUMFDS; ++i) {
speedy_poll_set(&pi, cb[i].rdfd, SPEEDY_POLLIN);
speedy_poll_set(&pi, cb[i].wrfd, SPEEDY_POLLOUT);
}
continue;
}
}
/* Reset events */
speedy_poll_reset(&pi);
/* Do select on signal pipe */
if (!backend_exited)
speedy_poll_set(&pi, sig_pipes[0], SPEEDY_POLLIN);
/* Set read/write events */
for (i = 0; i < NUMFDS; ++i) {
CopyBuf *b = cb + i;
if (my_canread(b))
speedy_poll_set(&pi, b->rdfd, SPEEDY_POLLIN);
if (speedy_cb_canwrite(b))
speedy_poll_set(&pi, b->wrfd, SPEEDY_POLLOUT);
}
/* Poll... */
i = speedy_poll_wait(&pi, 5000);
if (i < 1) {
if (i == -1 && errno != EINTR)
speedy_util_exit(1, 0);
/* Want to check whether backend is still alive */
if (!backend_exited)
catch_sig(0);
speedy_poll_reset(&pi);
}
}
/* SGI's /dev/tty goes crazy unless we turn on blocking I/O. */
for (i = 0; i < NUMFDS; ++i)
fd_change(i, FD_BLOCK);
if (am_child)
speedy_util_exit(0, 0);
#ifdef SPEEDY_PROFILING
/* Slightly faster to skip these, since we're exiting anyways. */
if (profile_runs) {
for (i = 0; i < NUMFDS; ++i)
fd_change(socks[i], FD_CLOSE);
speedy_poll_free(&pi);
speedy_cb_free(&CB_IN);
speedy_cb_free(&CB_OUT);
speedy_cb_free(&CB_ERR);
signal(SIGUSR1, SIG_DFL);
signal(SIGPIPE, SIG_DFL);
close(pipes[0]);
close(pipes[1]);
}
#endif
}
int main(int argc, char **argv, char **_junk) {
int exit_on_sig, exit_val;
speedy_util_unlimit_core();
#ifdef SPEEDY_PROFILING
char *runs = getenv("SPEEDY_PROFILE_RUNS");
profile_runs = runs ? atoi(runs) : 1;
while (profile_runs--)
#endif
doit((const char * const *)argv, &exit_on_sig, &exit_val);
/* If signal, try to kill ourself with the same sig the backend died on */
if (exit_on_sig)
killme(exit_val);
return exit_val;
}
/*
* Glue Functions
*/
void speedy_abort(const char *s) {
write(2, s, strlen(s));
speedy_util_exit(1, 0);
}
#ifdef SPEEDY_EFENCE
( run in 1.788 second using v1.01-cache-2.11-cpan-df04353d9ac )