From d10742025b3fc726c9a4b75d695ae8f01d289a25 Mon Sep 17 00:00:00 2001 From: Martin Liu Date: Thu, 27 Jun 2024 15:17:05 +0000 Subject: [PATCH] lmkd: handle missing process' information case When we get nothing from /proc//status and /proc//cmdline, we should return NULL or False because this usually indicates the process has already terminated. We should avoid attempting to kill a non-existent process, as it's an unnecessary waste of kill timeout. Bug: 331612600 Test: give memory pressure to trigger LMKD Change-Id: I468ff25012f9bb6fc842a7fad268ebcad0de4690 Signed-off-by: Martin Liu --- lmkd.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lmkd.cpp b/lmkd.cpp index 2a0f69b..23373fb 100644 --- a/lmkd.cpp +++ b/lmkd.cpp @@ -1050,7 +1050,7 @@ static bool read_proc_status(int pid, char *buf, size_t buf_sz) { size = read_all(fd, buf, buf_sz - 1); close(fd); - if (size < 0) { + if (size <= 0) { return false; } buf[size] = 0; @@ -1118,7 +1118,7 @@ static char *proc_get_name(int pid, char *buf, size_t buf_size) { } ret = read_all(fd, buf, buf_size - 1); close(fd); - if (ret < 0) { + if (ret <= 0) { return NULL; } buf[ret] = '\0';