diff options
author | Yuki Wang <yukiwang@google.com> | 2023-04-17 13:58:52 -0700 |
---|---|---|
committer | Joshua Peraza <jperaza@chromium.org> | 2023-04-17 21:23:19 +0000 |
commit | bd9d94c70843620adeebcd73c243001237c6d426 (patch) | |
tree | 418ba36bcb1920973476f6763372039fc63f0de9 | |
parent | b1775c56b253e8f3c19e4ae8cfd67f9fe1fe45b1 (diff) | |
download | google-breakpad-bd9d94c70843620adeebcd73c243001237c6d426.tar.gz |
Set O_NONBLOCK for opening file to prevent hanging when file unavailable.
Bug: 277976345
Change-Id: Iddf55d8e172f98c76ae7167f609fb53c4c60fa48
Reviewed-on: https://chromium-review.googlesource.com/c/breakpad/breakpad/+/4437089
Reviewed-by: Joshua Peraza <jperaza@chromium.org>
-rw-r--r-- | src/common/linux/memory_mapped_file.cc | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/src/common/linux/memory_mapped_file.cc b/src/common/linux/memory_mapped_file.cc index 568312cf..a7b96eb5 100644 --- a/src/common/linux/memory_mapped_file.cc +++ b/src/common/linux/memory_mapped_file.cc @@ -61,8 +61,11 @@ MemoryMappedFile::~MemoryMappedFile() { bool MemoryMappedFile::Map(const char* path, size_t offset) { Unmap(); - - int fd = sys_open(path, O_RDONLY, 0); + // Based on https://pubs.opengroup.org/onlinepubs/7908799/xsh/open.html + // If O_NONBLOCK is set: The open() function will return without blocking + // for the device to be ready or available. Setting this value will provent + // hanging if file is not avilable. + int fd = sys_open(path, O_RDONLY | O_NONBLOCK, 0); if (fd == -1) { return false; } |