Skip to content

Commit bd6776d

Browse files
Revert fpm_sockets.c changes
1 parent fc9185b commit bd6776d

File tree

1 file changed

+42
-28
lines changed

1 file changed

+42
-28
lines changed

sapi/fpm/fpm/fpm_sockets.c

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* (c) 2007,2008 Andrei Nigmatulin */
1+
/* (c) 2007,2008 Andrei Nigmatulin */
22

33
#include "fpm_config.h"
44

@@ -27,7 +27,6 @@
2727
#include "fpm_env.h"
2828
#include "fpm_cleanup.h"
2929
#include "fpm_scoreboard.h"
30-
#include "zend_smart_string.h"
3130

3231
struct listening_socket_s {
3332
int refcount;
@@ -59,24 +58,40 @@ static void fpm_sockets_cleanup(int which, void *arg) /* {{{ */
5958
unsigned i;
6059
unsigned socket_set_count = 0;
6160
unsigned socket_set[FPM_ENV_SOCKET_SET_MAX];
61+
unsigned socket_set_buf = 0;
6262
char envname[32];
63-
smart_string env_str = {0};
63+
char *env_value = 0;
64+
int p = 0;
6465
struct listening_socket_s *ls = sockets_list.data;
6566

6667
for (i = 0; i < sockets_list.used; i++, ls++) {
6768
if (which != FPM_CLEANUP_PARENT_EXEC) {
6869
close(ls->sock);
6970
} else { /* on PARENT EXEC we want socket fds to be inherited through environment variable */
71+
char fd[32];
72+
char *tmpenv_value;
73+
snprintf(fd, sizeof(fd), "%d", ls->sock);
74+
75+
socket_set_buf = (i % FPM_ENV_SOCKET_SET_SIZE == 0 && i) ? 1 : 0;
76+
tmpenv_value = realloc(env_value, p + (p ? 1 : 0) + strlen(ls->key) + 1 + strlen(fd) + socket_set_buf + 1);
77+
if (!tmpenv_value) {
78+
zlog(ZLOG_SYSERROR, "failure to inherit data on parent exec for socket `%s` due to memory allocation failure", ls->key);
79+
free(ls->key);
80+
break;
81+
}
82+
83+
env_value = tmpenv_value;
84+
7085
if (i % FPM_ENV_SOCKET_SET_SIZE == 0) {
71-
smart_string_appendc(&env_str, '\0');
72-
socket_set[socket_set_count] = env_str.len;
86+
socket_set[socket_set_count] = p + socket_set_buf;
7387
socket_set_count++;
74-
} else {
75-
smart_string_appendc(&env_str, ',');
88+
if (i) {
89+
*(env_value + p + 1) = 0;
90+
}
7691
}
77-
smart_string_appends(&env_str, ls->key);
78-
smart_string_appendc(&env_str, '=');
79-
smart_string_append_long(&env_str, ls->sock);
92+
93+
p += sprintf(env_value + p + socket_set_buf, "%s%s=%s", (p && !socket_set_buf) ? "," : "", ls->key, fd);
94+
p += socket_set_buf;
8095
}
8196

8297
if (which == FPM_CLEANUP_PARENT_EXIT_MAIN) {
@@ -87,15 +102,14 @@ static void fpm_sockets_cleanup(int which, void *arg) /* {{{ */
87102
free(ls->key);
88103
}
89104

90-
if (env_str.c) {
91-
smart_string_appendc(&env_str, '\0');
105+
if (env_value) {
92106
for (i = 0; i < socket_set_count; i++) {
93107
fpm_sockets_get_env_name(envname, sizeof(envname), i);
94-
setenv(envname, env_str.c + socket_set[i], 1);
108+
setenv(envname, env_value + socket_set[i], 1);
95109
}
96110
fpm_sockets_get_env_name(envname, sizeof(envname), socket_set_count);
97111
unsetenv(envname);
98-
smart_string_free(&env_str);
112+
free(env_value);
99113
}
100114

101115
fpm_array_free(&sockets_list);
@@ -383,24 +397,24 @@ static int fpm_socket_af_inet_listening_socket(struct fpm_worker_pool_s *wp) /*
383397
static int fpm_socket_af_unix_listening_socket(struct fpm_worker_pool_s *wp) /* {{{ */
384398
{
385399
struct sockaddr_un sa_un;
386-
size_t socket_length = sizeof(sa_un.sun_path);
387-
size_t address_length = strlen(wp->config->listen_address);
400+
size_t socket_length = sizeof(sa_un.sun_path);
401+
size_t address_length = strlen(wp->config->listen_address);
388402

389403
memset(&sa_un, 0, sizeof(sa_un));
390404
strlcpy(sa_un.sun_path, wp->config->listen_address, socket_length);
391405

392-
if (address_length >= socket_length) {
393-
zlog(
394-
ZLOG_WARNING,
395-
"[pool %s] cannot bind to UNIX socket '%s' as path is too long (found length: %zu, "
406+
if (address_length >= socket_length) {
407+
zlog(
408+
ZLOG_WARNING,
409+
"[pool %s] cannot bind to UNIX socket '%s' as path is too long (found length: %zu, "
396410
"maximal length: %zu), trying cut socket path instead '%s'",
397-
wp->config->name,
398-
wp->config->listen_address,
399-
address_length,
400-
socket_length,
401-
sa_un.sun_path
402-
);
403-
}
411+
wp->config->name,
412+
wp->config->listen_address,
413+
address_length,
414+
socket_length,
415+
sa_un.sun_path
416+
);
417+
}
404418

405419
sa_un.sun_family = AF_UNIX;
406420
return fpm_sockets_get_listening_socket(wp, (struct sockaddr *) &sa_un, sizeof(struct sockaddr_un));
@@ -499,7 +513,7 @@ int fpm_sockets_init_main(void)
499513
return -1;
500514
}
501515

502-
if (wp->listen_address_domain == FPM_AF_INET && fpm_socket_get_listening_queue(wp->listening_socket, NULL, &lq_len) >= 0) {
516+
if (wp->listen_address_domain == FPM_AF_INET && fpm_socket_get_listening_queue(wp->listening_socket, NULL, &lq_len) >= 0) {
503517
fpm_scoreboard_update(-1, -1, -1, (int)lq_len, -1, -1, 0, 0, FPM_SCOREBOARD_ACTION_SET, wp->scoreboard);
504518
}
505519
}

0 commit comments

Comments
 (0)