CGI-SpeedyCGI
view release on metacpan or search on metacpan
src/speedy_perl.c view on Meta::CPAN
/* Cached time is now invalid */
speedy_util_time_invalidate();
/* Cancel any alarms */
alarm(0);
/* Terminate if a forked child returned */
if (getpid() != speedy_util_getpid()) {
speedy_util_pid_invalidate();
speedy_file_fork_child();
all_done();
}
/* Tell our file code that its fd is suspect */
speedy_file_fd_is_suspect();
}
/* One run of the perl process, do stdio using socket. */
static int onerun(int single_script) {
int sz, new_script, cwd_where, exit_val;
char *scr_path;
SpeedyDevIno fe_scr;
SpeedyScript *scr;
PerlIO *pio_in, *pio_out, *pio_err;
register char *s, *buf;
pio_in = PerlIO_stdin();
pio_out = PerlIO_stdout();
pio_err = PerlIO_stderr();
/* Set up perl STD* filehandles to have the PerlIO file pointers */
IoIFP(GvIOp(PERLVAL_STDIN)) = IoOFP(GvIOp(PERLVAL_STDIN)) = pio_in;
IoIFP(GvIOp(PERLVAL_STDOUT)) = IoOFP(GvIOp(PERLVAL_STDOUT)) = pio_out;
IoIFP(GvIOp(PERLVAL_STDERR)) = IoOFP(GvIOp(PERLVAL_STDERR)) = pio_err;
/* Do "select STDOUT" */
setdefout(PERLVAL_STDOUT);
/* TEST - this should cause a "protocol error" */
/* close(0); */
/* Get info from the frontend. */
/*
* %ENV
*/
/* Undef it */
hv_undef(PERLVAL_ENV);
/* Read in environment from stdin. */
while ((buf = get_string(pio_in, &sz))) {
/* Find equals. Store key/val in %ENV */
if ((s = strchr(buf, '='))) {
register int i = s - buf;
register int len = sz - (i+1);
SV *sv = newSVpvn(s+1, len);
my_hv_store(PERLVAL_ENV, buf, i, sv);
*s = '\0';
my_setenv(buf, s+1);
}
speedy_free(buf);
}
/*
* @ARGV
*/
/* Undef it. */
av_undef(PERLVAL_ARGV);
/* Read in argv from stdin. */
while ((buf = get_string(pio_in, &sz))) {
register SV *sv = newSVpvn(buf, sz);
av_push(PERLVAL_ARGV, sv);
speedy_free(buf);
}
/*
* Script filename
*/
scr_path = get_string(pio_in, NULL);
/*
* Script device/inode
*/
DEVINO_GET(pio_in, fe_scr);
/*
* Find the script structure for this script
*/
scr = find_scr(fe_scr, &new_script);
/*
* Is cwd part of the script filename?
*/
cwd_where = PerlIO_getc(pio_in);
if (cwd_where == SPEEDY_CWD_IN_SCRIPT) {
char *dir;
/* Get directory from the script path */
if ((dir = fname_dir(scr_path))) {
SV **sv;
int done = 0;
SpeedyCwd *cwd = NULL;
/* Look up path in hash to find SpeedyCwd and device/inode */
if ((sv = hv_fetch(cwd_hash, dir, strlen(dir), 0))) {
cwd = (SpeedyCwd*)SvIV(*sv);
/* Try to cd there quickly without using a path */
done = quick_cd(cwd->devino);
}
if (!done) {
/* Chdir to the path the frontend gave us and get its cwd */
cwd = cwd_new(dir);
}
/* Store the cwd struct with this script */
store_last_cwd(&(scr->last_cwd), cwd);
( run in 0.523 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )