1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

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 <bukka@php.net>

* fpm: Disable `TEST_FPM_RUN_AS_ROOT` for proc-user-not-set-when-root.phpt

---------

Co-authored-by: Jakub Zelenka <bukka@php.net>
This commit is contained in:
Tim Düsterhus
2025-09-04 18:58:59 +02:00
committed by GitHub
parent 1c664e1c74
commit 066553c454
3 changed files with 47 additions and 2 deletions

View File

@@ -859,7 +859,7 @@ static int fpm_conf_process_all_pools(void)
/* alert if user is not set; only if we are root and fpm is not running with --allow-to-run-as-root */
if (!wp->config->user && !geteuid() && !fpm_globals.run_as_root) {
zlog(ZLOG_ALERT, "[pool %s] user has not been defined", wp->config->name);
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);
return -1;
}

View File

@@ -0,0 +1,45 @@
--TEST--
FPM: Process user setting unset when running as root
--SKIPIF--
<?php
include "skipif.inc";
FPM\Tester::skipIfNotRoot();
?>
--FILE--
<?php
require_once "tester.inc";
$cfg = <<<EOT
[global]
error_log = {{FILE:LOG}}
[unconfined]
listen = {{ADDR}}
ping.path = /ping
ping.response = pong
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
EOT;
$tester = new FPM\Tester($cfg);
$tester->start(envVars: [
'TEST_FPM_RUN_AS_ROOT' => 0,
]);
$tester->expectLogAlert(
"'user' directive has not been specified when running as a root without --allow-to-run-as-root",
'unconfined'
);
$tester->close();
?>
Done
--EXPECT--
Done
--CLEAN--
<?php
require_once "tester.inc";
FPM\Tester::clean();
?>

View File

@@ -540,7 +540,7 @@ class Tester
$cmd[] = '-d' . $iniEntryName . '=' . $iniEntryValue;
}
if (getenv('TEST_FPM_RUN_AS_ROOT')) {
if ($envVars['TEST_FPM_RUN_AS_ROOT'] ?? getenv('TEST_FPM_RUN_AS_ROOT')) {
$cmd[] = '--allow-to-run-as-root';
}
$cmd = array_merge($cmd, $extraArgs);