rbb 99/10/20 11:28:11
Modified: src/lib/apr/threadproc/unix proc.c src/modules/standard mod_cgi.c Log: Fix mod_cgi so it works on Unix systems. We need to be VERY careful about calling ap_cleanups_for_exec now. There is really no reason to call this from outside of APR, unless you are specifically doing a fork/exec. If you use ap_create_process, it will call ap_cleanups_for_exec for you in the right spot now. Also cleaned up some of the code because it helped with debugging. We need better error messages in mod_cgi now. iCVS: Revision Changes Path 1.8 +4 -1 apache-2.0/src/lib/apr/threadproc/unix/proc.c Index: proc.c =================================================================== RCS file: /home/cvs/apache-2.0/src/lib/apr/threadproc/unix/proc.c,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- proc.c 1999/10/15 14:20:22 1.7 +++ proc.c 1999/10/20 18:27:48 1.8 @@ -343,6 +343,9 @@ exit(-1); /* We have big problems, the child should exit. */ } } + + ap_cleanup_for_exec(); + if (attr->cmdtype == APR_SHELLCMD) { i = 0; while (args[i]) { @@ -470,7 +473,7 @@ if (proc == NULL) { return APR_ENOPROC; } - theproc = &(proc->pid); + *theproc = proc->pid; return APR_SUCCESS; } 1.14 +27 -35 apache-2.0/src/modules/standard/mod_cgi.c Index: mod_cgi.c =================================================================== RCS file: /home/cvs/apache-2.0/src/modules/standard/mod_cgi.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- mod_cgi.c 1999/10/20 15:15:39 1.13 +++ mod_cgi.c 1999/10/20 18:28:04 1.14 @@ -216,7 +216,7 @@ * on Unix, thanks to the magic of fork(). */ while (ap_bgets(argsbuffer, HUGE_STRING_LEN, script_err) > 0) { - ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, errno, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0, r, "%s", argsbuffer); } #else @@ -319,13 +319,8 @@ /* Transumute ourselves into the script. * NB only ISINDEX scripts get decoded arguments. */ - ap_cleanup_for_exec(); - if ((ap_createprocattr_init(&procattr, p) != APR_SUCCESS) || - (ap_setprocattr_io(procattr, - script_in ? 1 : 0, - script_out ? 1 : 0, - script_err ? 1 : 0) != APR_SUCCESS) || + (ap_setprocattr_io(procattr, 1, 1, 1) != APR_SUCCESS) || (ap_setprocattr_dir(procattr, ap_make_dirstr_parent(r->pool, r->filename)) != APR_SUCCESS) || (ap_setprocattr_cmdtype(procattr, APR_PROGRAM) != APR_SUCCESS)) { /* Something bad happened, tell the world. */ @@ -350,32 +345,29 @@ ap_get_os_proc(&fred, procnew); ap_note_subprocess(p, fred, kill_after_timeout); #endif - if (script_in) { - ap_get_childout(&file, procnew); - iol = ap_create_file_iol(file); - if (!iol) - return APR_EBADF; - *script_in = ap_bcreate(p, B_RD); - ap_bpush_iol(*script_in, iol); - } - - if (script_out) { - ap_get_childin(&file, procnew); - iol = ap_create_file_iol(file); - if (!iol) - return APR_EBADF; - *script_out = ap_bcreate(p, B_WR); - ap_bpush_iol(*script_out, iol); - } - - if (script_err) { - ap_get_childerr(&file, procnew); - iol = ap_create_file_iol(file); - if (!iol) - return APR_EBADF; - *script_err = ap_bcreate(p, B_RD); - ap_bpush_iol(*script_err, iol); - } + /* Fill in BUFF structure for parents pipe to child's stdout */ + ap_get_childout(&file, procnew); + iol = ap_create_file_iol(file); + if (!iol) + return APR_EBADF; + *script_in = ap_bcreate(p, B_RD); + ap_bpush_iol(*script_in, iol); + + /* Fill in BUFF structure for parents pipe to child's stdin */ + ap_get_childin(&file, procnew); + iol = ap_create_file_iol(file); + if (!iol) + return APR_EBADF; + *script_out = ap_bcreate(p, B_WR); + ap_bpush_iol(*script_out, iol); + + /* Fill in BUFF structure for parents pipe to child's stderr */ + ap_get_childerr(&file, procnew); + iol = ap_create_file_iol(file); + if (!iol) + return APR_EBADF; + *script_err = ap_bcreate(p, B_RD); + ap_bpush_iol(*script_err, iol); } } ap_unblock_alarms(); @@ -424,7 +416,7 @@ fileType = ap_get_win32_interpreter(r, &interpreter); if (fileType == eFileTypeUNKNOWN) { - ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, errno, r, + ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, r, "%s is not executable; ensure interpreted scripts have " "\"#!\" first line", r->filename); @@ -454,7 +446,7 @@ char *command; char *argv = NULL; - BUFF *script_out, *script_in, *script_err; + BUFF *script_out = NULL, *script_in = NULL, *script_err = NULL; char argsbuffer[HUGE_STRING_LEN]; int is_included = !strcmp(r->protocol, "INCLUDED"); void *sconf = r->server->module_config;