Clean up trailing whitespaces in cpu stats process cmdline (#22089)

The psutil library reads the process commandline as by opening
/proc/pid/cmdline which returns a buffer that is larger than just the
program cmdline due to rounded memory allocation sizes.

That means that if the library does not detect a Null-terminated string
it keeps appending empty strings which add up as whitespaces when joined.
This commit is contained in:
Martin Weinelt
2026-02-27 05:53:26 +01:00
committed by GitHub
parent 9c3a74b4f5
commit b4eac11cbd

View File

@@ -121,7 +121,7 @@ def get_cpu_stats() -> dict[str, dict]:
pid = str(process.info["pid"])
try:
cpu_percent = process.info["cpu_percent"]
cmdline = process.info["cmdline"]
cmdline = " ".join(process.info["cmdline"]).rstrip()
with open(f"/proc/{pid}/stat", "r") as f:
stats = f.readline().split()
@@ -155,7 +155,7 @@ def get_cpu_stats() -> dict[str, dict]:
"cpu": str(cpu_percent),
"cpu_average": str(round(cpu_average_usage, 2)),
"mem": f"{mem_pct}",
"cmdline": clean_camera_user_pass(" ".join(cmdline)),
"cmdline": clean_camera_user_pass(cmdline),
}
except Exception:
continue