diff options
author | Daniel Lange <DLange@git.local> | 2018-04-11 01:26:28 +0200 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2018-04-11 01:52:54 +0200 |
commit | df568a576f7b44ac5a2b9b7222c7f39d9932f626 (patch) | |
tree | b30ce33fd0d49398b52bf9a90b42304a7c32455a /linux | |
parent | 2ee50d030178cede83eb9d0005fbc19f819d30fe (diff) | |
download | debian_htop-df568a576f7b44ac5a2b9b7222c7f39d9932f626.tar.gz debian_htop-df568a576f7b44ac5a2b9b7222c7f39d9932f626.tar.bz2 debian_htop-df568a576f7b44ac5a2b9b7222c7f39d9932f626.zip |
Imported Upstream version 2.2.0
Diffstat (limited to 'linux')
-rw-r--r-- | linux/Battery.c | 5 | ||||
-rw-r--r-- | linux/LinuxProcess.c | 3 | ||||
-rw-r--r-- | linux/LinuxProcess.h | 3 | ||||
-rw-r--r-- | linux/LinuxProcessList.c | 68 | ||||
-rw-r--r-- | linux/LinuxProcessList.h | 5 | ||||
-rw-r--r-- | linux/Platform.c | 2 |
6 files changed, 48 insertions, 38 deletions
diff --git a/linux/Battery.c b/linux/Battery.c index 34a2401..aedacab 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -110,16 +110,13 @@ static ACPresence procAcpiCheck() { char statePath[50]; xSnprintf((char *) statePath, sizeof statePath, "%s/%s/state", power_supplyPath, entryName); FILE* file = fopen(statePath, "r"); - if (!file) { isOn = AC_ERROR; continue; } - char* line = String_readLine(file); - if (!line) continue; - fclose(file); + if (!line) continue; const char *isOnline = String_getToken(line, 2); free(line); diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 39b5647..09ccbe1 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -93,6 +93,7 @@ typedef enum LinuxProcessFields { typedef struct LinuxProcess_ { Process super; + bool isKernelThread; IOPriority ioPriority; unsigned long int cminflt; unsigned long int cmajflt; @@ -142,7 +143,7 @@ typedef struct LinuxProcess_ { } LinuxProcess; #ifndef Process_isKernelThread -#define Process_isKernelThread(_process) (_process->pgrp == 0) +#define Process_isKernelThread(_process) ((LinuxProcess*)(_process)->isKernelThread) #endif #ifndef Process_isUserlandThread diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 9400d7b..d75fe89 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -85,6 +85,7 @@ typedef enum LinuxProcessFields { typedef struct LinuxProcess_ { Process super; + bool isKernelThread; IOPriority ioPriority; unsigned long int cminflt; unsigned long int cmajflt; @@ -134,7 +135,7 @@ typedef struct LinuxProcess_ { } LinuxProcess; #ifndef Process_isKernelThread -#define Process_isKernelThread(_process) (_process->pgrp == 0) +#define Process_isKernelThread(_process) (((LinuxProcess*)(_process))->isKernelThread) #endif #ifndef Process_isUserlandThread diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 6f2631a..2edd042 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -26,6 +26,12 @@ in the source distribution for its full text. #include <assert.h> #include <sys/types.h> #include <fcntl.h> +#ifdef MAJOR_IN_MKDEV +#include <sys/mkdev.h> +#elif defined(MAJOR_IN_SYSMACROS) || \ + (defined(HAVE_SYS_SYSMACROS_H) && HAVE_SYS_SYSMACROS_H) +#include <sys/sysmacros.h> +#endif #ifdef HAVE_DELAYACCT #include <netlink/attr.h> @@ -436,7 +442,7 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna } break; case 's': - if (line[5] == 'r' && strncmp(line+1, "yscr: ", 6) == 0) { + if (line[4] == 'r' && strncmp(line+1, "yscr: ", 6) == 0) { process->io_syscr = strtoull(line+7, NULL, 10); } else if (strncmp(line+1, "yscw: ", 6) == 0) { process->io_syscw = strtoull(line+7, NULL, 10); @@ -595,36 +601,36 @@ static void LinuxProcessList_readOomData(LinuxProcess* process, const char* dirn static int handleNetlinkMsg(struct nl_msg *nlmsg, void *linuxProcess) { struct nlmsghdr *nlhdr; - struct nlattr *nlattrs[TASKSTATS_TYPE_MAX + 1]; - struct nlattr *nlattr; - struct taskstats *stats; - int rem; - unsigned long long int timeDelta; - LinuxProcess* lp = (LinuxProcess*) linuxProcess; + struct nlattr *nlattrs[TASKSTATS_TYPE_MAX + 1]; + struct nlattr *nlattr; + struct taskstats *stats; + int rem; + unsigned long long int timeDelta; + LinuxProcess* lp = (LinuxProcess*) linuxProcess; - nlhdr = nlmsg_hdr(nlmsg); + nlhdr = nlmsg_hdr(nlmsg); if (genlmsg_parse(nlhdr, 0, nlattrs, TASKSTATS_TYPE_MAX, NULL) < 0) { return NL_SKIP; - } - - if ((nlattr = nlattrs[TASKSTATS_TYPE_AGGR_PID]) || (nlattr = nlattrs[TASKSTATS_TYPE_NULL])) { - stats = nla_data(nla_next(nla_data(nlattr), &rem)); - assert(lp->super.pid == stats->ac_pid); - timeDelta = (stats->ac_etime*1000 - lp->delay_read_time); - #define BOUNDS(x) isnan(x) ? 0.0 : (x > 100) ? 100.0 : x; - #define DELTAPERC(x,y) BOUNDS((float) (x - y) / timeDelta * 100); - lp->cpu_delay_percent = DELTAPERC(stats->cpu_delay_total, lp->cpu_delay_total); - lp->blkio_delay_percent = DELTAPERC(stats->blkio_delay_total, lp->blkio_delay_total); - lp->swapin_delay_percent = DELTAPERC(stats->swapin_delay_total, lp->swapin_delay_total); - #undef DELTAPERC - #undef BOUNDS - lp->swapin_delay_total = stats->swapin_delay_total; - lp->blkio_delay_total = stats->blkio_delay_total; - lp->cpu_delay_total = stats->cpu_delay_total; - lp->delay_read_time = stats->ac_etime*1000; - } - return NL_OK; + } + + if ((nlattr = nlattrs[TASKSTATS_TYPE_AGGR_PID]) || (nlattr = nlattrs[TASKSTATS_TYPE_NULL])) { + stats = nla_data(nla_next(nla_data(nlattr), &rem)); + assert(lp->super.pid == stats->ac_pid); + timeDelta = (stats->ac_etime*1000 - lp->delay_read_time); + #define BOUNDS(x) isnan(x) ? 0.0 : (x > 100) ? 100.0 : x; + #define DELTAPERC(x,y) BOUNDS((float) (x - y) / timeDelta * 100); + lp->cpu_delay_percent = DELTAPERC(stats->cpu_delay_total, lp->cpu_delay_total); + lp->blkio_delay_percent = DELTAPERC(stats->blkio_delay_total, lp->blkio_delay_total); + lp->swapin_delay_percent = DELTAPERC(stats->swapin_delay_total, lp->swapin_delay_total); + #undef DELTAPERC + #undef BOUNDS + lp->swapin_delay_total = stats->swapin_delay_total; + lp->blkio_delay_total = stats->blkio_delay_total; + lp->cpu_delay_total = stats->cpu_delay_total; + lp->delay_read_time = stats->ac_etime*1000; + } + return NL_OK; } static void LinuxProcessList_readDelayAcctData(LinuxProcessList* this, LinuxProcess* process) { @@ -671,9 +677,6 @@ static void setCommand(Process* process, const char* command, int len) { } static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirname, const char* name) { - if (Process_isKernelThread(process)) - return true; - char filename[MAX_NAME+1]; xSnprintf(filename, MAX_NAME, "%s/%s/cmdline", dirname, name); int fd = open(filename, O_RDONLY); @@ -685,7 +688,10 @@ static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirna close(fd); int tokenEnd = 0; int lastChar = 0; - if (amtRead <= 0) { + if (amtRead == 0) { + ((LinuxProcess*)process)->isKernelThread = true; + return true; + } else if (amtRead < 0) { return false; } for (int i = 0; i < amtRead; i++) { diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index 5005220..0851a10 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -9,6 +9,11 @@ Released under the GNU GPL, see the COPYING file in the source distribution for its full text. */ +#ifdef MAJOR_IN_MKDEV +#elif defined(MAJOR_IN_SYSMACROS) || \ + (defined(HAVE_SYS_SYSMACROS_H) && HAVE_SYS_SYSMACROS_H) +#endif + #ifdef HAVE_DELAYACCT #endif diff --git a/linux/Platform.c b/linux/Platform.c index 025abff..ab90ca7 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -96,7 +96,7 @@ static Htop_Reaction Platform_actionSetIOPriority(State* st) { void* set = Action_pickFromVector(st, ioprioPanel, 21); if (set) { IOPriority ioprio = IOPriorityPanel_getIOPriority(ioprioPanel); - bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) LinuxProcess_setIOPriority, (size_t) ioprio, NULL); + bool ok = MainPanel_foreachProcess((MainPanel*)panel, (MainPanel_ForeachProcessFn) LinuxProcess_setIOPriority, (Arg){ .i = ioprio }, NULL); if (!ok) beep(); } |