@@ -44,6 +44,10 @@ enum { FPM_GET_USE_SOCKET = 1, FPM_STORE_SOCKET = 2, FPM_STORE_USE_SOCKET = 3 };
44
44
static void fpm_sockets_cleanup (int which , void * arg ) /* {{{ */
45
45
{
46
46
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 [16 ];
47
51
char * env_value = 0 ;
48
52
int p = 0 ;
49
53
struct listening_socket_s * ls = sockets_list .data ;
@@ -54,8 +58,20 @@ static void fpm_sockets_cleanup(int which, void *arg) /* {{{ */
54
58
} else { /* on PARENT EXEC we want socket fds to be inherited through environment variable */
55
59
char fd [32 ];
56
60
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 ;
59
75
}
60
76
61
77
if (which == FPM_CLEANUP_PARENT_EXIT_MAIN ) {
@@ -67,7 +83,10 @@ static void fpm_sockets_cleanup(int which, void *arg) /* {{{ */
67
83
}
68
84
69
85
if (env_value ) {
70
- setenv ("FPM_SOCKETS" , env_value , 1 );
86
+ for (i = 0 ; i < socket_set_count ; i ++ ) {
87
+ sprintf (envname , "FPM_SOCKETS_%d" , i );
88
+ setenv (envname , env_value + socket_set [i ], 1 );
89
+ }
71
90
free (env_value );
72
91
}
73
92
@@ -324,36 +343,43 @@ int fpm_sockets_init_main() /* {{{ */
324
343
{
325
344
unsigned i , lq_len ;
326
345
struct fpm_worker_pool_s * wp ;
327
- char * inherited = getenv ("FPM_SOCKETS" );
346
+ char sockname [16 ];
347
+ char * inherited ;
328
348
struct listening_socket_s * ls ;
329
349
330
350
if (0 == fpm_array_init (& sockets_list , sizeof (struct listening_socket_s ), 10 )) {
331
351
return -1 ;
332
352
}
333
353
334
354
/* import inherited sockets */
335
- while (inherited && * inherited ) {
336
- char * comma = strchr (inherited , ',' );
337
- int type , fd_no ;
338
- char * eq ;
339
-
340
- if (comma ) {
341
- * comma = '\0' ;
342
- }
355
+ for (i = 0 ; i < FPM_ENV_SOCKET_SET_MAX ; i ++ ) {
356
+ sprintf (sockname , "FPM_SOCKETS_%d" , i );
357
+ inherited = getenv (sockname );
358
+ if (!inherited ) break ;
359
+
360
+ while (inherited && * inherited ) {
361
+ char * comma = strchr (inherited , ',' );
362
+ int type , fd_no ;
363
+ char * eq ;
364
+
365
+ if (comma ) {
366
+ * comma = '\0' ;
367
+ }
343
368
344
- eq = strchr (inherited , '=' );
345
- if (eq ) {
346
- * eq = '\0' ;
347
- fd_no = atoi (eq + 1 );
348
- type = fpm_sockets_domain_from_address (inherited );
349
- zlog (ZLOG_NOTICE , "using inherited socket fd=%d, \"%s\"" , fd_no , inherited );
350
- fpm_sockets_hash_op (fd_no , 0 , inherited , type , FPM_STORE_SOCKET );
351
- }
369
+ eq = strchr (inherited , '=' );
370
+ if (eq ) {
371
+ * eq = '\0' ;
372
+ fd_no = atoi (eq + 1 );
373
+ type = fpm_sockets_domain_from_address (inherited );
374
+ zlog (ZLOG_NOTICE , "using inherited socket fd=%d, \"%s\"" , fd_no , inherited );
375
+ fpm_sockets_hash_op (fd_no , 0 , inherited , type , FPM_STORE_SOCKET );
376
+ }
352
377
353
- if (comma ) {
354
- inherited = comma + 1 ;
355
- } else {
356
- inherited = 0 ;
378
+ if (comma ) {
379
+ inherited = comma + 1 ;
380
+ } else {
381
+ inherited = 0 ;
382
+ }
357
383
}
358
384
}
359
385
0 commit comments