Skip to content

Commit

Permalink
Actually better error message for mount() and ENOENT
Browse files Browse the repository at this point in the history
The previous change assumed that we could mount over a dangling symlink, which is true for the `mount` command-line tool, but not actually for the `mount()` syscall.
Also removed the odd `%s%s%s%s` string format in the message in favor of an easier to read if-else.

PiperOrigin-RevId: 676366941
Change-Id: Ib0bab7e18adadbb4dda79bbaa404f44bc6141cdb
  • Loading branch information
cblichmann authored and copybara-github committed Sep 19, 2024
1 parent 4dab011 commit 4094bd8
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions sandboxed_api/sandbox2/mounts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -641,19 +641,21 @@ void MountWithDefaults(const std::string& source, const std::string& target,
// File does not exist (anymore). This may be the case when trying to
// gather stack-traces on SAPI crashes. The sandboxee application is a
// memfd file that is not existing anymore.
// Check which file/dir of the call is actually missing. Do not follow
// symlinks here as it's valid to "mount over" a dangling symlink.
// Check which file/dir of the call is actually missing.
bool have_source =
file_util::fileops::Exists(source, /*fully_resolve=*/false);
file_util::fileops::Exists(source, /*fully_resolve=*/true);
bool have_target =
file_util::fileops::Exists(target, /*fully_resolve=*/false);
SAPI_RAW_LOG(WARNING,
"Could not mount %s (source) to %s (target): %s%s%s%s exist",
source.c_str(), target.c_str(),
have_source || have_target ? "" : "neither ",
have_source ? "" : "source",
have_source || have_target ? "" : " nor ",
have_target ? "" : "target");
file_util::fileops::Exists(target, /*fully_resolve=*/true);
const char* detail = "unknown error, source and target exist";
if (!have_source && !have_target) {
detail = "neither source nor target exist";
} else if (!have_source) {
detail = "source does not exist";
} else if (!have_target) {
detail = "target does not exist";
}
SAPI_RAW_LOG(WARNING, "Could not mount %s (source) to %s (target): %s",
source.c_str(), target.c_str(), detail);
return;
}
SAPI_RAW_PLOG(FATAL, "mounting %s to %s failed (flags=%s)", source, target,
Expand Down

0 comments on commit 4094bd8

Please sign in to comment.