Révision bcfab93f
Ajouté par Ermal il y a presque 10 ans
pfPorts/check_reload_status/files/check_reload_status.c | ||
---|---|---|
88 | 88 |
|
89 | 89 |
static pid_t ppid = -1; |
90 | 90 |
static struct utsname uts; |
91 |
static int keepalive = 1;
|
|
91 |
static int keepalive = 0;
|
|
92 | 92 |
static char *fcgipath = (char *)FCGI_SOCK_PATH; |
93 | 93 |
|
94 | 94 |
static int |
... | ... | |
110 | 110 |
if (lkey < 128) |
111 | 111 |
sbuf_putc(sb, lkey); |
112 | 112 |
else |
113 |
sbuf_printf(sb, "%c%c%c%c", (u_char)((lkey >> 24) | 0x80), (u_char)((lkey >> 16) & 0xFF), (u_char)((lkey >> 8) & 0xFF), (u_char)(lkey & 0xFF));
|
|
113 |
sbuf_printf(sb, "%c%c%c%c", (u_char)(((lkey >> 24) | 0x80) & 0xFF), (u_char)((lkey >> 16) & 0xFF), (u_char)((lkey >> 8) & 0xFF), (u_char)(lkey & 0xFF));
|
|
114 | 114 |
|
115 | 115 |
if (lvalue < 128 || lvalue > 65535) |
116 | 116 |
sbuf_putc(sb, lvalue); |
117 | 117 |
else |
118 |
sbuf_printf(sb, "%c%c%c%c", (u_char)((lvalue >> 24) | 0x80), (u_char)((lvalue >> 16) & 0xFF), (u_char)((lvalue >> 8) & 0xFF), (u_char)(lvalue & 0xFF));
|
|
118 |
sbuf_printf(sb, "%c%c%c%c", (u_char)(((lvalue >> 24) | 0x80) & 0xFF), (u_char)((lvalue >> 16) & 0xFF), (u_char)((lvalue >> 8) & 0xFF), (u_char)(lvalue & 0xFF));
|
|
119 | 119 |
|
120 | 120 |
if (lkey > 0) |
121 | 121 |
sbuf_printf(sb, "%s", key); |
... | ... | |
320 | 320 |
/* TODO: Remove some env variables since might not be needed at all!!! */ |
321 | 321 |
build_nvpair(&sb, strlen("GATEWAY_INTERFACE"), strlen("FastCGI/1.0"), "GATEWAY_INTERFACE", (char *)"FastCGI/1.0"); |
322 | 322 |
build_nvpair(&sb, strlen("REQUEST_METHOD"), strlen("GET"), "REQUEST_METHOD", (char *)"GET"); |
323 |
build_nvpair(&sb, strlen("SCRIPT_FILENAME"), strlen(cmd->command), "SCRIPT_FILENAME", cmd->command); |
|
324 | 323 |
build_nvpair(&sb, strlen("NO_HEADERS"), strlen("1"), "NO_HEADERS", (char *)"1"); |
324 |
build_nvpair(&sb, strlen("SCRIPT_FILENAME"), strlen(cmd->command), "SCRIPT_FILENAME", cmd->command); |
|
325 | 325 |
p = strrchr(cmd->command, '/'); |
326 | 326 |
build_nvpair(&sb, strlen("SCRIPT_NAME"), strlen(p), "SCRIPT_NAME", p); |
327 |
p++; |
|
327 |
if (!cmd->params[0]) |
|
328 |
build_nvpair(&sb, strlen("REQUEST_URI"), strlen(p), "REQUEST_URI", p); |
|
328 | 329 |
build_nvpair(&sb, strlen("DOCUMENT_URI"), strlen(p), "DOCUMENT_URI", p); |
329 |
build_nvpair(&sb, strlen("QUERY_STRING"), strlen(cmd->params), "QUERY_STRING", cmd->params); |
|
330 |
if (!cmd->params[0]) { |
|
331 |
build_nvpair(&sb, strlen("REQUEST_URI"), 0, "REQUEST_URI", p); |
|
332 |
} else { |
|
330 |
if (cmd->params[0]) { |
|
331 |
build_nvpair(&sb, strlen("QUERY_STRING"), strlen(cmd->params), "QUERY_STRING", cmd->params); |
|
333 | 332 |
/* XXX: Hack in sight to avoid using another sbuf */ |
334 |
build_nvpair(&sb, strlen("REQUEST_URI"), 1 + strlen(p) + strlen(cmd->params) + 1, "REQUEST_URI", (char *)"/"); |
|
333 |
/* + 2 is for the / and ? added chars */ |
|
334 |
build_nvpair(&sb, strlen("REQUEST_URI"), strlen(p) + strlen(cmd->params) + 2, "REQUEST_URI", (char *)"/"); |
|
335 | 335 |
sbuf_printf(&sb, "%s?%s", p, cmd->params); |
336 | 336 |
} |
337 | 337 |
sbuf_finish(&sb); |
... | ... | |
356 | 356 |
bHeader->body.roleB0 = (unsigned char)FCGI_RESPONDER; |
357 | 357 |
bHeader->body.flags = (unsigned char)(keepalive ? FCGI_KEEP_CONN : 0); |
358 | 358 |
|
359 |
bufptr += sizeof(FCGI_Header);
|
|
359 |
bufptr += sizeof(FCGI_BeginRequestRecord);
|
|
360 | 360 |
tmpl = (FCGI_Header *)bufptr; |
361 | 361 |
prepare_packet(tmpl, FCGI_PARAMS, sbuf_len(&sb), requestId); |
362 | 362 |
|
363 | 363 |
bufptr += sizeof(FCGI_Header); |
364 |
tmpl = (FCGI_Header *)bufptr; |
|
365 |
memcpy((char *)tmpl, sbuf_data(&sb), sbuf_len(&sb)); |
|
364 |
memcpy(bufptr, sbuf_data(&sb), sbuf_len(&sb)); |
|
366 | 365 |
|
367 | 366 |
bufptr += sbuf_len(&sb); |
368 | 367 |
tmpl = (FCGI_Header *)bufptr; |
... | ... | |
370 | 369 |
|
371 | 370 |
bufptr += sizeof(FCGI_Header); |
372 | 371 |
tmpl = (FCGI_Header *)bufptr; |
372 |
|
|
373 | 373 |
prepare_packet(tmpl, FCGI_STDIN, 0, requestId); |
374 | 374 |
if (cmd->socket < 0) { |
375 | 375 |
if ((cmd->socket = fcgi_open_socket(cmd)) < 0) { |
376 | 376 |
/* Reschedule */ |
377 | 377 |
tv.tv_sec = 1; |
378 |
cmd->socket = -1; |
|
379 | 378 |
timeout_add(&cmd->ev, &tv); |
380 | 379 |
return; |
381 | 380 |
} |
... | ... | |
501 | 500 |
case INTEGER: |
502 | 501 |
case IFNAME: |
503 | 502 |
case STRING: |
504 |
if (p != NULL)
|
|
503 |
if (argv != NULL)
|
|
505 | 504 |
syslog(LOG_NOTICE, cmd->cmd.syslog, argv); |
506 | 505 |
else |
507 | 506 |
syslog(LOG_NOTICE, "%s", cmd->cmd.syslog); |
... | ... | |
534 | 533 |
FCGI_Header header; |
535 | 534 |
char buf[4096]; |
536 | 535 |
int len, terr, success = 0; |
536 |
struct timeval tv = { 1, 0 }; |
|
537 | 537 |
|
538 | 538 |
if (event == EV_TIMEOUT) { |
539 | 539 |
close(fd); |
540 |
fcgi_open_socket(tmpcmd); |
|
540 |
syslog(LOG_ERR, "Rescheduling command %s due to timeout waiting for response", tmpcmd->command); |
|
541 |
tmpcmd->socket = fcgi_open_socket(tmpcmd); |
|
542 |
timeout_set(&tmpcmd->ev, fcgi_send_command, tmpcmd); |
|
543 |
timeout_add(&tmpcmd->ev, &tv); |
|
541 | 544 |
return; |
542 | 545 |
} |
543 | 546 |
|
... | ... | |
744 | 747 |
|
745 | 748 |
if ((p = getenv("fcgipath")) != NULL) { |
746 | 749 |
fcgipath = p; |
747 |
syslog(LOG_ERR, "fcgipath %s", fcgipath);
|
|
750 |
syslog(LOG_NOTICE, "fcgipath from environment %s", fcgipath);
|
|
748 | 751 |
} |
749 | 752 |
|
750 | 753 |
sigemptyset(&set); |
pfPorts/check_reload_status/files/fcgicli.c | ||
---|---|---|
132 | 132 |
socketpath = optarg; |
133 | 133 |
break; |
134 | 134 |
case 'o': |
135 |
if (!strcasecmp(optarg, "POST")) |
|
135 |
if (!strcasecmp(optarg, "POST")) {
|
|
136 | 136 |
ispost = 1; |
137 |
else if(!strcasecmp(optarg, "GET")) |
|
137 |
printf("POST mode is not yet implemented\n"); |
|
138 |
exit(-2); |
|
139 |
} else if(!strcasecmp(optarg, "GET")) |
|
138 | 140 |
ispost = 0; |
139 | 141 |
else |
140 | 142 |
usage(); |
... | ... | |
197 | 199 |
|
198 | 200 |
uname(&uts); |
199 | 201 |
|
200 |
if (ispost) { |
|
201 |
printf("POST is not yet implemented\n"); |
|
202 |
tmpl = NULL; |
|
203 |
|
|
204 |
} else { |
|
205 |
sbtmp2 = sbuf_new_auto(); |
|
206 |
if (sbtmp2 == NULL) |
|
207 |
errx(-3, "Could not allocate memory\n"); |
|
208 |
build_nvpair(sbtmp2, "GATEWAY_INTERFACE", (char *)"FastCGI/1.0"); |
|
209 |
build_nvpair(sbtmp2, "REQUEST_METHOD", (char *)"GET"); |
|
210 |
build_nvpair(sbtmp2, "NO_HEADERS", (char *)"1"); |
|
202 |
sbtmp2 = sbuf_new_auto(); |
|
203 |
if (sbtmp2 == NULL) |
|
204 |
errx(-3, "Could not allocate memory\n"); |
|
205 |
build_nvpair(sbtmp2, "GATEWAY_INTERFACE", (char *)"FastCGI/1.0"); |
|
206 |
build_nvpair(sbtmp2, "REQUEST_METHOD", (char *)"GET"); |
|
207 |
build_nvpair(sbtmp2, "NO_HEADERS", (char *)"1"); |
|
208 |
sbtmp = sbuf_new_auto(); |
|
209 |
sbuf_printf(sbtmp, "/%s", basename(script)); |
|
210 |
sbuf_finish(sbtmp); |
|
211 |
build_nvpair(sbtmp2, "SCRIPT_FILENAME", script); |
|
212 |
build_nvpair(sbtmp2, "SCRIPT_NAME", sbuf_data(sbtmp)); |
|
213 |
if (data == NULL) { |
|
214 |
build_nvpair(sbtmp2, "REQUEST_URI", sbuf_data(sbtmp)); |
|
215 |
} |
|
216 |
build_nvpair(sbtmp2, "DOCUMENT_URI", sbuf_data(sbtmp)); |
|
217 |
sbuf_delete(sbtmp); |
|
218 |
if (data) { |
|
219 |
build_nvpair(sbtmp2, "QUERY_STRING", data); |
|
211 | 220 |
sbtmp = sbuf_new_auto(); |
212 |
sbuf_printf(sbtmp, "/%s", basename(script));
|
|
221 |
sbuf_printf(sbtmp, "/%s?%s", basename(script), data);
|
|
213 | 222 |
sbuf_finish(sbtmp); |
214 |
build_nvpair(sbtmp2, "SCRIPT_FILENAME", script); |
|
215 |
build_nvpair(sbtmp2, "SCRIPT_NAME", sbuf_data(sbtmp)); |
|
216 |
if (data == NULL) { |
|
217 |
build_nvpair(sbtmp2, "REQUEST_URI", sbuf_data(sbtmp)); |
|
218 |
} |
|
219 |
build_nvpair(sbtmp2, "DOCUMENT_URI", sbuf_data(sbtmp)); |
|
223 |
build_nvpair(sbtmp2, "REQUEST_URI", sbuf_data(sbtmp)); |
|
220 | 224 |
sbuf_delete(sbtmp); |
221 |
if (data) { |
|
222 |
build_nvpair(sbtmp2, "QUERY_STRING", data); |
|
223 |
sbtmp = sbuf_new_auto(); |
|
224 |
sbuf_printf(sbtmp, "/%s?%s", basename(script), data); |
|
225 |
sbuf_finish(sbtmp); |
|
226 |
build_nvpair(sbtmp2, "REQUEST_URI", sbuf_data(sbtmp)); |
|
227 |
sbuf_delete(sbtmp); |
|
228 |
} |
|
229 |
sbuf_finish(sbtmp2); |
|
230 |
|
|
231 |
len = (3 * sizeof(FCGI_Header)) + sizeof(FCGI_BeginRequestRecord) + sbuf_len(sbtmp2); |
|
232 |
buf = calloc(1, len); |
|
233 |
if (buf == NULL) |
|
234 |
errx(-4, "Cannot allocate memory"); |
|
235 |
|
|
236 |
bHeader = (FCGI_BeginRequestRecord *)buf; |
|
237 |
prepare_packet(&bHeader->header, FCGI_BEGIN_REQUEST, sizeof(bHeader->body), 1); |
|
238 |
bHeader->body.roleB0 = (unsigned char)FCGI_RESPONDER; |
|
239 |
bHeader->body.flags = (unsigned char)(keepalive ? FCGI_KEEP_CONN : 0); |
|
240 |
bHeader++; |
|
241 |
tmpl = (FCGI_Header *)bHeader; |
|
242 |
prepare_packet(tmpl, FCGI_PARAMS, sbuf_len(sbtmp2), 1); |
|
243 |
tmpl++; |
|
244 |
memcpy((char *)tmpl, sbuf_data(sbtmp2), sbuf_len(sbtmp2)); |
|
245 |
tmpl = (FCGI_Header *)(((char *)tmpl) + sbuf_len(sbtmp2)); |
|
246 |
sbuf_delete(sbtmp2); |
|
247 | 225 |
} |
226 |
sbuf_finish(sbtmp2); |
|
227 |
|
|
228 |
len = (3 * sizeof(FCGI_Header)) + sizeof(FCGI_BeginRequestRecord) + sbuf_len(sbtmp2); |
|
229 |
buf = calloc(1, len); |
|
230 |
if (buf == NULL) |
|
231 |
errx(-4, "Cannot allocate memory"); |
|
232 |
|
|
233 |
bHeader = (FCGI_BeginRequestRecord *)buf; |
|
234 |
prepare_packet(&bHeader->header, FCGI_BEGIN_REQUEST, sizeof(bHeader->body), 1); |
|
235 |
bHeader->body.roleB0 = (unsigned char)FCGI_RESPONDER; |
|
236 |
bHeader->body.flags = (unsigned char)(keepalive ? FCGI_KEEP_CONN : 0); |
|
237 |
bHeader++; |
|
238 |
tmpl = (FCGI_Header *)bHeader; |
|
239 |
prepare_packet(tmpl, FCGI_PARAMS, sbuf_len(sbtmp2), 1); |
|
240 |
tmpl++; |
|
241 |
memcpy((char *)tmpl, sbuf_data(sbtmp2), sbuf_len(sbtmp2)); |
|
242 |
tmpl = (FCGI_Header *)(((char *)tmpl) + sbuf_len(sbtmp2)); |
|
243 |
sbuf_delete(sbtmp2); |
|
248 | 244 |
prepare_packet(tmpl, FCGI_PARAMS, 0, 1); |
249 | 245 |
tmpl++; |
250 | 246 |
prepare_packet(tmpl, FCGI_STDIN, 0, 1); |
Formats disponibles : Unified diff
Correct check_reload_status behaviour but correcting the pointer arithmetic! Also while here add more error checking