| // Copyright 2019 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "root_resource.h" |
| |
| #include <fcntl.h> |
| #include <fuchsia/sysinfo/c/fidl.h> |
| #include <lib/fdio/fdio.h> |
| #include <lib/zx/channel.h> |
| |
| #include "src/lib/fxl/logging.h" |
| |
| namespace harvester { |
| |
| zx_status_t GetRootResource(zx_handle_t* root_resource) { |
| const char* sysinfo = "/dev/misc/sysinfo"; |
| int fd = open(sysinfo, O_RDWR); |
| if (fd < 0) { |
| FXL_LOG(ERROR) << "Cannot open sysinfo: " << strerror(errno); |
| return ZX_ERR_NOT_FOUND; |
| } |
| |
| zx::channel channel; |
| zx_status_t status = |
| fdio_get_service_handle(fd, channel.reset_and_get_address()); |
| if (status != ZX_OK) { |
| FXL_LOG(ERROR) << "Cannot obtain sysinfo channel: " |
| << zx_status_get_string(status); |
| return status; |
| } |
| |
| zx_status_t fidl_status = fuchsia_sysinfo_DeviceGetRootResource( |
| channel.get(), &status, root_resource); |
| if (fidl_status != ZX_OK) { |
| FXL_LOG(ERROR) << "FIDL issue while trying to get root resource: " |
| << zx_status_get_string(fidl_status); |
| return fidl_status; |
| } else if (status != ZX_OK) { |
| FXL_LOG(ERROR) << "Cannot obtain root resource: " |
| << zx_status_get_string(status); |
| return status; |
| } |
| return ZX_OK; |
| } |
| |
| } // namespace harvester |