Project

General

Profile

Feature #2422 ยป backlog.diff

aschmitz, 2012-07-01 06:56

View differences:

spawn-fcgi.c 2012-06-30 23:53:49.427484580 -0500
#define CONST_STR_LEN(s) s, sizeof(s) - 1
static int bind_socket(const char *addr, unsigned short port, const char *unixsocket, uid_t uid, gid_t gid, int mode) {
static int bind_socket(const char *addr, unsigned short port, const char *unixsocket, uid_t uid, gid_t gid, int mode, int backlog) {
int fcgi_fd, socket_type, val;
struct sockaddr_un fcgi_addr_un;
......
}
}
if (-1 == listen(fcgi_fd, 1024)) {
if (-1 == listen(fcgi_fd, backlog)) {
fprintf(stderr, "spawn-fcgi: listen failed: %s\n", strerror(errno));
return -1;
}
......
" -C <children> (PHP only) numbers of childs to spawn (default: not setting\n" \
" the PHP_FCGI_CHILDREN environment variable - PHP defaults to 0)\n" \
" -F <children> number of children to fork (default 1)\n" \
" -b <backlog> backlog to allow on the socket (default 1024)\n" \
" -P <path> name of PID-file for spawned process (ignored in no-fork mode)\n" \
" -n no fork (for daemontools)\n" \
" -v show version\n" \
......
int sockmode = -1;
int child_count = -1;
int fork_count = 1;
int backlog = 1024;
int i_am_root, o;
int pid_fd = -1;
int nofork = 0;
......
i_am_root = (getuid() == 0);
while (-1 != (o = getopt(argc, argv, "c:d:f:g:?hna:p:u:vC:F:s:P:U:G:M:S"))) {
while (-1 != (o = getopt(argc, argv, "c:d:f:g:?hna:p:b:u:vC:F:s:P:U:G:M:S"))) {
switch(o) {
case 'f': fcgi_app = optarg; break;
case 'd': fcgi_dir = optarg; break;
......
break;
case 'C': child_count = strtol(optarg, NULL, 10);/* */ break;
case 'F': fork_count = strtol(optarg, NULL, 10);/* */ break;
case 'b': backlog = strtol(optarg, NULL, 10);/* */ break;
case 's': unixsocket = optarg; /* unix-domain socket */ break;
case 'c': if (i_am_root) { changeroot = optarg; }/* chroot() */ break;
case 'u': if (i_am_root) { username = optarg; } /* set user */ break;
......
if (0 == sockuid) sockuid = uid;
if (0 == sockgid) sockgid = gid;
if (sockbeforechroot && -1 == (fcgi_fd = bind_socket(addr, port, unixsocket, sockuid, sockgid, sockmode)))
if (sockbeforechroot && -1 == (fcgi_fd = bind_socket(addr, port, unixsocket, sockuid, sockgid, sockmode, backlog)))
return -1;
/* Change group before chroot, when we have access
......
}
}
if (!sockbeforechroot && -1 == (fcgi_fd = bind_socket(addr, port, unixsocket, sockuid, sockgid, sockmode)))
if (!sockbeforechroot && -1 == (fcgi_fd = bind_socket(addr, port, unixsocket, sockuid, sockgid, sockmode, backlog)))
return -1;
/* drop root privs */
......
setuid(uid);
}
} else {
if (-1 == (fcgi_fd = bind_socket(addr, port, unixsocket, 0, 0, sockmode)))
if (-1 == (fcgi_fd = bind_socket(addr, port, unixsocket, 0, 0, sockmode, backlog)))
return -1;
}
    (1-1/1)