From bd9d94c70843620adeebcd73c243001237c6d426 Mon Sep 17 00:00:00 2001 From: Yuki Wang Date: Mon, 17 Apr 2023 13:58:52 -0700 Subject: [PATCH] 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 --- src/common/linux/memory_mapped_file.cc | 7 +++++-- 1 file 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; }