0

[ios blink] Replicate stdout/stderr to child process

To aid with debugging in the simulator replicate stdout/stderr
file handles so that we can receive logging in the parent
process. This does not work on the device because the write
SWI is blocked (although you can disable the sandbox) to make
it work.

Bug: 40254930
Change-Id: I3f417b7661c36703464261c9fe0a78c76f8ccf7d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6235527
Commit-Queue: Dave Tapuska <dtapuska@chromium.org>
Reviewed-by: Justin Cohen <justincohen@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1416339}
This commit is contained in:
Dave Tapuska
2025-02-05 11:14:43 -08:00
committed by Chromium LUCI CQ
parent f0371fa68b
commit 5f05abaee9
2 changed files with 14 additions and 0 deletions

@ -57,6 +57,18 @@ extern "C" IOS_INIT_EXPORT void ChildProcessHandleNewConnection(
g_argv[i] = strdup(xpc_array_get_string(args_array, i));
}
// Setup stdout/stderr.
int fd = xpc_dictionary_dup_fd(msg, "stdout");
if (fd != -1) {
dup2(fd, STDOUT_FILENO);
close(fd);
}
fd = xpc_dictionary_dup_fd(msg, "stderr");
if (fd != -1) {
dup2(fd, STDERR_FILENO);
close(fd);
}
mach_port_t port = xpc_dictionary_copy_mach_send(msg, "port");
base::apple::ScopedMachSendRight server_port(port);
bool res =

@ -293,6 +293,8 @@ void ChildProcessLauncherHelper::OnChildProcessStarted(
xpc_array_append_value(args_array, value);
}
xpc_dictionary_set_value(message, "args", args_array);
xpc_dictionary_set_fd(message, "stdout", STDOUT_FILENO);
xpc_dictionary_set_fd(message, "stderr", STDERR_FILENO);
xpc_dictionary_set_mach_send(
message, "port", rendezvous_server_->GetMachSendRight().get());
xpc_connection_send_message(xpc_connection, message);