Commit 80cbb52f by Abseil Team Committed by Copybara-Service

`absl::base_internal::ReadLongFromFile` should use `O_CLOEXEC` and handle interrupts to `read`

PiperOrigin-RevId: 477547252
Change-Id: Icc94290511b5071d15584d59dcd9cf6ad7319e2b
parent f7404cd3
...@@ -189,12 +189,15 @@ static double GetNominalCPUFrequency() { ...@@ -189,12 +189,15 @@ static double GetNominalCPUFrequency() {
// and the memory location pointed to by value is set to the value read. // and the memory location pointed to by value is set to the value read.
static bool ReadLongFromFile(const char *file, long *value) { static bool ReadLongFromFile(const char *file, long *value) {
bool ret = false; bool ret = false;
int fd = open(file, O_RDONLY); int fd = open(file, O_RDONLY | O_CLOEXEC);
if (fd != -1) { if (fd != -1) {
char line[1024]; char line[1024];
char *err; char *err;
memset(line, '\0', sizeof(line)); 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) { if (len <= 0) {
ret = false; ret = false;
} else { } else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment