termux-packages/packages/htop/access-procstat-file.patch

37 lines
1.1 KiB
Diff

diff -uNr htop-3.2.0/linux/LinuxProcessList.c htop-3.2.0.mod/linux/LinuxProcessList.c
--- htop-3.2.0/linux/LinuxProcessList.c 2022-05-01 14:31:20.000000000 +0800
+++ htop-3.2.0.mod/linux/LinuxProcessList.c 2022-06-18 13:46:07.415229800 +0800
@@ -274,7 +274,14 @@
this->haveSmapsRollup = (access(PROCDIR "/self/smaps_rollup", R_OK) == 0);
// Read btime (the kernel boot time, as number of seconds since the epoch)
- FILE* statfile = fopen(PROCSTATFILE, "r");
+ FILE* statfile;
+
+ if (access("/proc/stat", R_OK) == 0){
+ statfile = fopen("/proc/stat", "r");
+ } else {
+ statfile = fopen(PROCSTATFILE, "r");
+ }
+
if (statfile == NULL)
CRT_fatalError("Cannot open " PROCSTATFILE);
while (true) {
@@ -1925,7 +1932,15 @@
LinuxProcessList_updateCPUcount(super);
- FILE* file = fopen(PROCSTATFILE, "r");
+ FILE* file;
+
+ /* Read the actual procstat file only if the /proc/stat is readable by any means */
+ if (access("/proc/stat", R_OK) == 0){
+ file = fopen("/proc/stat", "r");
+ } else {
+ file = fopen(PROCSTATFILE, "r");
+ }
+
if (!file)
CRT_fatalError("Cannot open " PROCSTATFILE);