com php-src: Skip FPM tests when running as root (unless requested): sapi/fpm/tests/include.inc sapi/fpm/tests/skipif.inc

[email protected] (Sara Golemon)
Newsgroups php.cvs
Message-ID <[email protected]>
Commit:    d8d1c78ed08423738376adc450aba3932b33a20e
Author:    Sara Golemon <[email protected]>         Wed, 24 May 2017 12:41:57 -0700
Parents:   7c7383067f6719324004407e17c0f5d6c740c39f
Branches:  master

Link:       http://git.php.net/?p=php-src.git;a=commitdiff;h=d8d1c78ed08423738376adc450aba3932b33a20e

Log:
Skip FPM tests when running as root (unless requested)

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.

Changed paths:
  M  sapi/fpm/tests/include.inc
  M  sapi/fpm/tests/skipif.inc


Diff:
diff --git a/sapi/fpm/tests/include.inc b/sapi/fpm/tests/include.inc
index 8faf53d..1e41957 100644
--- a/sapi/fpm/tests/include.inc
+++ b/sapi/fpm/tests/include.inc
@@ -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);
diff --git a/sapi/fpm/tests/skipif.inc b/sapi/fpm/tests/skipif.inc
index 8c569da..08c6bbf 100644
--- a/sapi/fpm/tests/skipif.inc
+++ b/sapi/fpm/tests/skipif.inc
@@ -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");
 }
-
 ?>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.