From fc5b228db537461bcd198ac9a8352418cf88677c Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 5 May 2022 09:52:46 -0700 Subject: [PATCH] Return STDIN, STDOUT, and STDERR file descriptors from parent process Summary: Ref T13675. When a process daemonizes, it needs to close these actual file descriptors, so the calling context must provide them. Elsewhere, modify the embedded "arc" to provide them. Then use them in place of reopening the streams. Test Plan: Ran locally with embedded "arc", will deploy for production hangs. Maniphest Tasks: T13675 Differential Revision: https://secure.phabricator.com/D21804 --- src/utils/PhutilSystem.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/utils/PhutilSystem.php b/src/utils/PhutilSystem.php index 3657d8b0..d2c053a5 100644 --- a/src/utils/PhutilSystem.php +++ b/src/utils/PhutilSystem.php @@ -17,7 +17,7 @@ final class PhutilSystem extends Phobject { */ public static function getStdinHandle() { if (self::$stdin === false) { - self::$stdin = self::newStdioHandle('php://stdin'); + self::$stdin = self::getStdioHandle('STDIN'); } return self::$stdin; @@ -28,7 +28,7 @@ final class PhutilSystem extends Phobject { */ public static function getStdoutHandle() { if (self::$stdout === false) { - self::$stdout = self::newStdioHandle('php://stdout'); + self::$stdout = self::getStdioHandle('STDOUT'); } return self::$stdout; @@ -39,7 +39,7 @@ final class PhutilSystem extends Phobject { */ public static function getStderrHandle() { if (self::$stderr === false) { - self::$stderr = self::newStdioHandle('php://stderr'); + self::$stderr = self::getStdioHandle('STDERR'); } return self::$stderr; @@ -63,15 +63,12 @@ final class PhutilSystem extends Phobject { /** * @task stdio */ - private static function newStdioHandle($ref) { - $ignored_mode = ''; - - $handle = @fopen($ref, $ignored_mode); - if ($handle === false) { - return null; + private static function getStdioHandle($ref) { + if (defined($ref)) { + return constant($ref); } - return $handle; + return null; } /**