Skip to content

Commit 118cd3e

Browse files
committed
Merge branch 'PHP-8.0'
2 parents 37969dc + 713b821 commit 118cd3e

File tree

5 files changed

+209
-38
lines changed

5 files changed

+209
-38
lines changed

sapi/fpm/fpm/fpm_sockets.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@ static struct fpm_array_s sockets_list;
3939

4040
enum { FPM_GET_USE_SOCKET = 1, FPM_STORE_SOCKET = 2, FPM_STORE_USE_SOCKET = 3 };
4141

42+
static inline void fpm_sockets_get_env_name(char *envname, unsigned idx) /* {{{ */
43+
{
44+
if (!idx) {
45+
strcpy(envname, "FPM_SOCKETS");
46+
} else {
47+
sprintf(envname, "FPM_SOCKETS_%d", idx);
48+
}
49+
}
50+
/* }}} */
51+
4252
static void fpm_sockets_cleanup(int which, void *arg) /* {{{ */
4353
{
4454
unsigned i;
@@ -82,13 +92,11 @@ static void fpm_sockets_cleanup(int which, void *arg) /* {{{ */
8292

8393
if (env_value) {
8494
for (i = 0; i < socket_set_count; i++) {
85-
if (!i) {
86-
strcpy(envname, "FPM_SOCKETS");
87-
} else {
88-
sprintf(envname, "FPM_SOCKETS_%d", i);
89-
}
95+
fpm_sockets_get_env_name(envname, i);
9096
setenv(envname, env_value + socket_set[i], 1);
9197
}
98+
fpm_sockets_get_env_name(envname, socket_set_count);
99+
unsetenv(envname);
92100
free(env_value);
93101
}
94102

@@ -373,7 +381,7 @@ int fpm_sockets_init_main() /* {{{ */
373381
{
374382
unsigned i, lq_len;
375383
struct fpm_worker_pool_s *wp;
376-
char sockname[32];
384+
char envname[32];
377385
char sockpath[256];
378386
char *inherited;
379387
struct listening_socket_s *ls;
@@ -384,12 +392,8 @@ int fpm_sockets_init_main() /* {{{ */
384392

385393
/* import inherited sockets */
386394
for (i = 0; i < FPM_ENV_SOCKET_SET_MAX; i++) {
387-
if (!i) {
388-
strcpy(sockname, "FPM_SOCKETS");
389-
} else {
390-
sprintf(sockname, "FPM_SOCKETS_%d", i);
391-
}
392-
inherited = getenv(sockname);
395+
fpm_sockets_get_env_name(envname, i);
396+
inherited = getenv(envname);
393397
if (!inherited) {
394398
break;
395399
}

sapi/fpm/tests/bug68391-conf-include-order.phpt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,15 @@ log_level = notice
1717
include = {{INCLUDE:CONF}}
1818
EOT;
1919

20-
$cfgPoolTemplate = <<<EOT
20+
$cfg['poolTemplate'] = <<<EOT
2121
[%name%]
2222
listen = {{ADDR[%name%]}}
2323
user = foo
2424
pm = ondemand
2525
pm.max_children = 5
2626
EOT;
2727

28-
$names = ['cccc', 'aaaa', 'eeee', 'dddd', 'bbbb'];
29-
foreach($names as $name) {
30-
$cfg[$name] = str_replace('%name%', $name, $cfgPoolTemplate);
31-
}
28+
$cfg['names'] = ['cccc', 'aaaa', 'eeee', 'dddd', 'bbbb'];
3229

3330
$tester = new FPM\Tester($cfg);
3431
$tester->start();
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
--TEST--
2+
FPM: bug80024 - Duplication of info about inherited socket after pool removing
3+
--SKIPIF--
4+
<?php include "skipif.inc"; ?>
5+
--FILE--
6+
<?php
7+
8+
require_once "tester.inc";
9+
10+
$cfg['main'] = <<<EOT
11+
[global]
12+
error_log = {{FILE:LOG}}
13+
pid = {{FILE:PID}}
14+
include = {{INCLUDE:CONF}}
15+
EOT;
16+
17+
$cfg['poolTemplate'] = <<<EOT
18+
[pool_%index%]
19+
listen = {{ADDR:UDS[pool_%index%]}}
20+
pm = ondemand
21+
pm.start_servers = 2
22+
pm.min_spare_servers = 1
23+
pm.max_spare_servers = 3
24+
pm.max_children = 5
25+
EOT;
26+
27+
$cfg['count'] = 129;
28+
29+
$tester = new FPM\Tester($cfg);
30+
$tester->start();
31+
$tester->expectLogStartNotices();
32+
$cfg['count'] = 128;
33+
$tester->reload($cfg);
34+
$tester->expectLogReloadingNotices(129);
35+
$tester->reload();
36+
$tester->expectLogReloadingNotices(128);
37+
$tester->terminate();
38+
$tester->expectLogTerminatingNotices();
39+
$tester->close();
40+
41+
?>
42+
Done
43+
--EXPECT--
44+
Done
45+
--CLEAN--
46+
<?php
47+
require_once "tester.inc";
48+
FPM\Tester::clean();
49+
?>

sapi/fpm/tests/logtool.inc

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ class LogTool
99
const P_PREFIX_STDOUT = '\[pool unconfined\] child \d+ said into stdout: ';
1010
const FINAL_SUFFIX = ', pipe is closed';
1111

12+
const DEBUG = 'DEBUG';
13+
const NOTICE = 'NOTICE';
14+
const WARNING = 'WARNING';
15+
const ERROR = 'ERROR';
16+
const ALERT = 'ALERT';
17+
1218
/**
1319
* @var string
1420
*/
@@ -278,6 +284,28 @@ class LogTool
278284
return true;
279285
}
280286

287+
/**
288+
* @param array $lines
289+
* @return bool
290+
*/
291+
public function expectReloadingLines(array $lines)
292+
{
293+
if (
294+
!$this->expectNotice($lines[0], 'Reloading in progress ...') ||
295+
!$this->expectNotice($lines[1], 'reloading: .*')
296+
) {
297+
return false;
298+
}
299+
300+
for ($i = 2; $i < count($lines) - 2; $i++) {
301+
if (!$this->expectNotice($lines[$i], 'using inherited socket fd=\d+, "[^"]+"')) {
302+
return false;
303+
}
304+
}
305+
306+
return $this->expectStartingLines(array_splice($lines, $i));
307+
}
308+
281309
/**
282310
* @param array $lines
283311
* @return bool
@@ -359,7 +387,7 @@ class LogTool
359387
*/
360388
public function expectDebug(string $line, string $expectedMessage, $pool = null)
361389
{
362-
return $this->expectEntry('DEBUG', $line, $expectedMessage, $pool);
390+
return $this->expectEntry(self::DEBUG, $line, $expectedMessage, $pool);
363391
}
364392

365393
/**
@@ -370,7 +398,7 @@ class LogTool
370398
*/
371399
public function expectNotice(string $line, string $expectedMessage, $pool = null)
372400
{
373-
return $this->expectEntry('NOTICE', $line, $expectedMessage, $pool);
401+
return $this->expectEntry(self::NOTICE, $line, $expectedMessage, $pool);
374402
}
375403

376404
/**
@@ -381,7 +409,7 @@ class LogTool
381409
*/
382410
public function expectWarning(string $line, string $expectedMessage, $pool = null)
383411
{
384-
return $this->expectEntry('WARNING', $line, $expectedMessage, $pool);
412+
return $this->expectEntry(self::WARNING, $line, $expectedMessage, $pool);
385413
}
386414

387415
/**
@@ -392,7 +420,7 @@ class LogTool
392420
*/
393421
public function expectError(string $line, string $expectedMessage, $pool = null)
394422
{
395-
return $this->expectEntry('ERROR', $line, $expectedMessage, $pool);
423+
return $this->expectEntry(self::ERROR, $line, $expectedMessage, $pool);
396424
}
397425

398426
/**
@@ -403,10 +431,9 @@ class LogTool
403431
*/
404432
public function expectAlert(string $line, string $expectedMessage, $pool = null)
405433
{
406-
return $this->expectEntry('ALERT', $line, $expectedMessage, $pool);
434+
return $this->expectEntry(self::ALERT, $line, $expectedMessage, $pool);
407435
}
408436

409-
410437
/**
411438
* @param string $msg
412439
* @return bool

0 commit comments

Comments
 (0)