0
0
mirror of https://github.com/termux/termux-packages.git synced 2024-12-12 00:10:52 +00:00
termux-packages/packages/htop/access-procstat-file.patch
2024-04-24 10:38:05 +03:00

37 lines
1.1 KiB
Diff

diff --git a/linux/LinuxMachine.c b/linux/LinuxMachine.c
--- a/linux/LinuxMachine.c
+++ b/linux/LinuxMachine.c
@@ -404,7 +404,15 @@ static void LinuxMachine_scanCPUTime(LinuxMachine* this) {
LinuxMachine_updateCPUcount(this);
- 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);
@@ -653,7 +661,14 @@ Machine* Machine_new(UsersTable* usersTable, uid_t userId) {
CRT_fatalError("Cannot get clock ticks by sysconf(_SC_CLK_TCK)");
// 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);