Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions ext/standard/VmProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ final class VmProcess
*/
public static function getrusage(int $who = 0)
{
$raw = false;
if (VmGetrusageNative::available()) {
$raw = VmGetrusageNative::getrusage($who);
} elseif (\function_exists('getrusage')) {
$raw = @\getrusage($who);
}
$raw = VmGetrusageNative::available()
? VmGetrusageNative::getrusage($who)
: false;
if (false === $raw) {
return false;
}
Expand Down
31 changes: 1 addition & 30 deletions ext/standard/VmProcessIdentity.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* Process identity builtins (issue #6119, native libc #7891).
*
* php-src: ext/standard/basic_functions.c — getmyuid, getmygid, get_current_user.
* No host \\posix_* / \\get*() delegation — libc FFI only (pairs #7287 getrusage shrink).
*/
final class VmProcessIdentity
{
Expand All @@ -19,12 +20,6 @@ public static function getmyuid(): int
return $uid;
}
}
if (\function_exists('posix_getuid')) {
return (int) \posix_getuid();
}
if (\function_exists('getuid')) {
return (int) \getuid();
}

throw new \LogicException('getmyuid() requires POSIX support in this compiler build');
}
Expand All @@ -37,12 +32,6 @@ public static function getmygid(): int
return $gid;
}
}
if (\function_exists('posix_getgid')) {
return (int) \posix_getgid();
}
if (\function_exists('getgid')) {
return (int) \getgid();
}

throw new \LogicException('getmygid() requires POSIX support in this compiler build');
}
Expand All @@ -58,24 +47,6 @@ public static function getCurrentUser(): string
}
}
}
$euid = null;
if (\function_exists('posix_geteuid')) {
$euid = (int) \posix_geteuid();
} elseif (\function_exists('geteuid')) {
$euid = (int) \geteuid();
}
if (null !== $euid && \function_exists('posix_getpwuid')) {
$pw = @\posix_getpwuid($euid);
if (\is_array($pw) && isset($pw['name']) && '' !== $pw['name']) {
return (string) $pw['name'];
}
}
if (null !== $euid && \function_exists('getpwuid')) {
$pw = @\getpwuid($euid);
if (\is_object($pw) && isset($pw->pw_name) && '' !== $pw->pw_name) {
return (string) $pw->pw_name;
}
}

return 'Unknown';
}
Expand Down
2 changes: 2 additions & 0 deletions test/unit/VmGetrusageNativeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public function testVmProcessPrefersNativeOverHostDelegation(): void
$this->assertStringContainsString('VmGetrusageNative::available()', $source);
$this->assertStringContainsString('VmGetrusageNative::getrusage', $source);
$this->assertStringNotContainsString('host libc via Zend PHP', $source);
$this->assertStringNotContainsString("function_exists('getrusage')", $source);
$this->assertDoesNotMatchRegularExpression('/\\\\getrusage\\s*\\(/', $source);
}

public function testNativeDefinesLibcGetrusageFfi(): void
Expand Down
7 changes: 7 additions & 0 deletions test/unit/VmProcessIdentityNativeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ public function testVmProcessIdentityPrefersNativeOverHostDelegation(): void
$this->assertStringContainsString('VmProcessIdentityNative::getgid()', $source);
$this->assertStringContainsString('VmProcessIdentityNative::geteuid()', $source);
$this->assertStringContainsString('VmProcessIdentityNative::getpwuidName', $source);
$this->assertStringNotContainsString("function_exists('posix_", $source);
$this->assertStringNotContainsString("function_exists('getuid')", $source);
$this->assertStringNotContainsString("function_exists('getgid')", $source);
$this->assertStringNotContainsString("function_exists('geteuid')", $source);
$this->assertStringNotContainsString("function_exists('getpwuid')", $source);
$this->assertDoesNotMatchRegularExpression('/\\\\posix_[a-z_]+\\(/', $source);
$this->assertDoesNotMatchRegularExpression('/\\\\getpwuid\\s*\\(/', $source);
}

public function testVmDateGetmygrgidUsesProcessIdentity(): void
Expand Down