Skip to content

Commit 8b642af

Browse files
committed
Merge branch 'PHP-7.1' into PHP-7.2
2 parents 35e3d59 + 2688023 commit 8b642af

File tree

3 files changed

+75
-24
lines changed

3 files changed

+75
-24
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ PHP NEWS
99
- Date:
1010
. Fixed bug #76131 (mismatch arginfo for date_create). (carusogabriel)
1111

12+
- FPM:
13+
. Fixed bug #68440 (ERROR: failed to reload: execvp() failed: Argument list
14+
too long). (Jacob Hipps)
15+
. Fixed incorrect write to getenv result in FPM reload. (Jakub Zelenka)
16+
1217
- mbstring:
1318
. Fixed bug #75944 (Wrong cp1251 detection). (dmk001)
1419
. Fixed bug #76113 (mbstring does not build with Oniguruma 6.8.1).

sapi/fpm/fpm/fpm_sockets.c

Lines changed: 66 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ enum { FPM_GET_USE_SOCKET = 1, FPM_STORE_SOCKET = 2, FPM_STORE_USE_SOCKET = 3 };
4444
static void fpm_sockets_cleanup(int which, void *arg) /* {{{ */
4545
{
4646
unsigned i;
47+
unsigned socket_set_count = 0;
48+
unsigned socket_set[FPM_ENV_SOCKET_SET_MAX];
49+
unsigned socket_set_buf = 0;
50+
char envname[32];
4751
char *env_value = 0;
4852
int p = 0;
4953
struct listening_socket_s *ls = sockets_list.data;
@@ -54,8 +58,20 @@ static void fpm_sockets_cleanup(int which, void *arg) /* {{{ */
5458
} else { /* on PARENT EXEC we want socket fds to be inherited through environment variable */
5559
char fd[32];
5660
sprintf(fd, "%d", ls->sock);
57-
env_value = realloc(env_value, p + (p ? 1 : 0) + strlen(ls->key) + 1 + strlen(fd) + 1);
58-
p += sprintf(env_value + p, "%s%s=%s", p ? "," : "", ls->key, fd);
61+
62+
socket_set_buf = (i % FPM_ENV_SOCKET_SET_SIZE == 0 && i) ? 1 : 0;
63+
env_value = realloc(env_value, p + (p ? 1 : 0) + strlen(ls->key) + 1 + strlen(fd) + socket_set_buf + 1);
64+
65+
if (i % FPM_ENV_SOCKET_SET_SIZE == 0) {
66+
socket_set[socket_set_count] = p + socket_set_buf;
67+
socket_set_count++;
68+
if (i) {
69+
*(env_value + p + 1) = 0;
70+
}
71+
}
72+
73+
p += sprintf(env_value + p + socket_set_buf, "%s%s=%s", (p && !socket_set_buf) ? "," : "", ls->key, fd);
74+
p += socket_set_buf;
5975
}
6076

6177
if (which == FPM_CLEANUP_PARENT_EXIT_MAIN) {
@@ -67,7 +83,14 @@ static void fpm_sockets_cleanup(int which, void *arg) /* {{{ */
6783
}
6884

6985
if (env_value) {
70-
setenv("FPM_SOCKETS", env_value, 1);
86+
for (i = 0; i < socket_set_count; i++) {
87+
if (!i) {
88+
strcpy(envname, "FPM_SOCKETS");
89+
} else {
90+
sprintf(envname, "FPM_SOCKETS_%d", i);
91+
}
92+
setenv(envname, env_value + socket_set[i], 1);
93+
}
7194
free(env_value);
7295
}
7396

@@ -352,36 +375,56 @@ int fpm_sockets_init_main() /* {{{ */
352375
{
353376
unsigned i, lq_len;
354377
struct fpm_worker_pool_s *wp;
355-
char *inherited = getenv("FPM_SOCKETS");
378+
char sockname[32];
379+
char sockpath[256];
380+
char *inherited;
356381
struct listening_socket_s *ls;
357382

358383
if (0 == fpm_array_init(&sockets_list, sizeof(struct listening_socket_s), 10)) {
359384
return -1;
360385
}
361386

362387
/* import inherited sockets */
363-
while (inherited && *inherited) {
364-
char *comma = strchr(inherited, ',');
365-
int type, fd_no;
366-
char *eq;
367-
368-
if (comma) {
369-
*comma = '\0';
388+
for (i = 0; i < FPM_ENV_SOCKET_SET_MAX; i++) {
389+
if (!i) {
390+
strcpy(sockname, "FPM_SOCKETS");
391+
} else {
392+
sprintf(sockname, "FPM_SOCKETS_%d", i);
370393
}
371-
372-
eq = strchr(inherited, '=');
373-
if (eq) {
374-
*eq = '\0';
375-
fd_no = atoi(eq + 1);
376-
type = fpm_sockets_domain_from_address(inherited);
377-
zlog(ZLOG_NOTICE, "using inherited socket fd=%d, \"%s\"", fd_no, inherited);
378-
fpm_sockets_hash_op(fd_no, 0, inherited, type, FPM_STORE_SOCKET);
394+
inherited = getenv(sockname);
395+
if (!inherited) {
396+
break;
379397
}
380398

381-
if (comma) {
382-
inherited = comma + 1;
383-
} else {
384-
inherited = 0;
399+
while (inherited && *inherited) {
400+
char *comma = strchr(inherited, ',');
401+
int type, fd_no;
402+
char *eq;
403+
404+
if (comma) {
405+
*comma = '\0';
406+
}
407+
408+
eq = strchr(inherited, '=');
409+
if (eq) {
410+
int sockpath_len = eq - inherited;
411+
if (sockpath_len > 255) {
412+
/* this should never happen as UDS limit is lower */
413+
sockpath_len = 255;
414+
}
415+
memcpy(sockpath, inherited, sockpath_len);
416+
sockpath[sockpath_len] = '\0';
417+
fd_no = atoi(eq + 1);
418+
type = fpm_sockets_domain_from_address(sockpath);
419+
zlog(ZLOG_NOTICE, "using inherited socket fd=%d, \"%s\"", fd_no, sockpath);
420+
fpm_sockets_hash_op(fd_no, 0, sockpath, type, FPM_STORE_SOCKET);
421+
}
422+
423+
if (comma) {
424+
inherited = comma + 1;
425+
} else {
426+
inherited = 0;
427+
}
385428
}
386429
}
387430

sapi/fpm/fpm/fpm_sockets.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@
1919
#if (__FreeBSD__) || (__OpenBSD__)
2020
#define FPM_BACKLOG_DEFAULT -1
2121
#else
22-
#define FPM_BACKLOG_DEFAULT 511
22+
#define FPM_BACKLOG_DEFAULT 511
2323
#endif
2424

25+
#define FPM_ENV_SOCKET_SET_MAX 256
26+
#define FPM_ENV_SOCKET_SET_SIZE 128
27+
2528
enum fpm_address_domain fpm_sockets_domain_from_address(char *addr);
2629
int fpm_sockets_init_main();
2730
int fpm_socket_get_listening_queue(int sock, unsigned *cur_lq, unsigned *max_lq);

0 commit comments

Comments
 (0)