src/server/safs/cgi.c

changeset 567
fed45fc71e7c
parent 566
963edce64e6e
child 579
e10457d74fe1
equal deleted inserted replaced
566:963edce64e6e 567:fed45fc71e7c
50 #define CGI_VARS 32 50 #define CGI_VARS 32
51 51
52 #define CGI_RESPONSE_PARSER_BUFLEN 2048 52 #define CGI_RESPONSE_PARSER_BUFLEN 2048
53 #define CGI_RESPONSE_MAX_LINE_LENGTH 512 53 #define CGI_RESPONSE_MAX_LINE_LENGTH 512
54 54
55 static void close_std_pipes(int fds[static 6]) {
56 for(int i=0;i<6;i++) {
57 if(fds[i] >= 0) {
58 close(fds[i]);
59 }
60 }
61 }
62
55 int send_cgi(pblock *pb, Session *sn, Request *rq) { 63 int send_cgi(pblock *pb, Session *sn, Request *rq) {
56 char *path = pblock_findkeyval(pb_key_path, rq->vars); 64 char *path = pblock_findkeyval(pb_key_path, rq->vars);
57 char *ctlen = pblock_findkeyval(pb_key_content_length, rq->headers); 65 char *ctlen = pblock_findkeyval(pb_key_content_length, rq->headers);
58 int64_t content_length = 0; 66 int64_t content_length = 0;
59 67
102 CGIHandler *handler = pool_malloc(sn->pool, sizeof(CGIHandler)); 110 CGIHandler *handler = pool_malloc(sn->pool, sizeof(CGIHandler));
103 if(!handler) { 111 if(!handler) {
104 return REQ_ABORTED; 112 return REQ_ABORTED;
105 } 113 }
106 ZERO(handler, sizeof(CGIHandler)); 114 ZERO(handler, sizeof(CGIHandler));
115 handler->process.out[0] = -1;
116 handler->process.out[1] = -1;
117 handler->process.err[0] = -1;
118 handler->process.err[0] = -1;
119 handler->process.in[0] = -1;
120 handler->process.in[0] = -1;
107 handler->path = path; 121 handler->path = path;
108 122
109 int ret = cgi_start(rq, &handler->process, path, argv, env); 123 int ret = cgi_start(rq, &handler->process, path, argv, env);
110 if(ret != REQ_PROCEED) { 124 if(ret != REQ_PROCEED) {
125 close_std_pipes((int[6]){
126 handler->process.out[0], handler->process.out[1],
127 handler->process.err[0], handler->process.err[1],
128 handler->process.in[0], handler->process.in[1]});
111 util_env_free(env); 129 util_env_free(env);
112 cgi_free_argv(argv); 130 cgi_free_argv(argv);
113 return ret; 131 return ret;
114 } 132 }
115 log_ereport(LOG_DEBUG, "send-cgi: req: %p pid: %d", rq, (int)handler->process.pid); 133 log_ereport(LOG_DEBUG, "send-cgi: req: %p pid: %d", rq, (int)handler->process.pid);

mercurial