Skip to content

Commit 066553c

Browse files
TimWollabukka
andauthored
fpm: Improve the error message when FPM is running as root (#19695)
* fpm: Improve the error message when FPM is running as root Co-authored-by: Jakub Zelenka <[email protected]> * fpm: Disable `TEST_FPM_RUN_AS_ROOT` for proc-user-not-set-when-root.phpt --------- Co-authored-by: Jakub Zelenka <[email protected]>
1 parent 1c664e1 commit 066553c

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

sapi/fpm/fpm/fpm_conf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ static int fpm_conf_process_all_pools(void)
859859

860860
/* alert if user is not set; only if we are root and fpm is not running with --allow-to-run-as-root */
861861
if (!wp->config->user && !geteuid() && !fpm_globals.run_as_root) {
862-
zlog(ZLOG_ALERT, "[pool %s] user has not been defined", wp->config->name);
862+
zlog(ZLOG_ALERT, "[pool %s] 'user' directive has not been specified when running as a root without --allow-to-run-as-root", wp->config->name);
863863
return -1;
864864
}
865865

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
--TEST--
2+
FPM: Process user setting unset when running as root
3+
--SKIPIF--
4+
<?php
5+
include "skipif.inc";
6+
FPM\Tester::skipIfNotRoot();
7+
?>
8+
--FILE--
9+
<?php
10+
11+
require_once "tester.inc";
12+
13+
$cfg = <<<EOT
14+
[global]
15+
error_log = {{FILE:LOG}}
16+
[unconfined]
17+
listen = {{ADDR}}
18+
ping.path = /ping
19+
ping.response = pong
20+
pm = dynamic
21+
pm.max_children = 5
22+
pm.start_servers = 2
23+
pm.min_spare_servers = 1
24+
pm.max_spare_servers = 3
25+
EOT;
26+
27+
$tester = new FPM\Tester($cfg);
28+
$tester->start(envVars: [
29+
'TEST_FPM_RUN_AS_ROOT' => 0,
30+
]);
31+
$tester->expectLogAlert(
32+
"'user' directive has not been specified when running as a root without --allow-to-run-as-root",
33+
'unconfined'
34+
);
35+
$tester->close();
36+
37+
?>
38+
Done
39+
--EXPECT--
40+
Done
41+
--CLEAN--
42+
<?php
43+
require_once "tester.inc";
44+
FPM\Tester::clean();
45+
?>

sapi/fpm/tests/tester.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ class Tester
540540
$cmd[] = '-d' . $iniEntryName . '=' . $iniEntryValue;
541541
}
542542

543-
if (getenv('TEST_FPM_RUN_AS_ROOT')) {
543+
if ($envVars['TEST_FPM_RUN_AS_ROOT'] ?? getenv('TEST_FPM_RUN_AS_ROOT')) {
544544
$cmd[] = '--allow-to-run-as-root';
545545
}
546546
$cmd = array_merge($cmd, $extraArgs);

0 commit comments

Comments
 (0)