pcntl_unshare_02.phpt 930 B

12345678910111213141516171819202122232425262728293031323334353637
  1. --TEST--
  2. pcntl_unshare() with CLONE_NEWPID
  3. --EXTENSIONS--
  4. pcntl
  5. posix
  6. --SKIPIF--
  7. <?php
  8. if (!function_exists("pcntl_unshare")) die("skip pcntl_unshare is not available");
  9. if (!defined("CLONE_NEWPID")) die("skip flag unavailable");
  10. if (getenv("SKIP_ASAN")) die("skip asan chokes on this");
  11. if (posix_getuid() !== 0 &&
  12. (!defined("CLONE_NEWUSER") ||
  13. (@pcntl_unshare(CLONE_NEWUSER) == false && pcntl_get_last_error() == PCNTL_EPERM))) {
  14. die("skip Insufficient privileges for CLONE_NEWUSER");
  15. }
  16. if (@pcntl_unshare(CLONE_NEWPID) == false && pcntl_get_last_error() == PCNTL_EPERM) {
  17. die("skip Insufficient privileges for CLONE_NEWPID");
  18. }
  19. if (getenv("SKIP_REPEAT")) die("skip cannot be repeated");
  20. ?>
  21. --FILE--
  22. <?php
  23. if(posix_getuid() !== 0) {
  24. pcntl_unshare(CLONE_NEWUSER);
  25. }
  26. var_dump(getmypid());
  27. pcntl_unshare(CLONE_NEWPID);
  28. if(!pcntl_fork()) {
  29. var_dump(getmypid());
  30. exit();
  31. }
  32. ?>
  33. --EXPECTF--
  34. int(%d)
  35. int(1)