src/server/safs/cgi.c

changeset 566
963edce64e6e
parent 565
6a0138b67cee
child 567
fed45fc71e7c
equal deleted inserted replaced
565:6a0138b67cee 566:963edce64e6e
104 return REQ_ABORTED; 104 return REQ_ABORTED;
105 } 105 }
106 ZERO(handler, sizeof(CGIHandler)); 106 ZERO(handler, sizeof(CGIHandler));
107 handler->path = path; 107 handler->path = path;
108 108
109 int ret = cgi_start(&handler->process, path, argv, env); 109 int ret = cgi_start(rq, &handler->process, path, argv, env);
110 if(ret != REQ_PROCEED) { 110 if(ret != REQ_PROCEED) {
111 util_env_free(env); 111 util_env_free(env);
112 cgi_free_argv(argv); 112 cgi_free_argv(argv);
113 return ret; 113 return ret;
114 } 114 }
115 log_ereport(LOG_DEBUG, "send-cgi: req: %p pid: %d pipes: [%d, %d]", rq, (int)handler->process.pid, handler->process.out[0], handler->process.err[0]); 115 log_ereport(LOG_DEBUG, "send-cgi: req: %p pid: %d", rq, (int)handler->process.pid);
116 116
117 util_env_free(env); 117 util_env_free(env);
118 cgi_free_argv(argv); 118 cgi_free_argv(argv);
119 119
120 char buf[4096]; // I/O buffer 120 char buf[4096]; // I/O buffer
677 log_ereport(LOG_DEBUG, "cgi-send: req: %p event-finish nsapi return", rq); 677 log_ereport(LOG_DEBUG, "cgi-send: req: %p event-finish nsapi return", rq);
678 nsapi_function_return(sn, rq, handler->result); 678 nsapi_function_return(sn, rq, handler->result);
679 return 0; 679 return 0;
680 } 680 }
681 681
682 int cgi_start(CGIProcess *p, char *path, char *const argv[], char *const envp[]) { 682 int cgi_start(Request *rq, CGIProcess *p, char *path, char *const argv[], char *const envp[]) {
683 if(pipe(p->in) || pipe(p->out) || pipe(p->err)) { 683 if(pipe(p->in) || pipe(p->out) || pipe(p->err)) {
684 log_ereport( 684 log_ereport(
685 LOG_FAILURE, 685 LOG_FAILURE,
686 "send-cgi: cannot create pipe: %s", 686 "send-cgi: cannot create pipe: %s",
687 strerror(errno)); 687 strerror(errno));
728 system_close(p->in[1]); 728 system_close(p->in[1]);
729 729
730 // execute program 730 // execute program
731 exit(execve(script.ptr, argv, envp)); 731 exit(execve(script.ptr, argv, envp));
732 } else { 732 } else {
733 // parent 733 log_ereport(LOG_DEBUG, "send-cgi: start-cgi: req: %p pid: %d pipes: [%d, %d][%d, %d][%d, %d]", rq, (int)p->pid, p->out[0], p->out[1], p->err[0], p->err[1], p->in[0], p->in[1]);
734 // parent
734 system_close(p->out[1]); 735 system_close(p->out[1]);
735 system_close(p->err[1]); 736 system_close(p->err[1]);
736 p->out[1] = -1; 737 p->out[1] = -1;
737 p->err[1] = -1; 738 p->err[1] = -1;
738 } 739 }

mercurial