]> granicus.if.org Git - php/commitdiff
Skip FPM tests when running as root (unless requested)
authorSara Golemon <pollita@php.net>
Wed, 24 May 2017 19:41:57 +0000 (12:41 -0700)
committerSara Golemon <pollita@php.net>
Wed, 24 May 2017 20:58:18 +0000 (13:58 -0700)
FPM must be configured as a user.
Normally it defaults to the current user,
but if that's root it'll fail to startup
unless the --run-as-root option is provided.

Extend that logic into the test runner so that
we don't fail for stupid reasons.

If you're running `make test` as root and you want
FPM tests to run anyway, set TEST_FPM_RUN_AS_ROOT=1
in your environment.

sapi/fpm/tests/include.inc
sapi/fpm/tests/skipif.inc

index 8faf53dcc210ce582be89b5178f5e4a351ccd2e0..1e41957c7c21c0efb869bfeac0e32c9948b09e28 100644 (file)
@@ -38,7 +38,10 @@ function run_fpm($config, &$out = false, $extra_args = '') /* {{{ */
     /* Since it's not possible to spawn a process under linux without using a
      * shell in php (why?!?) we need a little shell trickery, so that we can
      * actually kill php-fpm */
-    $fpm = proc_open('killit () { kill $child; }; trap killit TERM; '.get_fpm_path().' -F -O -y '.$cfg.' '.$extra_args.' 2>&1 & child=$!; wait', $desc, $pipes);
+    $asroot = getenv('TEST_FPM_RUN_AS_ROOT') ? '--allow-to-run-as-root' : '';
+    $cmd = get_fpm_path()." $asroot -F -O -y $cfg $extra_args";
+    $fpm = proc_open("killit () { kill \$child; }; trap killit TERM; $cmd 2>&1 & child=\$!; wait",
+                     $desc, $pipes);
     register_shutdown_function(
             function($fpm) use($cfg) {
                     @unlink($cfg);
index 8c569daafdc7e9fb2440fbb1646b9fdbd38f8026..08c6bbff69df098bbb1dd64c0775097ec8df41a9 100644 (file)
@@ -4,10 +4,14 @@ if (substr(PHP_OS, 0, 3) == 'WIN') {
        die ("skip not for Windows");
 }
 
+
+if (!getmyuid() && !getenv('TEST_FPM_RUN_AS_ROOT')) {
+       die('Refusing to run as root');
+}
+
 include dirname(__FILE__)."/include.inc";
 
 if (!get_fpm_path()) {
        die("skip FPM not found");
 }
-
 ?>