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>
This commit is contained in:
Yuki Wang 2023-04-17 13:58:52 -07:00 committed by Joshua Peraza
parent b1775c56b2
commit bd9d94c708

View File

@ -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;
}