diff options
author | Benny Baumann <BenBE@geshi.org> | 2024-03-10 16:04:57 +0100 |
---|---|---|
committer | cgzones <cgzones@googlemail.com> | 2024-03-27 20:06:42 +0100 |
commit | cdf7a5a93be45c7c72bfdcbc5795a68cd8536c18 (patch) | |
tree | 25119d42a79070e8207ff1cbab8e0942357ee6cb /linux/LinuxProcessTable.c | |
parent | 2b7f4a65a8a033c125548c2be17d091a90f1c34f (diff) |
Avoid glibc FILE API for oom_score
Diffstat (limited to 'linux/LinuxProcessTable.c')
-rw-r--r-- | linux/LinuxProcessTable.c | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/linux/LinuxProcessTable.c b/linux/LinuxProcessTable.c index b7cc35a4..2285667d 100644 --- a/linux/LinuxProcessTable.c +++ b/linux/LinuxProcessTable.c @@ -933,19 +933,24 @@ static void LinuxProcessTable_readCGroupFile(LinuxProcess* process, openat_arg_t } static void LinuxProcessTable_readOomData(LinuxProcess* process, openat_arg_t procFd) { - FILE* file = fopenat(procFd, "oom_score", "r"); - if (!file) + char buffer[PROC_LINE_LENGTH + 1] = {0}; + + ssize_t oomRead = xReadfileat(procFd, "oom_score", buffer, sizeof(buffer)); + if (oomRead < 1) { return; + } - char buffer[PROC_LINE_LENGTH + 1]; - if (fgets(buffer, PROC_LINE_LENGTH, file)) { - unsigned int oom; - int ok = sscanf(buffer, "%u", &oom); - if (ok == 1) { - process->oom = oom; - } + char* oomPtr = buffer; + uint64_t oom = fast_strtoull_dec(&oomPtr, oomRead); + if (*oomPtr && *oomPtr != '\n' && *oomPtr != ' ') { + return; } - fclose(file); + + if (oom > UINT_MAX) { + return; + } + + process->oom = oom; } static void LinuxProcessTable_readAutogroup(LinuxProcess* process, openat_arg_t procFd) { |