Skip to content

Commit efdd929

Browse files
committed
fix(cgi): exec cgi but not serve file
1 parent 0bba0e0 commit efdd929

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

server.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ static void accept_action(tcpool_thread_timer_t *p) {
140140
path -= 2;
141141
path[0] = '.'; path[1] = '/';
142142

143-
printf("[%s] <%s> (%s) = ", getmethod(method_type), path, query_string);
143+
printf("[%s] p='%s' ?='%s' ", getmethod(method_type), path, query_string);
144144
do {
145145
// 花括号不可省略
146146
if(stat(path, &st) == -1) {
@@ -151,14 +151,12 @@ static void accept_action(tcpool_thread_timer_t *p) {
151151
int pathlen = strlen(path) + 1;
152152
char path_stack[pathlen + 11]; // 11 is for possible /index.html
153153
memcpy(path_stack, path, pathlen);
154-
printf("<%d> ", pathlen);
155154
path = path_stack;
156155

157156
int query_length = strlen(query_string) + 1;
158157
char query_string_stack[query_length];
159158
memcpy(query_string_stack, query_string, query_length);
160159
query_string = query_string_stack;
161-
printf("(%d) ", query_length);
162160

163161
if((st.st_mode & S_IFMT) == S_IFDIR) {
164162
strcat(path, "/index.html");
@@ -170,7 +168,8 @@ static void accept_action(tcpool_thread_timer_t *p) {
170168
}
171169
int content_length = 0;
172170
int host_chk_passed = !(uintptr_t)hostnameport;
173-
cgi &= ((st.st_mode & S_IXUSR) || (st.st_mode & S_IXGRP) || (st.st_mode & S_IXOTH));
171+
cgi |= ((st.st_mode & S_IXUSR) || (st.st_mode & S_IXGRP) || (st.st_mode & S_IXOTH));
172+
if(cgi) printf("(CGI) ");
174173
while(numchars > 0) {
175174
numchars = get_line(client, p->data, sizeof(p->data));
176175
if(p->data[0] == '\n' || p->data[0] == '\r') {
@@ -308,7 +307,7 @@ static void execute_cgi(tcpool_thread_timer_t *timer, int content_length, const
308307
goto CGI_CLOSE;
309308
}
310309
}
311-
printf("CGI msg len: %u bytes.\n", cnt);
310+
printf("read %u bytes from pipe, ", cnt);
312311
if(cnt > 0) {
313312
int len = 0;
314313
#if __APPLE__
@@ -332,7 +331,7 @@ static void execute_cgi(tcpool_thread_timer_t *timer, int content_length, const
332331
len += delta;
333332
}
334333
#endif
335-
printf("CGI send %d bytes\n", len);
334+
printf("send %d bytes.\n", len);
336335
}
337336
CGI_CLOSE:
338337
close(cgi_output[0]);

0 commit comments

Comments
 (0)