Skip to content

Commit acc7872

Browse files
happyCoder92copybara-github
authored andcommitted
Improve mount error reporting for symlinks
PiperOrigin-RevId: 786644850 Change-Id: I946989964cd07972c84456e4843611ed547d6ef2
1 parent 8c49ac4 commit acc7872

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

sandboxed_api/sandbox2/mounts.cc

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,14 @@ std::string MountFlagsToString(uint64_t flags) {
445445
return absl::StrJoin(flags_list, "|");
446446
}
447447

448+
bool IsSymlink(const std::string& path) {
449+
struct stat sb;
450+
if (stat(path.c_str(), &sb) == -1) {
451+
return false;
452+
}
453+
return S_ISLNK(sb.st_mode);
454+
}
455+
448456
void MountWithDefaults(const std::string& source, const std::string& target,
449457
const char* fs_type, uint64_t extra_flags,
450458
const char* option_str, bool is_ro) {
@@ -467,16 +475,20 @@ void MountWithDefaults(const std::string& source, const std::string& target,
467475
file_util::fileops::Exists(source, /*fully_resolve=*/true);
468476
bool have_target =
469477
file_util::fileops::Exists(target, /*fully_resolve=*/true);
470-
const char* detail = "unknown error, source and target exist";
478+
std::string detail = "unknown error, source and target exist";
471479
if (!have_source && !have_target) {
472480
detail = "neither source nor target exist";
473481
} else if (!have_source) {
474482
detail = "source does not exist";
475483
} else if (!have_target) {
476484
detail = "target does not exist";
485+
if (IsSymlink(target)) {
486+
absl::StrAppend(&detail, " (symlink to ",
487+
file_util::fileops::ReadLink(target), ")");
488+
}
477489
}
478490
SAPI_RAW_LOG(WARNING, "Could not mount %s (source) to %s (target): %s",
479-
source.c_str(), target.c_str(), detail);
491+
source.c_str(), target.c_str(), detail.c_str());
480492
return;
481493
}
482494
SAPI_RAW_PLOG(FATAL, "mounting %s to %s failed (flags=%s)", source, target,
@@ -523,14 +535,6 @@ std::vector<MapEntry> GetSortedEntries(const MountTree& tree) {
523535
return ordered;
524536
}
525537

526-
bool IsSymlink(const std::string& path) {
527-
struct stat sb;
528-
if (stat(path.c_str(), &sb) == -1) {
529-
return false;
530-
}
531-
return S_ISLNK(sb.st_mode);
532-
}
533-
534538
// Traverses the MountTree to create all required files and perform the mounts.
535539
void CreateMounts(const MountTree& tree, const std::string& root_path,
536540
const std::string& path, bool create_backing_files,

0 commit comments

Comments
 (0)