Project

General

Profile

backlog.diff

aschmitz, 2012-07-01 06:56

View differences:

spawn-fcgi.c 2012-06-30 23:53:49.427484580 -0500
79 79

  
80 80
#define CONST_STR_LEN(s) s, sizeof(s) - 1
81 81

  
82
static int bind_socket(const char *addr, unsigned short port, const char *unixsocket, uid_t uid, gid_t gid, int mode) {
82
static int bind_socket(const char *addr, unsigned short port, const char *unixsocket, uid_t uid, gid_t gid, int mode, int backlog) {
83 83
	int fcgi_fd, socket_type, val;
84 84

  
85 85
	struct sockaddr_un fcgi_addr_un;
......
208 208
		}
209 209
	}
210 210

  
211
	if (-1 == listen(fcgi_fd, 1024)) {
211
	if (-1 == listen(fcgi_fd, backlog)) {
212 212
		fprintf(stderr, "spawn-fcgi: listen failed: %s\n", strerror(errno));
213 213
		return -1;
214 214
	}
......
427 427
		" -C <children>  (PHP only) numbers of childs to spawn (default: not setting\n" \
428 428
		"                the PHP_FCGI_CHILDREN environment variable - PHP defaults to 0)\n" \
429 429
		" -F <children>  number of children to fork (default 1)\n" \
430
		" -b <backlog>   backlog to allow on the socket (default 1024)\n" \
430 431
		" -P <path>      name of PID-file for spawned process (ignored in no-fork mode)\n" \
431 432
		" -n             no fork (for daemontools)\n" \
432 433
		" -v             show version\n" \
......
455 456
	int sockmode = -1;
456 457
	int child_count = -1;
457 458
	int fork_count = 1;
459
	int backlog = 1024;
458 460
	int i_am_root, o;
459 461
	int pid_fd = -1;
460 462
	int nofork = 0;
......
469 471

  
470 472
	i_am_root = (getuid() == 0);
471 473

  
472
	while (-1 != (o = getopt(argc, argv, "c:d:f:g:?hna:p:u:vC:F:s:P:U:G:M:S"))) {
474
	while (-1 != (o = getopt(argc, argv, "c:d:f:g:?hna:p:b:u:vC:F:s:P:U:G:M:S"))) {
473 475
		switch(o) {
474 476
		case 'f': fcgi_app = optarg; break;
475 477
		case 'd': fcgi_dir = optarg; break;
......
482 484
			break;
483 485
		case 'C': child_count = strtol(optarg, NULL, 10);/*  */ break;
484 486
		case 'F': fork_count = strtol(optarg, NULL, 10);/*  */ break;
487
		case 'b': backlog = strtol(optarg, NULL, 10);/*  */ break;
485 488
		case 's': unixsocket = optarg; /* unix-domain socket */ break;
486 489
		case 'c': if (i_am_root) { changeroot = optarg; }/* chroot() */ break;
487 490
		case 'u': if (i_am_root) { username = optarg; } /* set user */ break;
......
581 584
		if (0 == sockuid) sockuid = uid;
582 585
		if (0 == sockgid) sockgid = gid;
583 586

  
584
		if (sockbeforechroot && -1 == (fcgi_fd = bind_socket(addr, port, unixsocket, sockuid, sockgid, sockmode)))
587
		if (sockbeforechroot && -1 == (fcgi_fd = bind_socket(addr, port, unixsocket, sockuid, sockgid, sockmode, backlog)))
585 588
			return -1;
586 589

  
587 590
		/* Change group before chroot, when we have access
......
606 609
			}
607 610
		}
608 611

  
609
		if (!sockbeforechroot && -1 == (fcgi_fd = bind_socket(addr, port, unixsocket, sockuid, sockgid, sockmode)))
612
		if (!sockbeforechroot && -1 == (fcgi_fd = bind_socket(addr, port, unixsocket, sockuid, sockgid, sockmode, backlog)))
610 613
			return -1;
611 614

  
612 615
		/* drop root privs */
......
614 617
			setuid(uid);
615 618
		}
616 619
	} else {
617
		if (-1 == (fcgi_fd = bind_socket(addr, port, unixsocket, 0, 0, sockmode)))
620
		if (-1 == (fcgi_fd = bind_socket(addr, port, unixsocket, 0, 0, sockmode, backlog)))
618 621
			return -1;
619 622
	}
620 623