aboutsummaryrefslogtreecommitdiffstats
path: root/linux
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2020-09-03 12:34:39 +0200
committerDaniel Lange <DLange@git.local>2020-09-03 12:34:39 +0200
commit59eeadec918a955b40427a1b012992161050c939 (patch)
tree4d3a4708e29a6a2f8807b2843a3cbae99f5dfda3 /linux
parentf3147ea2d1598914c2db53e8cfb34c8ff81e2ff4 (diff)
downloaddebian_htop-59eeadec918a955b40427a1b012992161050c939.tar.gz
debian_htop-59eeadec918a955b40427a1b012992161050c939.tar.bz2
debian_htop-59eeadec918a955b40427a1b012992161050c939.zip
New upstream version 3.0.1upstream/3.0.1
Diffstat (limited to 'linux')
-rw-r--r--linux/Battery.c4
-rw-r--r--linux/LinuxProcess.c7
-rw-r--r--linux/LinuxProcessList.c19
3 files changed, 15 insertions, 15 deletions
diff --git a/linux/Battery.c b/linux/Battery.c
index 4014a50..a8784da 100644
--- a/linux/Battery.c
+++ b/linux/Battery.c
@@ -107,7 +107,7 @@ static ACPresence procAcpiCheck() {
if (entryName[0] != 'A')
continue;
- char statePath[50];
+ char statePath[256];
xSnprintf((char *) statePath, sizeof statePath, "%s/%s/state", power_supplyPath, entryName);
FILE* file = fopen(statePath, "r");
if (!file) {
@@ -191,7 +191,7 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) {
if (!dirEntry)
break;
char* entryName = (char *) dirEntry->d_name;
- const char filePath[50];
+ const char filePath[256];
xSnprintf((char *) filePath, sizeof filePath, SYS_POWERSUPPLY_DIR "/%s/type", entryName);
int fd1 = open(filePath, O_RDONLY);
diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c
index 3a15049..5970c93 100644
--- a/linux/LinuxProcess.c
+++ b/linux/LinuxProcess.c
@@ -241,7 +241,7 @@ ProcessFieldData Process_fields[] = {
#ifdef HAVE_CGROUP
[CGROUP] = { .name = "CGROUP", .title = " CGROUP ", .description = "Which cgroup the process is in", .flags = PROCESS_FLAG_LINUX_CGROUP, },
#endif
- [OOM] = { .name = "OOM", .title = " OOM ", .description = "OOM (Out-of-Memory) killer score", .flags = PROCESS_FLAG_LINUX_OOM, },
+ [OOM] = { .name = "OOM", .title = " OOM ", .description = "OOM (Out-of-Memory) killer score", .flags = PROCESS_FLAG_LINUX_OOM, },
[IO_PRIORITY] = { .name = "IO_PRIORITY", .title = "IO ", .description = "I/O priority", .flags = PROCESS_FLAG_LINUX_IOPRIO, },
#ifdef HAVE_DELAYACCT
[PERCENT_CPU_DELAY] = { .name = "PERCENT_CPU_DELAY", .title = "CPUD% ", .description = "CPU delay %", .flags = 0, },
@@ -264,7 +264,6 @@ ProcessPidColumn Process_pidColumns[] = {
{ .id = TGID, .label = "TGID" },
{ .id = PGRP, .label = "PGRP" },
{ .id = SESSION, .label = "SID" },
- { .id = OOM, .label = "OOM" },
{ .id = 0, .label = NULL },
};
@@ -397,7 +396,7 @@ void LinuxProcess_writeField(Process* this, RichString* str, ProcessField field)
#ifdef HAVE_CGROUP
case CGROUP: xSnprintf(buffer, n, "%-10s ", lp->cgroup); break;
#endif
- case OOM: xSnprintf(buffer, n, Process_pidFormat, lp->oom); break;
+ case OOM: xSnprintf(buffer, n, "%4u ", lp->oom); break;
case IO_PRIORITY: {
int klass = IOPriority_class(lp->ioPriority);
if (klass == IOPRIO_CLASS_NONE) {
@@ -493,7 +492,7 @@ long LinuxProcess_compare(const void* v1, const void* v2) {
return strcmp(p1->cgroup ? p1->cgroup : "", p2->cgroup ? p2->cgroup : "");
#endif
case OOM:
- return (p2->oom - p1->oom);
+ return ((int)p2->oom - (int)p1->oom);
#ifdef HAVE_DELAYACCT
case PERCENT_CPU_DELAY:
return (p2->cpu_delay_percent > p1->cpu_delay_percent ? 1 : -1);
diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c
index 6d3d034..732a86b 100644
--- a/linux/LinuxProcessList.c
+++ b/linux/LinuxProcessList.c
@@ -275,7 +275,8 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidWhiteList, ui
} else if (String_startsWith(buffer, "cpu")) {
cpus++;
} else if (String_startsWith(buffer, "btime ")) {
- sscanf(buffer, "btime %lld\n", &btime);
+ if (sscanf(buffer, "btime %lld\n", &btime) != 1)
+ CRT_fatalError("Failed to parse btime from " PROCSTATFILE);
break;
}
} while(true);
@@ -577,7 +578,7 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d
FILE* file = fopen(filename, "r");
if (!file)
return;
- (void) fscanf(file,
+ (void)! fscanf(file,
"%*32u %*32s %*1c %*32u %*32u %*32u %*32u %*32u %*32u %*32u "
"%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u "
"%*32u %*32u %*32u %*32u %*32u %*32u %*32u %*32u "
@@ -670,7 +671,7 @@ static void LinuxProcessList_readOomData(LinuxProcess* process, const char* dirn
char buffer[PROC_LINE_LENGTH + 1];
if (fgets(buffer, PROC_LINE_LENGTH, file)) {
unsigned int oom;
- int ok = sscanf(buffer, "%32u", &oom);
+ int ok = sscanf(buffer, "%u", &oom);
if (ok >= 1) {
process->oom = oom;
}
@@ -1062,9 +1063,9 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) {
}
static inline void LinuxProcessList_scanZfsArcstats(LinuxProcessList* lpl) {
- unsigned long long int dbufSize;
- unsigned long long int dnodeSize;
- unsigned long long int bonusSize;
+ unsigned long long int dbufSize = 0;
+ unsigned long long int dnodeSize = 0;
+ unsigned long long int bonusSize = 0;
FILE* file = fopen(PROCARCSTATSFILE, "r");
if (file == NULL) {
@@ -1142,10 +1143,10 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) {
char* ok = fgets(buffer, PROC_LINE_LENGTH, file);
if (!ok) buffer[0] = '\0';
if (i == 0)
- sscanf(buffer, "cpu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
+ (void) sscanf(buffer, "cpu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
else {
int cpuid;
- sscanf(buffer, "cpu%4d %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
+ (void) sscanf(buffer, "cpu%4d %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu %16llu", &cpuid, &usertime, &nicetime, &systemtime, &idletime, &ioWait, &irq, &softIrq, &steal, &guest, &guestnice);
assert(cpuid == i - 1);
}
// Guest time is already accounted in usertime
@@ -1235,7 +1236,7 @@ static inline double LinuxProcessList_scanCPUFrequency(LinuxProcessList* this) {
(sscanf(buffer, "cpu MHz : %lf", &frequency) == 1) ||
(sscanf(buffer, "cpu MHz: %lf", &frequency) == 1)
) {
- if (cpuid < 0) {
+ if (cpuid < 0 || cpuid > (cpus - 1)) {
CRT_fatalError(PROCCPUINFOFILE " is malformed: cpu MHz line without corresponding processor line");
}

© 2014-2024 Faster IT GmbH | imprint | privacy policy