Skip to content

Commit

Permalink
[fuchsia] Set up namespace properly (flutter#4920)
Browse files Browse the repository at this point in the history
When we converted this code to FIDL2, we moved the FlatNamespace into
SetupNamespace, which meant it grabed the service root handle instead of
leaving it in-place for ApplicationContext::CreateFrom to pick it up.
Now, we pass this object by pointer, which is what we did in FIDL1.
  • Loading branch information
abarth authored Apr 2, 2018
1 parent c092e14 commit a594a91
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions content_handler/application_controller_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ ApplicationControllerImpl::ApplicationControllerImpl(
auto request = service_provider.NewRequest();
service_provider_bridge_.set_backend(std::move(service_provider));

fdio_ns_t* fdio_ns = SetupNamespace(std::move(startup_info.flat_namespace));
fdio_ns_t* fdio_ns = SetupNamespace(&startup_info.flat_namespace);
if (fdio_ns == nullptr) {
FXL_LOG(ERROR) << "Failed to initialize namespace";
return;
Expand All @@ -66,7 +66,8 @@ ApplicationControllerImpl::ApplicationControllerImpl(
runtime_holder_.reset(new RuntimeHolder());
runtime_holder_->SetMainIsolateShutdownCallback([this]() { Kill(); });
runtime_holder_->Init(
fdio_ns, component::ApplicationContext::CreateFrom(std::move(startup_info)),
fdio_ns,
component::ApplicationContext::CreateFrom(std::move(startup_info)),
std::move(request), std::move(bundle));
}

Expand All @@ -75,24 +76,24 @@ ApplicationControllerImpl::~ApplicationControllerImpl() = default;
constexpr char kServiceRootPath[] = "/svc";

fdio_ns_t* ApplicationControllerImpl::SetupNamespace(
component::FlatNamespace flat) {
component::FlatNamespace* flat) {
fdio_ns_t* fdio_namespc;
zx_status_t status = fdio_ns_create(&fdio_namespc);
if (status != ZX_OK) {
FXL_LOG(ERROR) << "Failed to create namespace";
return nullptr;
}
for (size_t i = 0; i < flat.paths->size(); ++i) {
if (flat.paths->at(i) == kServiceRootPath) {
for (size_t i = 0; i < flat->paths->size(); ++i) {
if (flat->paths->at(i) == kServiceRootPath) {
// Ownership of /svc goes to the ApplicationContext created above.
continue;
}
zx::channel dir = std::move(flat.directories->at(i));
zx::channel dir = std::move(flat->directories->at(i));
zx_handle_t dir_handle = dir.release();
const char* path = flat.paths->at(i)->data();
const char* path = flat->paths->at(i)->data();
status = fdio_ns_bind(fdio_namespc, path, dir_handle);
if (status != ZX_OK) {
FXL_LOG(ERROR) << "Failed to bind " << flat.paths->at(i)
FXL_LOG(ERROR) << "Failed to bind " << flat->paths->at(i)
<< " to namespace";
zx_handle_close(dir_handle);
fdio_ns_destroy(fdio_namespc);
Expand Down
2 changes: 1 addition & 1 deletion content_handler/application_controller_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ApplicationControllerImpl : public component::ApplicationController,
void StartRuntimeIfReady();
void SendReturnCode(int32_t return_code);

fdio_ns_t* SetupNamespace(component::FlatNamespace flat);
fdio_ns_t* SetupNamespace(component::FlatNamespace* flat);

App* app_;
fidl::Binding<component::ApplicationController> binding_;
Expand Down

0 comments on commit a594a91

Please sign in to comment.