Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit c35f53f

Browse files
zandersocommit-bot@chromium.org
authored andcommitted
[dart:io,fuchsia] Change namespace setup failure from ASSERTs to FATALs
To help investigate FLK-221. Change-Id: I8c2fafac232bff8cac1d2acac14a2a765d267975 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103360 Reviewed-by: Ryan Macnak <[email protected]> Commit-Queue: Zach Anderson <[email protected]>
1 parent af93ebc commit c35f53f

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

runtime/bin/file_fuchsia.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,24 +255,26 @@ bool File::Exists(Namespace* namespc, const char* name) {
255255
if (NO_RETRY_EXPECTED(fstatat(ns.fd(), ns.path(), &st, 0)) == 0) {
256256
// Everything but a directory and a link is a file to Dart.
257257
return !S_ISDIR(st.st_mode) && !S_ISLNK(st.st_mode);
258-
} else {
259-
return false;
260258
}
259+
return false;
261260
}
262261

263262
bool File::Create(Namespace* namespc, const char* name) {
264263
NamespaceScope ns(namespc, name);
265264
const int fd = NO_RETRY_EXPECTED(
266265
openat(ns.fd(), ns.path(), O_RDONLY | O_CREAT | O_CLOEXEC, 0666));
267266
if (fd < 0) {
267+
Syslog::PrintErr("File::Create() openat(%ld, %s) failed: %s\n", ns.fd(),
268+
ns.path(), strerror(errno));
268269
return false;
269270
}
270271
// File.create returns a File, so we shouldn't be giving the illusion that the
271272
// call has created a file or that a file already exists if there is already
272273
// an entity at the same path that is a directory or a link.
273-
bool is_file = true;
274+
bool is_file = false;
274275
struct stat st;
275276
if (NO_RETRY_EXPECTED(fstat(fd, &st)) == 0) {
277+
is_file = true;
276278
if (S_ISDIR(st.st_mode)) {
277279
errno = EISDIR;
278280
is_file = false;

runtime/bin/namespace_fuchsia.cc

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,32 @@ namespace bin {
2222

2323
NamespaceImpl::NamespaceImpl(fdio_ns_t* fdio_ns)
2424
: fdio_ns_(fdio_ns),
25-
rootfd_(fdio_ns_opendir(fdio_ns)),
2625
cwd_(strdup("/")) {
27-
ASSERT(rootfd_ > 0);
26+
rootfd_ = fdio_ns_opendir(fdio_ns);
27+
if (rootfd_ < 0) {
28+
FATAL2("Failed to open file descriptor for namespace: errno=%d: %s", errno,
29+
strerror(errno));
30+
}
2831
cwdfd_ = dup(rootfd_);
29-
ASSERT(cwdfd_ > 0);
32+
if (cwdfd_ < 0) {
33+
FATAL2("Failed to dup() namespace file descriptor: errno=%d: %s", errno,
34+
strerror(errno));
35+
}
3036
}
3137

3238
NamespaceImpl::NamespaceImpl(const char* path)
3339
: fdio_ns_(NULL),
34-
rootfd_(TEMP_FAILURE_RETRY(open(path, O_DIRECTORY))),
3540
cwd_(strdup("/")) {
36-
ASSERT(rootfd_ > 0);
41+
rootfd_ = TEMP_FAILURE_RETRY(open(path, O_DIRECTORY));
42+
if (rootfd_ < 0) {
43+
FATAL2("Failed to open file descriptor for namespace: errno=%d: %s", errno,
44+
strerror(errno));
45+
}
3746
cwdfd_ = dup(rootfd_);
38-
ASSERT(cwdfd_ > 0);
47+
if (cwdfd_ < 0) {
48+
FATAL2("Failed to dup() namespace file descriptor: errno=%d: %s", errno,
49+
strerror(errno));
50+
}
3951
}
4052

4153
NamespaceImpl::~NamespaceImpl() {
@@ -54,7 +66,7 @@ bool NamespaceImpl::SetCwd(Namespace* namespc, const char* new_path) {
5466
NamespaceScope ns(namespc, new_path);
5567
const intptr_t new_cwdfd =
5668
TEMP_FAILURE_RETRY(openat(ns.fd(), ns.path(), O_DIRECTORY));
57-
if (new_cwdfd != 0) {
69+
if (new_cwdfd < 0) {
5870
return false;
5971
}
6072

0 commit comments

Comments
 (0)