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