Projet

Général

Profil

« Précédent | Suivant » 

Révision bcfab93f

Ajouté par Ermal il y a presque 10 ans

Correct check_reload_status behaviour but correcting the pointer arithmetic! Also while here add more error checking

Voir les différences:

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);

Formats disponibles : Unified diff