Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
tempfs.cc
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "tempfs.h"
6
7#include <string_view>
8
9#include <zircon/errors.h>
10#include <zircon/status.h>
11#include <zircon/syscalls.h>
12
13#include "flutter/fml/logging.h"
14
15namespace {
16
17constexpr char kTmpPath[] = "/tmp";
18
19} // namespace
20
21namespace dart_utils {
22
23void BindTemp(fdio_ns_t* ns) {
24 // TODO(zra): Should isolates share a /tmp file system within a process, or
25 // should isolates each get their own private file system for /tmp? For now,
26 // sharing the process-wide /tmp simplifies hot reload since the hot reload
27 // devfs requires sharing between the service isolate and the app isolates.
28 fdio_flat_namespace_t* rootns;
29 if (zx_status_t status = fdio_ns_export_root(&rootns); status != ZX_OK) {
30 FML_LOG(ERROR) << "Failed to export root ns: "
31 << zx_status_get_string(status);
32 return;
33 }
34
35 zx_handle_t tmp_dir_handle;
36 for (size_t i = 0; i < rootns->count; i++) {
37 if (std::string_view{rootns->path[i]} == kTmpPath) {
38 tmp_dir_handle = std::exchange(rootns->handle[i], ZX_HANDLE_INVALID);
39 }
40 }
41 fdio_ns_free_flat_ns(rootns);
42
43 if (zx_status_t status = fdio_ns_bind(ns, kTmpPath, tmp_dir_handle);
44 status != ZX_OK) {
45 zx_handle_close(tmp_dir_handle);
46 FML_LOG(ERROR) << "Failed to bind /tmp directory into isolate namespace: "
47 << zx_status_get_string(status);
48 }
49}
50
51} // namespace dart_utils
#define FML_LOG(severity)
Definition logging.h:82
void BindTemp(fdio_ns_t *ns)
Definition tempfs.cc:23
#define ERROR(message)