diff options
author | Abseil Team <absl-team@google.com> | 2022-09-28 14:06:14 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-09-28 14:07:04 -0700 |
commit | 80cbb52f4d432d6572f7a40a10b2fd740a7c2c41 (patch) | |
tree | 83a4e061ce7c6f8fc3a72fd559c39438ac34f9b2 | |
parent | f7404cd33f2457bd561fdcfbb024e43852c94bcf (diff) |
`absl::base_internal::ReadLongFromFile` should use `O_CLOEXEC` and handle interrupts to `read`
PiperOrigin-RevId: 477547252
Change-Id: Icc94290511b5071d15584d59dcd9cf6ad7319e2b
-rw-r--r-- | absl/base/internal/sysinfo.cc | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/absl/base/internal/sysinfo.cc b/absl/base/internal/sysinfo.cc index d820ce38..da499d3a 100644 --- a/absl/base/internal/sysinfo.cc +++ b/absl/base/internal/sysinfo.cc @@ -189,12 +189,15 @@ static double GetNominalCPUFrequency() { // and the memory location pointed to by value is set to the value read. static bool ReadLongFromFile(const char *file, long *value) { bool ret = false; - int fd = open(file, O_RDONLY); + int fd = open(file, O_RDONLY | O_CLOEXEC); if (fd != -1) { char line[1024]; char *err; memset(line, '\0', sizeof(line)); - ssize_t len = read(fd, line, sizeof(line) - 1); + ssize_t len; + do { + len = read(fd, line, sizeof(line) - 1); + } while (len < 0 && errno == EINTR); if (len <= 0) { ret = false; } else { |