[vm/dart:io/fuchsia] Improve fdio_pipe_half signature, step 2.

The return value on fdio_pipe_half conflated two things: the error code
on failure (as a zx_status_t) or a file descriptor on success. This
technically worked, because they're both ints, the error code was always
negative, and the file descriptor always positive. However, the stated
return type of zx_status_t was misleading. This changes the signature
such that it always returns an actual zx_status_t, and the file
descriptor is returned through a pointer argument.

Also remove the last argument, since it was always given the same value.

This needs to be done as a soft transition because it's called from the
Dart runtime. The steps are as follows:
1. Add fdio_pipe_half2 with the new signature.
2. Update the Dart runtime to call fdio_pipe_half2.
3. Change fdio_pipe_half to be identical to fdio_pipe_half2.
4. Update the Dart runtime to call the updated fdio_pipe_half.
5. Delete fdio_pipe_half2.

This is step 2.

Change-Id: Ieac841c5f8055f34000851cef364a12b6c0aca2a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/96664
Commit-Queue: Zach Anderson <zra@google.com>
Auto-Submit: Michael Powell <mikepowell@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
This commit is contained in:
Michael Powell 2019-03-28 17:45:55 +00:00 committed by commit-bot@chromium.org
parent 1926f69e4d
commit dfcc52f909

View file

@ -664,12 +664,10 @@ class ProcessStarter {
zx_status_t AddPipe(int target_fd, int* local_fd,
fdio_spawn_action_t* action) {
zx_status_t status = fdio_pipe_half(&action->h.handle, &action->h.id);
if (status < 0)
return status;
*local_fd = status;
zx_status_t status = fdio_pipe_half2(local_fd, &action->h.handle);
if (status != ZX_OK) return status;
action->action = FDIO_SPAWN_ACTION_ADD_HANDLE;
action->h.id = PA_HND(PA_HND_TYPE(action->h.id), target_fd);
action->h.id = PA_HND(PA_HND_TYPE(PA_FD), target_fd);
return ZX_OK;
}
@ -677,11 +675,12 @@ class ProcessStarter {
intptr_t BuildSpawnActions(fdio_ns_t* ns, fdio_spawn_action_t** actions_out) {
const intptr_t fixed_actions_cnt = 4;
intptr_t ns_cnt = 0;
zx_status_t status;
// First, figure out how many namespace actions are needed.
fdio_flat_namespace_t* flat_ns = nullptr;
if (ns != nullptr) {
zx_status_t status = fdio_ns_export(ns, &flat_ns);
status = fdio_ns_export(ns, &flat_ns);
if (status != ZX_OK) {
LOG_ERR("ProcessStarter: BuildSpawnActions: fdio_ns_export: %s\n",
zx_status_get_string(status));
@ -696,9 +695,33 @@ class ProcessStarter {
// Fill in the entries for passing stdin/out/err handles, and the program
// name.
AddPipe(0, &write_out_, &actions[0]);
AddPipe(1, &read_in_, &actions[1]);
AddPipe(2, &read_err_, &actions[2]);
status = AddPipe(0, &write_out_, &actions[0]);
if (status != ZX_OK) {
LOG_ERR("ProcessStarter: BuildSpawnActions: stdout AddPipe failed: %s\n",
zx_status_get_string(status));
if (flat_ns != nullptr) {
fdio_ns_free_flat_ns(flat_ns);
}
return -1;
}
status = AddPipe(1, &read_in_, &actions[1]);
if (status != ZX_OK) {
LOG_ERR("ProcessStarter: BuildSpawnActions: stdin AddPipe failed: %s\n",
zx_status_get_string(status));
if (flat_ns != nullptr) {
fdio_ns_free_flat_ns(flat_ns);
}
return -1;
}
status = AddPipe(2, &read_err_, &actions[2]);
if (status != ZX_OK) {
LOG_ERR("ProcessStarter: BuildSpawnActions: stderr AddPipe failed: %s\n",
zx_status_get_string(status));
if (flat_ns != nullptr) {
fdio_ns_free_flat_ns(flat_ns);
}
return -1;
}
actions[3] = {
.action = FDIO_SPAWN_ACTION_SET_NAME,
.name.data = program_arguments_[0],