From 7ab0915a6c8bab76273085ac563102e7ef8a6756 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 20:08:44 +0100 Subject: [PATCH 01/17] Remove unnecessary trailing semicolon on macros --- Object.h | 2 +- RichString.h | 6 +++--- linux/LinuxProcessList.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Object.h b/Object.h index caa3e919..05a9a72d 100644 --- a/Object.h +++ b/Object.h @@ -33,7 +33,7 @@ typedef void(*Object_Delete)(Object*); #define Class(class_) ((const ObjectClass*)(&(class_ ## _class))) -#define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_)); +#define AllocThis(class_) (class_*) xMalloc(sizeof(class_)); Object_setClass(this, Class(class_)) typedef struct ObjectClass_ { const void* const extends; diff --git a/RichString.h b/RichString.h index aab2d891..3fb85279 100644 --- a/RichString.h +++ b/RichString.h @@ -15,9 +15,9 @@ in the source distribution for its full text. #define RichString_size(this) ((this)->chlen) #define RichString_sizeVal(this) ((this).chlen) -#define RichString_begin(this) RichString (this); RichString_beginAllocated(this); -#define RichString_beginAllocated(this) memset(&(this), 0, sizeof(RichString)); (this).chptr = (this).chstr; -#define RichString_end(this) RichString_prune(&(this)); +#define RichString_begin(this) RichString (this); RichString_beginAllocated(this) +#define RichString_beginAllocated(this) memset(&(this), 0, sizeof(RichString)); (this).chptr = (this).chstr +#define RichString_end(this) RichString_prune(&(this)) #ifdef HAVE_LIBNCURSESW #define RichString_printVal(this, y, x) mvadd_wchstr(y, x, (this).chptr) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 5e06e8c9..d40249fc 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -778,8 +778,8 @@ static int handleNetlinkMsg(struct nl_msg *nlmsg, void *linuxProcess) { assert(lp->super.pid == (pid_t)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); + #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); From c790b6ae67cc4af9f8b4dbba2e4590d36523f2a9 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 20:18:40 +0100 Subject: [PATCH 02/17] Remove accidental syntax collision --- linux/LinuxProcessList.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index d40249fc..577412a9 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1111,7 +1111,12 @@ static inline void LinuxProcessList_scanMemoryInfo(ProcessList* this) { char buffer[128]; while (fgets(buffer, 128, file)) { - #define tryRead(label, variable) do { if (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %32llu kB", variable)) { break; } } while(0) + #define tryRead(label, variable) \ + if (String_startsWith(buffer, label)) { \ + sscanf(buffer + strlen(label), " %32llu kB", variable); \ + break; \ + } + switch (buffer[0]) { case 'M': tryRead("MemTotal:", &this->totalMem); @@ -1208,8 +1213,17 @@ static inline void LinuxProcessList_scanZfsArcstats(LinuxProcessList* lpl) { } char buffer[128]; while (fgets(buffer, 128, file)) { - #define tryRead(label, variable) do { if (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %*2u %32llu", variable)) { break; } } while(0) - #define tryReadFlag(label, variable, flag) do { if (String_startsWith(buffer, label) && sscanf(buffer + strlen(label), " %*2u %32llu", variable)) { (flag) = 1; break; } else { (flag) = 0; } } while(0) + #define tryRead(label, variable) \ + if (String_startsWith(buffer, label)) { \ + sscanf(buffer + strlen(label), " %*2u %32llu", variable); \ + break; \ + } + #define tryReadFlag(label, variable, flag) \ + if (String_startsWith(buffer, label)) { \ + (flag) = sscanf(buffer + strlen(label), " %*2u %32llu", variable); \ + break; \ + } + switch (buffer[0]) { case 'c': tryRead("c_max", &lpl->zfs.max); From db0a13970ed512a75ade9770f0a1aa468f657f8b Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 20:26:53 +0100 Subject: [PATCH 03/17] Convert addattrstr to static inline function NB: The macro could have been a braced while(0) loop, which without optimization produces more code --- Action.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Action.c b/Action.c index 5b68811e..303eeeaf 100644 --- a/Action.c +++ b/Action.c @@ -443,6 +443,11 @@ static const struct { const char* key; const char* info; } helpRight[] = { { .key = NULL, .info = NULL } }; +static inline void addattrstr( int attr, const char* str) { + attrset(attr); + addstr(str); +} + static Htop_Reaction actionHelp(State* st) { Settings* settings = st->settings; @@ -460,7 +465,7 @@ static Htop_Reaction actionHelp(State* st) { attrset(CRT_colors[DEFAULT_COLOR]); line++; mvaddstr(line++, 0, "CPU usage bar: "); - #define addattrstr(a,s) attrset(a);addstr(s) + addattrstr(CRT_colors[BAR_BORDER], "["); if (settings->detailedCPUTime) { addattrstr(CRT_colors[CPU_NICE_TEXT], "low"); addstr("/"); From 1877325329b282ce59d8d6733b3728913cb2c6b2 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 20:33:01 +0100 Subject: [PATCH 04/17] Spacing after keywords (#define) --- Panel.h | 2 +- RichString.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Panel.h b/Panel.h index ec670ab5..1ada9243 100644 --- a/Panel.h +++ b/Panel.h @@ -61,7 +61,7 @@ struct Panel_ { int selectionColor; }; -#define Panel_setDefaultBar(this_) do{ (this_)->currentBar = (this_)->defaultBar; }while(0) +#define Panel_setDefaultBar(this_) do { (this_)->currentBar = (this_)->defaultBar; } while(0) #define KEY_CTRL(l) ((l)-'A'+1) diff --git a/RichString.h b/RichString.h index 3fb85279..d360299e 100644 --- a/RichString.h +++ b/RichString.h @@ -23,13 +23,13 @@ in the source distribution for its full text. #define RichString_printVal(this, y, x) mvadd_wchstr(y, x, (this).chptr) #define RichString_printoffnVal(this, y, x, off, n) mvadd_wchnstr(y, x, (this).chptr + (off), n) #define RichString_getCharVal(this, i) ((this).chptr[i].chars[0] & 255) -#define RichString_setChar(this, at, ch) do{ (this)->chptr[(at)] = (CharType) { .chars = { ch, 0 } }; } while(0) +#define RichString_setChar(this, at, ch) do { (this)->chptr[(at)] = (CharType) { .chars = { ch, 0 } }; } while(0) #define CharType cchar_t #else #define RichString_printVal(this, y, x) mvaddchstr(y, x, (this).chptr) #define RichString_printoffnVal(this, y, x, off, n) mvaddchnstr(y, x, (this).chptr + (off), n) #define RichString_getCharVal(this, i) ((this).chptr[i]) -#define RichString_setChar(this, at, ch) do{ (this)->chptr[(at)] = ch; } while(0) +#define RichString_setChar(this, at, ch) do { (this)->chptr[(at)] = ch; } while(0) #define CharType chtype #endif From 0a51eae11fdd741c295d7b0390c6d9dbf04468d8 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 20:39:01 +0100 Subject: [PATCH 05/17] Spacing after keywords (while) --- Panel.h | 2 +- RichString.h | 4 ++-- darwin/Platform.c | 4 ++-- htop.c | 4 ++-- linux/LinuxProcessList.c | 14 +++++++------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Panel.h b/Panel.h index 1ada9243..604750a5 100644 --- a/Panel.h +++ b/Panel.h @@ -61,7 +61,7 @@ struct Panel_ { int selectionColor; }; -#define Panel_setDefaultBar(this_) do { (this_)->currentBar = (this_)->defaultBar; } while(0) +#define Panel_setDefaultBar(this_) do { (this_)->currentBar = (this_)->defaultBar; } while (0) #define KEY_CTRL(l) ((l)-'A'+1) diff --git a/RichString.h b/RichString.h index d360299e..11be4137 100644 --- a/RichString.h +++ b/RichString.h @@ -23,13 +23,13 @@ in the source distribution for its full text. #define RichString_printVal(this, y, x) mvadd_wchstr(y, x, (this).chptr) #define RichString_printoffnVal(this, y, x, off, n) mvadd_wchnstr(y, x, (this).chptr + (off), n) #define RichString_getCharVal(this, i) ((this).chptr[i].chars[0] & 255) -#define RichString_setChar(this, at, ch) do { (this)->chptr[(at)] = (CharType) { .chars = { ch, 0 } }; } while(0) +#define RichString_setChar(this, at, ch) do { (this)->chptr[(at)] = (CharType) { .chars = { ch, 0 } }; } while (0) #define CharType cchar_t #else #define RichString_printVal(this, y, x) mvaddchstr(y, x, (this).chptr) #define RichString_printoffnVal(this, y, x, off, n) mvaddchnstr(y, x, (this).chptr + (off), n) #define RichString_getCharVal(this, i) ((this).chptr[i]) -#define RichString_setChar(this, at, ch) do { (this)->chptr[(at)] = ch; } while(0) +#define RichString_setChar(this, at, ch) do { (this)->chptr[(at)] = ch; } while (0) #define CharType chtype #endif diff --git a/darwin/Platform.c b/darwin/Platform.c index b1f9283d..17be92b2 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -286,7 +286,7 @@ char* Platform_getProcessEnv(pid_t pid) { p = strchr(p, 0)+1; // skip padding - while(!*p && p < endp) + while (!*p && p < endp) ++p; // skip argv @@ -294,7 +294,7 @@ char* Platform_getProcessEnv(pid_t pid) { ; // skip padding - while(!*p && p < endp) + while (!*p && p < endp) ++p; size_t size = endp - p; diff --git a/htop.c b/htop.c index e02f388a..f5c35929 100644 --- a/htop.c +++ b/htop.c @@ -190,7 +190,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { flags.pidMatchList = Hashtable_new(8, false); } - while(pid) { + while (pid) { unsigned int num_pid = atoi(pid); // deepcode ignore CastIntegerToAddress: we just want a non-NUll pointer here Hashtable_put(flags.pidMatchList, num_pid, (void *) 1); @@ -218,7 +218,7 @@ static void millisleep(unsigned long millisec) { .tv_sec = 0, .tv_nsec = millisec * 1000000L }; - while(nanosleep(&req,&req)==-1) { + while (nanosleep(&req,&req)==-1) { continue; } } diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 577412a9..e500f9dc 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -165,7 +165,7 @@ static int LinuxProcessList_computeCPUcount(void) { int cpus = 0; char buffer[PROC_LINE_LENGTH + 1]; - while(fgets(buffer, sizeof(buffer), file)) { + while (fgets(buffer, sizeof(buffer), file)) { if (String_startsWith(buffer, "cpu")) cpus++; } @@ -221,7 +221,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui if (statfile == NULL) CRT_fatalError("Cannot open " PROCSTATFILE); - while(true) { + while (true) { char buffer[PROC_LINE_LENGTH + 1]; if (fgets(buffer, sizeof(buffer), statfile) == NULL) { CRT_fatalError("No btime in " PROCSTATFILE); @@ -498,7 +498,7 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di while (fgets(buffer, sizeof(buffer), f)) { if(!strchr(buffer, '\n')) { // Partial line, skip to end of this line - while(fgets(buffer, sizeof(buffer), f)) { + while (fgets(buffer, sizeof(buffer), f)) { if(strchr(buffer, '\n')) { break; } @@ -542,10 +542,10 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d bool foundEnvID = false; bool foundVPid = false; char linebuf[256]; - while(fgets(linebuf, sizeof(linebuf), file) != NULL) { + while (fgets(linebuf, sizeof(linebuf), file) != NULL) { if(strchr(linebuf, '\n') == NULL) { // Partial line, skip to end of this line - while(fgets(linebuf, sizeof(linebuf), file) != NULL) { + while (fgets(linebuf, sizeof(linebuf), file) != NULL) { if(strchr(linebuf, '\n') != NULL) { break; } @@ -569,11 +569,11 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d do { name_value_sep++; - } while(*name_value_sep != '\0' && *name_value_sep <= 32); + } while (*name_value_sep != '\0' && *name_value_sep <= 32); char* value_end = name_value_sep; - while(*value_end != '\0' && *value_end > 32) { + while (*value_end != '\0' && *value_end > 32) { value_end++; } From 374edb9ed5e9d5fa24cfe358258d82f69d9d430d Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 20:52:20 +0100 Subject: [PATCH 06/17] Spacing after keywords (if) --- CRT.c | 4 ++-- Process.c | 2 +- TraceScreen.c | 4 ++-- Vector.c | 4 ++-- darwin/Battery.c | 10 ++++---- darwin/DarwinProcess.c | 6 ++--- darwin/DarwinProcessList.c | 10 ++++---- darwin/Platform.c | 2 +- dragonflybsd/DragonFlyBSDProcessList.c | 4 ++-- freebsd/FreeBSDProcessList.c | 4 ++-- htop.c | 6 ++--- linux/LinuxProcess.c | 6 ++--- linux/LinuxProcessList.c | 32 +++++++++++++------------- linux/Platform.c | 2 +- linux/ZramMeter.c | 6 ++--- solaris/SolarisProcessList.c | 2 +- 16 files changed, 52 insertions(+), 52 deletions(-) diff --git a/CRT.c b/CRT.c index a13f531a..d91d0d79 100644 --- a/CRT.c +++ b/CRT.c @@ -770,7 +770,7 @@ void CRT_handleSIGSEGV(int signal) { ); const char* signal_str = strsignal(signal); - if(!signal_str) { + if (!signal_str) { signal_str = "unknown reason"; } fprintf(stderr, @@ -821,7 +821,7 @@ void CRT_handleSIGSEGV(int signal) { ); /* Call old sigsegv handler; may be default exit or third party one (e.g. ASAN) */ - if(sigaction (signal, &old_sig_handler[signal], NULL) < 0) { + if (sigaction (signal, &old_sig_handler[signal], NULL) < 0) { /* This avoids an infinite loop in case the handler could not be reset. */ fprintf(stderr, "!!! Chained handler could not be restored. Forcing exit.\n" diff --git a/Process.c b/Process.c index 842232f7..bbc85ce1 100644 --- a/Process.c +++ b/Process.c @@ -325,7 +325,7 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field case PID: xSnprintf(buffer, n, Process_pidFormat, this->pid); break; case PPID: xSnprintf(buffer, n, Process_pidFormat, this->ppid); break; case PRIORITY: { - if(this->priority <= -100) + if (this->priority <= -100) xSnprintf(buffer, n, " RT "); else xSnprintf(buffer, n, "%3ld ", this->priority); diff --git a/TraceScreen.c b/TraceScreen.c index e83e8a51..18dad58c 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -81,10 +81,10 @@ bool TraceScreen_forkTracer(TraceScreen* this) { if (pipe(fdpair) == -1) return false; - if(fcntl(fdpair[0], F_SETFL, O_NONBLOCK) < 0) + if (fcntl(fdpair[0], F_SETFL, O_NONBLOCK) < 0) goto err; - if(fcntl(fdpair[1], F_SETFL, O_NONBLOCK) < 0) + if (fcntl(fdpair[1], F_SETFL, O_NONBLOCK) < 0) goto err; pid_t child = fork(); diff --git a/Vector.c b/Vector.c index 63b64723..ea276671 100644 --- a/Vector.c +++ b/Vector.c @@ -201,7 +201,7 @@ void Vector_insert(Vector* this, int idx, void* data_) { Vector_checkArraySize(this); //assert(this->array[this->items] == NULL); - if(idx < this->items) { + if (idx < this->items) { memmove(&this->array[idx + 1], &this->array[idx], (this->items - idx) * sizeof(this->array[0])); } this->array[idx] = data; @@ -215,7 +215,7 @@ Object* Vector_take(Vector* this, int idx) { Object* removed = this->array[idx]; assert(removed); this->items--; - if(idx < this->items) { + if (idx < this->items) { memmove(&this->array[idx], &this->array[idx + 1], (this->items - idx) * sizeof(this->array[0])); } //this->array[this->items] = NULL; diff --git a/darwin/Battery.c b/darwin/Battery.c index d82d0ffd..df644643 100644 --- a/darwin/Battery.c +++ b/darwin/Battery.c @@ -13,7 +13,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) { *level = NAN; *isOnAC = AC_ERROR; - if(NULL == power_sources) { + if (NULL == power_sources) { return; } @@ -21,7 +21,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) { CFDictionaryRef battery = NULL; int len; - if(NULL == list) { + if (NULL == list) { CFRelease(power_sources); return; @@ -35,18 +35,18 @@ void Battery_getData(double* level, ACPresence* isOnAC) { CFArrayGetValueAtIndex(list, i)); /* GET rule */ CFStringRef type; - if(NULL != candidate) { + if (NULL != candidate) { type = (CFStringRef) CFDictionaryGetValue(candidate, CFSTR(kIOPSTransportTypeKey)); /* GET rule */ - if(kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) { + if (kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) { CFRetain(candidate); battery = candidate; } } } - if(NULL != battery) { + if (NULL != battery) { /* Determine the AC state */ CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey)); diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index 73214836..8ad7a6d8 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -212,7 +212,7 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool e */ /* First, the "immutable" parts */ - if(!exists) { + if (!exists) { /* Set the PID/PGID/etc. */ proc->pid = ep->p_pid; proc->ppid = ps->kp_eproc.e_ppid; @@ -244,8 +244,8 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool e void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl) { struct proc_taskinfo pti; - if(sizeof(pti) == proc_pidinfo(proc->super.pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) { - if(0 != proc->utime || 0 != proc->stime) { + if (sizeof(pti) == proc_pidinfo(proc->super.pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) { + if (0 != proc->utime || 0 != proc->stime) { uint64_t diff = (pti.pti_total_system - proc->stime) + (pti.pti_total_user - proc->utime); diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index bae8e222..59ec9d31 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -57,14 +57,14 @@ int CompareKernelVersion(short int major, short int minor, short int component) void ProcessList_getHostInfo(host_basic_info_data_t *p) { mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT; - if(0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) { + if (0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) { CRT_fatalError("Unable to retrieve host info\n"); } } void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) { - if(NULL != p && NULL != *p) { - if(0 != munmap(*p, vm_page_size)) { + if (NULL != p && NULL != *p) { + if (0 != munmap(*p, vm_page_size)) { CRT_fatalError("Unable to free old CPU load information\n"); } *p = NULL; @@ -76,7 +76,7 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) { unsigned cpu_count; // TODO Improving the accuracy of the load counts woule help a lot. - if(0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t *)p, &info_size)) { + if (0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t *)p, &info_size)) { CRT_fatalError("Unable to retrieve CPU info\n"); } @@ -200,7 +200,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { super->totalTasks += 1; - if(!preExisting) { + if (!preExisting) { proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid); ProcessList_add(super, &proc->super); diff --git a/darwin/Platform.c b/darwin/Platform.c index 17be92b2..a7adaeee 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -149,7 +149,7 @@ int Platform_getUptime() { void Platform_getLoadAverage(double* one, double* five, double* fifteen) { double results[3]; - if(3 == getloadavg(results, 3)) { + if (3 == getloadavg(results, 3)) { *one = results[0]; *five = results[1]; *fifteen = results[2]; diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 8c441de5..2fe20dae 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -417,7 +417,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { dfp->jname = DragonFlyBSDProcessList_readJailName(dfpl, kproc->kp_jailid); } else { proc->processor = kproc->kp_lwp.kl_cpuid; - if(dfp->jid != kproc->kp_jailid) { // process can enter jail anytime + if (dfp->jid != kproc->kp_jailid) { // process can enter jail anytime dfp->jid = kproc->kp_jailid; free(dfp->jname); dfp->jname = DragonFlyBSDProcessList_readJailName(dfpl, kproc->kp_jailid); @@ -425,7 +425,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { if (proc->ppid != kproc->kp_ppid) { // if there are reapers in the system, process can get reparented anytime proc->ppid = kproc->kp_ppid; } - if(proc->st_uid != kproc->kp_uid) { // some processes change users (eg. to lower privs) + if (proc->st_uid != kproc->kp_uid) { // some processes change users (eg. to lower privs) proc->st_uid = kproc->kp_uid; proc->user = UsersTable_getRef(super->usersTable, proc->st_uid); } diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index df06546c..bfa046b8 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -502,7 +502,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { proc->comm = FreeBSDProcessList_readProcessName(fpl->kd, kproc, &proc->basenameOffset); fp->jname = FreeBSDProcessList_readJailName(kproc); } else { - if(fp->jid != kproc->ki_jid) { + if (fp->jid != kproc->ki_jid) { // process can enter jail anytime fp->jid = kproc->ki_jid; free(fp->jname); @@ -512,7 +512,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { // if there are reapers in the system, process can get reparented anytime proc->ppid = kproc->ki_ppid; } - if(proc->st_uid != kproc->ki_uid) { + if (proc->st_uid != kproc->ki_uid) { // some processes change users (eg. to lower privs) proc->st_uid = kproc->ki_uid; proc->user = UsersTable_getRef(super->usersTable, proc->st_uid); diff --git a/htop.c b/htop.c index f5c35929..2e11a949 100644 --- a/htop.c +++ b/htop.c @@ -186,7 +186,7 @@ static CommandLineSettings parseArguments(int argc, char** argv) { char* saveptr; char* pid = strtok_r(argCopy, ",", &saveptr); - if(!flags.pidMatchList) { + if (!flags.pidMatchList) { flags.pidMatchList = Hashtable_new(8, false); } @@ -243,7 +243,7 @@ static void setCommFilter(State* state, char** commFilter) { int main(int argc, char** argv) { char *lc_ctype = getenv("LC_CTYPE"); - if(lc_ctype != NULL) + if (lc_ctype != NULL) setlocale(LC_CTYPE, lc_ctype); else if ((lc_ctype = getenv("LC_ALL"))) setlocale(LC_CTYPE, lc_ctype); @@ -334,7 +334,7 @@ int main(int argc, char** argv) { UsersTable_delete(ut); Settings_delete(settings); - if(flags.pidMatchList) { + if (flags.pidMatchList) { Hashtable_delete(flags.pidMatchList); } return 0; diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index d607a71b..94b43896 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -244,11 +244,11 @@ void LinuxProcess_writeField(const Process* this, RichString* str, ProcessField case IO_WRITE_RATE: Process_outputRate(str, buffer, n, lp->io_rate_write_bps, coloring); return; case IO_RATE: { double totalRate = NAN; - if(!isnan(lp->io_rate_read_bps) && !isnan(lp->io_rate_write_bps)) + if (!isnan(lp->io_rate_read_bps) && !isnan(lp->io_rate_write_bps)) totalRate = lp->io_rate_read_bps + lp->io_rate_write_bps; - else if(!isnan(lp->io_rate_read_bps)) + else if (!isnan(lp->io_rate_read_bps)) totalRate = lp->io_rate_read_bps; - else if(!isnan(lp->io_rate_write_bps)) + else if (!isnan(lp->io_rate_write_bps)) totalRate = lp->io_rate_write_bps; else totalRate = NAN; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index e500f9dc..86dd4c75 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -208,7 +208,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui // Check for /proc/*/smaps_rollup availability (improves smaps parsing speed, Linux 4.14+) FILE* file = fopen(PROCDIR "/self/smaps_rollup", "r"); - if(file != NULL) { + if (file != NULL) { this->haveSmapsRollup = true; fclose(file); } else { @@ -271,10 +271,10 @@ void ProcessList_delete(ProcessList* pl) { static inline unsigned long long LinuxProcess_adjustTime(unsigned long long t) { static double jiffy = NAN; - if(isnan(jiffy)) { + if (isnan(jiffy)) { errno = 0; long sc_jiffy = sysconf(_SC_CLK_TCK); - if(errno || -1 == sc_jiffy) { + if (errno || -1 == sc_jiffy) { jiffy = NAN; return t; // Assume 100Hz clock } @@ -481,7 +481,7 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di char buffer[256]; - if(haveSmapsRollup) {// only available in Linux 4.14+ + if (haveSmapsRollup) {// only available in Linux 4.14+ xSnprintf(buffer, sizeof(buffer), "%s/%s/smaps_rollup", dirname, name); } else { xSnprintf(buffer, sizeof(buffer), "%s/%s/smaps", dirname, name); @@ -496,10 +496,10 @@ static bool LinuxProcessList_readSmapsFile(LinuxProcess* process, const char* di process->m_psswp = 0; while (fgets(buffer, sizeof(buffer), f)) { - if(!strchr(buffer, '\n')) { + if (!strchr(buffer, '\n')) { // Partial line, skip to end of this line while (fgets(buffer, sizeof(buffer), f)) { - if(strchr(buffer, '\n')) { + if (strchr(buffer, '\n')) { break; } } @@ -543,10 +543,10 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d bool foundVPid = false; char linebuf[256]; while (fgets(linebuf, sizeof(linebuf), file) != NULL) { - if(strchr(linebuf, '\n') == NULL) { + if (strchr(linebuf, '\n') == NULL) { // Partial line, skip to end of this line while (fgets(linebuf, sizeof(linebuf), file) != NULL) { - if(strchr(linebuf, '\n') != NULL) { + if (strchr(linebuf, '\n') != NULL) { break; } } @@ -554,14 +554,14 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d } char* name_value_sep = strchr(linebuf, ':'); - if(name_value_sep == NULL) { + if (name_value_sep == NULL) { continue; } int field; - if(0 == strncasecmp(linebuf, "envID", name_value_sep - linebuf)) { + if (0 == strncasecmp(linebuf, "envID", name_value_sep - linebuf)) { field = 1; - } else if(0 == strncasecmp(linebuf, "VPid", name_value_sep - linebuf)) { + } else if (0 == strncasecmp(linebuf, "VPid", name_value_sep - linebuf)) { field = 2; } else { continue; @@ -577,7 +577,7 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d value_end++; } - if(name_value_sep == value_end) { + if (name_value_sep == value_end) { continue; } @@ -586,7 +586,7 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d switch(field) { case 1: foundEnvID = true; - if(!String_eq(name_value_sep, process->ctid ? process->ctid : "")) { + if (!String_eq(name_value_sep, process->ctid ? process->ctid : "")) { free(process->ctid); process->ctid = xStrdup(name_value_sep); } @@ -603,12 +603,12 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d fclose(file); - if(!foundEnvID) { + if (!foundEnvID) { free(process->ctid); process->ctid = NULL; } - if(!foundVPid) { + if (!foundVPid) { process->vpid = process->super.pid; } } @@ -1010,7 +1010,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* if (isnan(proc->percent_cpu)) proc->percent_cpu = 0.0; proc->percent_mem = (proc->m_resident * CRT_pageSizeKB) / (double)(pl->totalMem) * 100.0; - if(!preExisting) { + if (!preExisting) { if (! LinuxProcessList_statProcessDir(proc, dirname, name)) goto errorReadingProcess; diff --git a/linux/Platform.c b/linux/Platform.c index f7a768c9..674952b0 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -272,7 +272,7 @@ char* Platform_getProcessEnv(pid_t pid) { char procname[128]; xSnprintf(procname, sizeof(procname), PROCDIR "/%d/environ", pid); FILE* fd = fopen(procname, "r"); - if(!fd) + if (!fd) return NULL; char *env = NULL; diff --git a/linux/ZramMeter.c b/linux/ZramMeter.c index f855488e..30d78eaa 100644 --- a/linux/ZramMeter.c +++ b/linux/ZramMeter.c @@ -19,18 +19,18 @@ static void ZramMeter_updateValues(Meter* this, char* buffer, int size) { written = Meter_humanUnit(buffer, this->values[0], size); buffer += written; size -= written; - if(size <= 0) { + if (size <= 0) { return; } *buffer++ = '('; size--; - if(size <= 0) { + if (size <= 0) { return; } written = Meter_humanUnit(buffer, this->values[1], size); buffer += written; size -= written; - if(size <= 0) { + if (size <= 0) { return; } *buffer++ = ')'; diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 2af82aab..e219d1ee 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -322,7 +322,7 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * // See note above (in common section) about this BINARY FRACTION proc->percent_cpu = ((uint16_t)_psinfo->pr_pctcpu/(double)32768)*(double)100.0; proc->time = _psinfo->pr_time.tv_sec; - if(!preExisting) { // Tasks done only for NEW processes + if (!preExisting) { // Tasks done only for NEW processes sproc->is_lwp = false; proc->starttime_ctime = _psinfo->pr_start.tv_sec; } From adf797c295db2e0b24cc49efc7af70dafc3f10c2 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 20:55:36 +0100 Subject: [PATCH 07/17] Spacing after keywords (for) --- IncSet.c | 2 +- Meter.c | 2 +- Panel.c | 2 +- darwin/Battery.c | 2 +- darwin/DarwinProcessList.c | 6 +++--- darwin/Platform.c | 2 +- linux/Battery.c | 4 ++-- linux/LinuxProcessList.c | 10 +++++----- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/IncSet.c b/IncSet.c index 0d1aecf5..40fe9532 100644 --- a/IncSet.c +++ b/IncSet.c @@ -114,7 +114,7 @@ static bool IncMode_find(IncMode* mode, Panel* panel, IncMode_GetPanelValue getP int size = Panel_size(panel); int here = Panel_getSelectedIndex(panel); int i = here; - for(;;) { + for (;;) { i+=step; if (i == size) i = 0; if (i == -1) i = size - 1; diff --git a/Meter.c b/Meter.c index 59daa0f5..0cf7ee0b 100644 --- a/Meter.c +++ b/Meter.c @@ -52,7 +52,7 @@ int Meter_humanUnit(char* buffer, unsigned long int value, int size) { unsigned long int powi = 1; unsigned int written, powj = 1, precision = 2; - for(;;) { + for (;;) { if (value / 1024 < powi) break; diff --git a/Panel.c b/Panel.c index ab3f6009..7507efda 100644 --- a/Panel.c +++ b/Panel.c @@ -259,7 +259,7 @@ void Panel_draw(Panel* this, bool focus) { if (this->needsRedraw) { int line = 0; - for(int i = first; line < h && i < upTo; i++) { + for (int i = first; line < h && i < upTo; i++) { Object* itemObj = Vector_get(this->items, i); RichString_begin(item); Object_display(itemObj, &item); diff --git a/darwin/Battery.c b/darwin/Battery.c index df644643..854425b3 100644 --- a/darwin/Battery.c +++ b/darwin/Battery.c @@ -30,7 +30,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) { len = CFArrayGetCount(list); /* Get the battery */ - for(int i = 0; i < len && battery == NULL; ++i) { + for (int i = 0; i < len && battery == NULL; ++i) { CFDictionaryRef candidate = IOPSGetPowerSourceDescription(power_sources, CFArrayGetValueAtIndex(list, i)); /* GET rule */ CFStringRef type; diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 59ec9d31..3f72a3a7 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -164,8 +164,8 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { /* Get the time difference */ dpl->global_diff = 0; - for(int i = 0; i < dpl->super.cpuCount; ++i) { - for(size_t j = 0; j < CPU_STATE_MAX; ++j) { + for (int i = 0; i < dpl->super.cpuCount; ++i) { + for (size_t j = 0; j < CPU_STATE_MAX; ++j) { dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j]; } } @@ -185,7 +185,7 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { */ ps = ProcessList_getKInfoProcs(&count); - for(size_t i = 0; i < count; ++i) { + for (size_t i = 0; i < count; ++i) { proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, DarwinProcess_new); DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting); diff --git a/darwin/Platform.c b/darwin/Platform.c index a7adaeee..9086c6de 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -206,7 +206,7 @@ double Platform_setCPUValues(Meter* mtr, int cpu) { double total = 0; /* Take the sums */ - for(size_t i = 0; i < CPU_STATE_MAX; ++i) { + for (size_t i = 0; i < CPU_STATE_MAX; ++i) { total += (double)curr->cpu_ticks[i] - (double)prev->cpu_ticks[i]; } diff --git a/linux/Battery.c b/linux/Battery.c index 0822ee9a..0d0a0ac4 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -168,7 +168,7 @@ static void Battery_getProcData(double* level, ACPresence* isOnAC) { static inline ssize_t xread(int fd, void *buf, size_t count) { // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. size_t alreadyRead = 0; - for(;;) { + for (;;) { ssize_t res = read(fd, buf, count); if (res == -1 && errno == EINTR) continue; if (res > 0) { @@ -282,7 +282,7 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { return; } char buffer[2] = ""; - for(;;) { + for (;;) { ssize_t res = read(fd3, buffer, 1); if (res == -1 && errno == EINTR) continue; break; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 86dd4c75..050607c7 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -54,7 +54,7 @@ in the source distribution for its full text. static ssize_t xread(int fd, void *buf, size_t count) { // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. size_t alreadyRead = 0; - for(;;) { + for (;;) { ssize_t res = read(fd, buf, count); if (res == -1 && errno == EINTR) continue; if (res > 0) { @@ -81,7 +81,7 @@ static void LinuxProcessList_initTtyDrivers(LinuxProcessList* this) { char* buf = NULL; int bufSize = MAX_READ; int bufLen = 0; - for(;;) { + for (;;) { buf = xRealloc(buf, bufSize); int size = xread(fd, buf + bufLen, MAX_READ); if (size <= 0) { @@ -255,7 +255,7 @@ void ProcessList_delete(ProcessList* pl) { ProcessList_done(pl); free(this->cpus); if (this->ttyDrivers) { - for(int i = 0; this->ttyDrivers[i].path; i++) { + for (int i = 0; this->ttyDrivers[i].path; i++) { free(this->ttyDrivers[i].path); } free(this->ttyDrivers); @@ -900,7 +900,7 @@ static char* LinuxProcessList_updateTtyDevice(TtyDriver* ttyDrivers, unsigned in unsigned int idx = min - ttyDrivers[i].minorFrom; struct stat sstat; char* fullPath; - for(;;) { + for (;;) { xAsprintf(&fullPath, "%s/%d", ttyDrivers[i].path, idx); int err = stat(fullPath, &sstat); if (err == 0 && major(sstat.st_rdev) == maj && minor(sstat.st_rdev) == min) return fullPath; @@ -1162,7 +1162,7 @@ static inline void LinuxProcessList_scanZramInfo(LinuxProcessList* this) { char disksize[34]; unsigned int i = 0; - for(;;) { + for (;;) { xSnprintf(mm_stat, sizeof(mm_stat), "/sys/block/zram%u/mm_stat", i); xSnprintf(disksize, sizeof(disksize), "/sys/block/zram%u/disksize", i); i++; From 493217e8145079e552d9da8d69f2767bb1b9e8c7 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 21:10:12 +0100 Subject: [PATCH 08/17] Fix indentation to 3 spaces --- linux/Battery.c | 26 +++++++++++++------------- linux/LinuxProcessList.c | 36 ++++++++++++++++++------------------ 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/linux/Battery.c b/linux/Battery.c index 0d0a0ac4..3554d799 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -166,19 +166,19 @@ static void Battery_getProcData(double* level, ACPresence* isOnAC) { // ---------------------------------------- static inline ssize_t xread(int fd, void *buf, size_t count) { - // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. - size_t alreadyRead = 0; - for (;;) { - ssize_t res = read(fd, buf, count); - if (res == -1 && errno == EINTR) continue; - if (res > 0) { - buf = ((char*)buf)+res; - count -= res; - alreadyRead += res; - } - if (res == -1) return -1; - if (count == 0 || res == 0) return alreadyRead; - } + // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. + size_t alreadyRead = 0; + for (;;) { + ssize_t res = read(fd, buf, count); + if (res == -1 && errno == EINTR) continue; + if (res > 0) { + buf = ((char*)buf)+res; + count -= res; + alreadyRead += res; + } + if (res == -1) return -1; + if (count == 0 || res == 0) return alreadyRead; + } } static void Battery_getSysData(double* level, ACPresence* isOnAC) { diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 050607c7..fb8bfc53 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -52,19 +52,19 @@ in the source distribution for its full text. static ssize_t xread(int fd, void *buf, size_t count) { - // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. - size_t alreadyRead = 0; - for (;;) { - ssize_t res = read(fd, buf, count); - if (res == -1 && errno == EINTR) continue; - if (res > 0) { - buf = ((char*)buf)+res; - count -= res; - alreadyRead += res; - } - if (res == -1) return -1; - if (count == 0 || res == 0) return alreadyRead; - } + // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. + size_t alreadyRead = 0; + for (;;) { + ssize_t res = read(fd, buf, count); + if (res == -1 && errno == EINTR) continue; + if (res > 0) { + buf = ((char*)buf)+res; + count -= res; + alreadyRead += res; + } + if (res == -1) return -1; + if (count == 0 || res == 0) return alreadyRead; + } } static int sortTtyDrivers(const void* va, const void* vb) { @@ -448,7 +448,7 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna case 'c': if (String_startsWith(line+1, "ancelled_write_bytes: ")) { process->io_cancelled_write_bytes = strtoull(line+23, NULL, 10); - } + } } } } @@ -981,14 +981,14 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* // Read smaps file of each process only every second pass to improve performance static int smaps_flag = 0; if ((pid & 1) == smaps_flag){ - LinuxProcessList_readSmapsFile(lp, dirname, name, this->haveSmapsRollup); + LinuxProcessList_readSmapsFile(lp, dirname, name, this->haveSmapsRollup); } if (pid == 1) { smaps_flag = !smaps_flag; } - } else { + } else { lp->m_pss = ((LinuxProcess*)parent)->m_pss; - } + } } proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc))); @@ -1336,8 +1336,8 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) { cpuData->stealTime = steal; cpuData->guestTime = virtalltime; cpuData->totalTime = totaltime; - } + double period = (double)this->cpus[0].totalPeriod / cpus; fclose(file); return period; From 9a16b1079ec1e831a449eb23ff23bf13b1b2a935 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 21:11:39 +0100 Subject: [PATCH 09/17] Make scope of match macro symmetric --- linux/Battery.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/linux/Battery.c b/linux/Battery.c index 3554d799..c185258a 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -232,9 +232,11 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { bool now = false; int fullSize = 0; double capacityLevel = NAN; + + #define match(str,prefix) \ + (String_startsWith(str,prefix) ? (str) + strlen(prefix) : NULL) + while ((line = strsep(&buf, "\n")) != NULL) { - #define match(str,prefix) \ - (String_startsWith(str,prefix) ? (str) + strlen(prefix) : NULL) const char* ps = match(line, "POWER_SUPPLY_"); if (!ps) { continue; @@ -266,7 +268,9 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { continue; } } - #undef match + + #undef match + if (!now && full && !isnan(capacityLevel)) { totalRemain += (capacityLevel * fullSize); } From b23f8235e28472c410dcb00893e0e3d403892673 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 22:14:27 +0100 Subject: [PATCH 10/17] Whitespace and indentation issues --- Affinity.c | 2 +- AffinityPanel.c | 4 +- IncSet.c | 2 +- ListItem.c | 4 +- Panel.c | 4 +- Process.c | 4 +- Settings.c | 5 +- darwin/Battery.c | 12 +- darwin/DarwinProcess.c | 18 +-- darwin/DarwinProcessList.c | 152 +++++++++++++------------ darwin/Platform.c | 18 +-- dragonflybsd/DragonFlyBSDProcessList.c | 47 ++++---- dragonflybsd/Platform.c | 6 +- freebsd/FreeBSDProcessList.c | 42 +++---- freebsd/Platform.c | 6 +- linux/LinuxProcess.c | 13 ++- linux/LinuxProcessList.c | 24 ++-- linux/PressureStallMeter.c | 32 +++--- openbsd/OpenBSDProcess.c | 75 ++++++++---- openbsd/Platform.c | 10 +- solaris/Platform.c | 6 +- solaris/SolarisProcessList.c | 54 +++++---- unsupported/UnsupportedProcessList.c | 64 +++++------ zfs/openzfs_sysctl.c | 31 ++--- 24 files changed, 347 insertions(+), 288 deletions(-) diff --git a/Affinity.c b/Affinity.c index 4d78944c..96591a65 100644 --- a/Affinity.c +++ b/Affinity.c @@ -65,7 +65,7 @@ Affinity* Affinity_get(Process* proc, ProcessList* pl) { } else { unsigned int id; hwloc_bitmap_foreach_begin(id, cpuset); - Affinity_add(affinity, id); + Affinity_add(affinity, id); hwloc_bitmap_foreach_end(); } } diff --git a/AffinityPanel.c b/AffinityPanel.c index a8cb66ee..e184d64b 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -285,7 +285,7 @@ static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u left -= len; } xSnprintf(&indent_buf[off], left, "%s", - obj->next_sibling ? CRT_treeStr[TREE_STR_RTEE] : CRT_treeStr[TREE_STR_BEND]); + obj->next_sibling ? CRT_treeStr[TREE_STR_RTEE] : CRT_treeStr[TREE_STR_BEND]); // Uncomment when further appending to indent_buf //size_t len = strlen(&indent_buf[off]); //off += len; @@ -417,7 +417,7 @@ Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl) { #ifdef HAVE_LIBHWLOC int i; hwloc_bitmap_foreach_begin(i, this->workCpuset) - Affinity_add(affinity, i); + Affinity_add(affinity, i); hwloc_bitmap_foreach_end(); #else for (int i = 0; i < this->pl->cpuCount; i++) { diff --git a/IncSet.c b/IncSet.c index 40fe9532..3deda737 100644 --- a/IncSet.c +++ b/IncSet.c @@ -170,7 +170,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue doSearch = false; } } else if (ch == KEY_RESIZE) { - Panel_resize(panel, COLS, LINES-panel->y-1); + Panel_resize(panel, COLS, LINES - panel->y - 1); } else { if (mode->isFilter) { filterChanged = true; diff --git a/ListItem.c b/ListItem.c index 031c4f72..c3c1a7d3 100644 --- a/ListItem.c +++ b/ListItem.c @@ -31,9 +31,9 @@ static void ListItem_display(const Object* cast, RichString* out) { if (this->moving) { RichString_write(out, CRT_colors[DEFAULT_COLOR], #ifdef HAVE_LIBNCURSESW - CRT_utf8 ? "↕ " : + CRT_utf8 ? "↕ " : #endif - "+ "); + "+ "); } else { RichString_prune(out); } diff --git a/Panel.c b/Panel.c index 7507efda..4c333963 100644 --- a/Panel.c +++ b/Panel.c @@ -254,8 +254,8 @@ void Panel_draw(Panel* this, bool focus) { int upTo = MINIMUM(first + h, size); int selectionColor = focus - ? this->selectionColor - : CRT_colors[PANEL_SELECTION_UNFOCUS]; + ? this->selectionColor + : CRT_colors[PANEL_SELECTION_UNFOCUS]; if (this->needsRedraw) { int line = 0; diff --git a/Process.c b/Process.c index bbc85ce1..11b99b8b 100644 --- a/Process.c +++ b/Process.c @@ -287,8 +287,8 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field for (int i = 0; i < 32; i++) if (indent & (1U << i)) - maxIndent = i+1; - for (int i = 0; i < maxIndent - 1; i++) { + maxIndent = i + 1; + for (int i = 0; i < maxIndent - 1; i++) { int written, ret; if (indent & (1 << i)) ret = snprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]); diff --git a/Settings.c b/Settings.c index 9ac27565..2cb560ed 100644 --- a/Settings.c +++ b/Settings.c @@ -182,8 +182,9 @@ static bool Settings_read(Settings* this, const char* fileName, int initialCpuCo this->delay = atoi(option[1]); } else if (String_eq(option[0], "color_scheme")) { this->colorScheme = atoi(option[1]); - if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) this->colorScheme = 0; - } else if (String_eq(option[0], "enable_mouse")) { + if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) + this->colorScheme = 0; + } else if (String_eq(option[0], "enable_mouse")) { this->enableMouse = atoi(option[1]); } else if (String_eq(option[0], "left_meters")) { Settings_readMeters(this, option[1], 0); diff --git a/darwin/Battery.c b/darwin/Battery.c index 854425b3..c89f5b30 100644 --- a/darwin/Battery.c +++ b/darwin/Battery.c @@ -32,12 +32,12 @@ void Battery_getData(double* level, ACPresence* isOnAC) { /* Get the battery */ for (int i = 0; i < len && battery == NULL; ++i) { CFDictionaryRef candidate = IOPSGetPowerSourceDescription(power_sources, - CFArrayGetValueAtIndex(list, i)); /* GET rule */ + CFArrayGetValueAtIndex(list, i)); /* GET rule */ CFStringRef type; if (NULL != candidate) { type = (CFStringRef) CFDictionaryGetValue(candidate, - CFSTR(kIOPSTransportTypeKey)); /* GET rule */ + CFSTR(kIOPSTransportTypeKey)); /* GET rule */ if (kCFCompareEqualTo == CFStringCompare(type, CFSTR(kIOPSInternalType), 0)) { CFRetain(candidate); @@ -51,17 +51,17 @@ void Battery_getData(double* level, ACPresence* isOnAC) { CFStringRef power_state = CFDictionaryGetValue(battery, CFSTR(kIOPSPowerSourceStateKey)); *isOnAC = (kCFCompareEqualTo == CFStringCompare(power_state, CFSTR(kIOPSACPowerValue), 0)) - ? AC_PRESENT - : AC_ABSENT; + ? AC_PRESENT + : AC_ABSENT; /* Get the percentage remaining */ double current; double max; CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSCurrentCapacityKey)), - kCFNumberDoubleType, ¤t); + kCFNumberDoubleType, ¤t); CFNumberGetValue(CFDictionaryGetValue(battery, CFSTR(kIOPSMaxCapacityKey)), - kCFNumberDoubleType, &max); + kCFNumberDoubleType, &max); *level = (current * 100.0) / max; diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index 8ad7a6d8..a92f2661 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -158,12 +158,12 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) { /* Convert previous '\0'. */ *np = ' '; } - /* Note location of current '\0'. */ - np = cp; - if (*basenameOffset == 0) { - *basenameOffset = cp - sp; - } - } + /* Note location of current '\0'. */ + np = cp; + if (*basenameOffset == 0) { + *basenameOffset = cp - sp; + } + } } /* @@ -247,10 +247,10 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList if (sizeof(pti) == proc_pidinfo(proc->super.pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) { if (0 != proc->utime || 0 != proc->stime) { uint64_t diff = (pti.pti_total_system - proc->stime) - + (pti.pti_total_user - proc->utime); + + (pti.pti_total_user - proc->utime); proc->super.percent_cpu = (double)diff * (double)dpl->super.cpuCount - / ((double)dpl->global_diff * 100000.0); + / ((double)dpl->global_diff * 100000.0); // fprintf(stderr, "%f %llu %llu %llu %llu %llu\n", proc->super.percent_cpu, // proc->stime, proc->utime, pti.pti_total_system, pti.pti_total_user, dpl->global_diff); @@ -263,7 +263,7 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList proc->super.m_resident = pti.pti_resident_size / CRT_pageSize; proc->super.majflt = pti.pti_faults; proc->super.percent_mem = (double)pti.pti_resident_size * 100.0 - / (double)dpl->host_info.max_mem; + / (double)dpl->host_info.max_mem; proc->stime = pti.pti_total_system; proc->utime = pti.pti_total_user; diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 3f72a3a7..bb7c56db 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -24,7 +24,7 @@ in the source distribution for its full text. #include struct kern { - short int version[3]; + short int version[3]; }; void GetKernelVersion(struct kern *k) { @@ -35,9 +35,11 @@ void GetKernelVersion(struct kern *k) { char str[256] = {0}; size_t size = sizeof(str); int ret = sysctlbyname("kern.osrelease", str, &size, NULL, 0); - if (ret == 0) sscanf(str, "%hd.%hd.%hd", &version_[0], &version_[1], &version_[2]); - } - memcpy(k->version, version_, sizeof(version_)); + if (ret == 0) { + sscanf(str, "%hd.%hd.%hd", &version_[0], &version_[1], &version_[2]); + } + } + memcpy(k->version, version_, sizeof(version_)); } /* compare the given os version with the one installed returns: @@ -46,28 +48,36 @@ positive value if less than the installed version negative value if more than the installed version */ int CompareKernelVersion(short int major, short int minor, short int component) { - struct kern k; - GetKernelVersion(&k); - if ( k.version[0] != major) return k.version[0] - major; - if ( k.version[1] != minor) return k.version[1] - minor; - if ( k.version[2] != component) return k.version[2] - component; - return 0; + struct kern k; + GetKernelVersion(&k); + + if (k.version[0] != major) { + return k.version[0] - major; + } + if (k.version[1] != minor) { + return k.version[1] - minor; + } + if (k.version[2] != component) { + return k.version[2] - component; + } + + return 0; } void ProcessList_getHostInfo(host_basic_info_data_t *p) { mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT; if (0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) { - CRT_fatalError("Unable to retrieve host info\n"); + CRT_fatalError("Unable to retrieve host info\n"); } } void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) { if (NULL != p && NULL != *p) { - if (0 != munmap(*p, vm_page_size)) { - CRT_fatalError("Unable to free old CPU load information\n"); - } - *p = NULL; + if (0 != munmap(*p, vm_page_size)) { + CRT_fatalError("Unable to free old CPU load information\n"); + } + *p = NULL; } } @@ -76,18 +86,19 @@ unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) { unsigned cpu_count; // TODO Improving the accuracy of the load counts woule help a lot. - if (0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t *)p, &info_size)) { - CRT_fatalError("Unable to retrieve CPU info\n"); + if (0 != host_processor_info(mach_host_self(), PROCESSOR_CPU_LOAD_INFO, &cpu_count, (processor_info_array_t*)p, &info_size)) { + CRT_fatalError("Unable to retrieve CPU info\n"); } return cpu_count; } void ProcessList_getVMStats(vm_statistics_t p) { - mach_msg_type_number_t info_size = HOST_VM_INFO_COUNT; + mach_msg_type_number_t info_size = HOST_VM_INFO_COUNT; - if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)p, &info_size) != 0) - CRT_fatalError("Unable to retrieve VM statistics\n"); + if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)p, &info_size) != 0) { + CRT_fatalError("Unable to retrieve VM statistics\n"); + } } struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) { @@ -145,67 +156,68 @@ void ProcessList_delete(ProcessList* this) { } void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { - DarwinProcessList *dpl = (DarwinProcessList *)super; - bool preExisting = true; - struct kinfo_proc *ps; - size_t count; - DarwinProcess *proc; + DarwinProcessList* dpl = (DarwinProcessList*)super; + bool preExisting = true; + struct kinfo_proc* ps; + size_t count; + DarwinProcess* proc; - /* Update the global data (CPU times and VM stats) */ - ProcessList_freeCPULoadInfo(&dpl->prev_load); - dpl->prev_load = dpl->curr_load; - ProcessList_allocateCPULoadInfo(&dpl->curr_load); - ProcessList_getVMStats(&dpl->vm_stats); - openzfs_sysctl_updateArcStats(&dpl->zfs); + /* Update the global data (CPU times and VM stats) */ + ProcessList_freeCPULoadInfo(&dpl->prev_load); + dpl->prev_load = dpl->curr_load; + ProcessList_allocateCPULoadInfo(&dpl->curr_load); + ProcessList_getVMStats(&dpl->vm_stats); + openzfs_sysctl_updateArcStats(&dpl->zfs); - // in pause mode only gather global data for meters (CPU/memory/...) - if (pauseProcessUpdate) - return; + // in pause mode only gather global data for meters (CPU/memory/...) + if (pauseProcessUpdate) { + return; + } - /* Get the time difference */ - dpl->global_diff = 0; - for (int i = 0; i < dpl->super.cpuCount; ++i) { - for (size_t j = 0; j < CPU_STATE_MAX; ++j) { - dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j]; - } - } + /* Get the time difference */ + dpl->global_diff = 0; + for (int i = 0; i < dpl->super.cpuCount; ++i) { + for (size_t j = 0; j < CPU_STATE_MAX; ++j) { + dpl->global_diff += dpl->curr_load[i].cpu_ticks[j] - dpl->prev_load[i].cpu_ticks[j]; + } + } - /* Clear the thread counts */ - super->kernelThreads = 0; - super->userlandThreads = 0; - super->totalTasks = 0; - super->runningTasks = 0; + /* Clear the thread counts */ + super->kernelThreads = 0; + super->userlandThreads = 0; + super->totalTasks = 0; + super->runningTasks = 0; - /* We use kinfo_procs for initial data since : - * - * 1) They always succeed. - * 2) The contain the basic information. - * - * We attempt to fill-in additional information with libproc. - */ - ps = ProcessList_getKInfoProcs(&count); + /* We use kinfo_procs for initial data since : + * + * 1) They always succeed. + * 2) The contain the basic information. + * + * We attempt to fill-in additional information with libproc. + */ + ps = ProcessList_getKInfoProcs(&count); - for (size_t i = 0; i < count; ++i) { - proc = (DarwinProcess *)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, DarwinProcess_new); + for (size_t i = 0; i < count; ++i) { + proc = (DarwinProcess*)ProcessList_getProcess(super, ps[i].kp_proc.p_pid, &preExisting, DarwinProcess_new); - DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting); - DarwinProcess_setFromLibprocPidinfo(proc, dpl); + DarwinProcess_setFromKInfoProc(&proc->super, &ps[i], preExisting); + DarwinProcess_setFromLibprocPidinfo(proc, dpl); - // Disabled for High Sierra due to bug in macOS High Sierra - bool isScanThreadSupported = ! ( CompareKernelVersion(17, 0, 0) >= 0 && CompareKernelVersion(17, 5, 0) < 0); + // Disabled for High Sierra due to bug in macOS High Sierra + bool isScanThreadSupported = ! ( CompareKernelVersion(17, 0, 0) >= 0 && CompareKernelVersion(17, 5, 0) < 0); - if (isScanThreadSupported){ - DarwinProcess_scanThreads(proc); - } + if (isScanThreadSupported) { + DarwinProcess_scanThreads(proc); + } - super->totalTasks += 1; + super->totalTasks += 1; - if (!preExisting) { - proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid); + if (!preExisting) { + proc->super.user = UsersTable_getRef(super->usersTable, proc->super.st_uid); - ProcessList_add(super, &proc->super); - } - } + ProcessList_add(super, &proc->super); + } + } - free(ps); + free(ps); } diff --git a/darwin/Platform.c b/darwin/Platform.c index 9086c6de..c5a22da4 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -211,11 +211,11 @@ double Platform_setCPUValues(Meter* mtr, int cpu) { } mtr->values[CPU_METER_NICE] - = ((double)curr->cpu_ticks[CPU_STATE_NICE] - (double)prev->cpu_ticks[CPU_STATE_NICE])* 100.0 / total; + = ((double)curr->cpu_ticks[CPU_STATE_NICE] - (double)prev->cpu_ticks[CPU_STATE_NICE]) * 100.0 / total; mtr->values[CPU_METER_NORMAL] - = ((double)curr->cpu_ticks[CPU_STATE_USER] - (double)prev->cpu_ticks[CPU_STATE_USER])* 100.0 / total; + = ((double)curr->cpu_ticks[CPU_STATE_USER] - (double)prev->cpu_ticks[CPU_STATE_USER]) * 100.0 / total; mtr->values[CPU_METER_KERNEL] - = ((double)curr->cpu_ticks[CPU_STATE_SYSTEM] - (double)prev->cpu_ticks[CPU_STATE_SYSTEM])* 100.0 / total; + = ((double)curr->cpu_ticks[CPU_STATE_SYSTEM] - (double)prev->cpu_ticks[CPU_STATE_SYSTEM]) * 100.0 / total; mtr->curItems = 3; @@ -239,13 +239,13 @@ void Platform_setMemoryValues(Meter* mtr) { } void Platform_setSwapValues(Meter* mtr) { - int mib[2] = {CTL_VM, VM_SWAPUSAGE}; - struct xsw_usage swapused; - size_t swlen = sizeof(swapused); - sysctl(mib, 2, &swapused, &swlen, NULL, 0); + int mib[2] = {CTL_VM, VM_SWAPUSAGE}; + struct xsw_usage swapused; + size_t swlen = sizeof(swapused); + sysctl(mib, 2, &swapused, &swlen, NULL, 0); - mtr->total = swapused.xsu_total / 1024; - mtr->values[0] = swapused.xsu_used / 1024; + mtr->total = swapused.xsu_total / 1024; + mtr->values[0] = swapused.xsu_used / 1024; } void Platform_setZfsArcValues(Meter* this) { diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 2fe20dae..90bc7f7a 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -101,10 +101,10 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui pl->cpuCount = MAXIMUM(cpus, 1); if (cpus == 1 ) { - dfpl->cpus = xRealloc(dfpl->cpus, sizeof(CPUData)); + dfpl->cpus = xRealloc(dfpl->cpus, sizeof(CPUData)); } else { - // on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well) - dfpl->cpus = xRealloc(dfpl->cpus, (pl->cpuCount + 1) * sizeof(CPUData)); + // on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well) + dfpl->cpus = xRealloc(dfpl->cpus, (pl->cpuCount + 1) * sizeof(CPUData)); } len = sizeof(kernelFScale); @@ -161,12 +161,12 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) { // get rest of CPUs if (cpus > 1) { - // on smp systems DragonFlyBSD kernel concats all CPU states into one long array in - // kern.cp_times sysctl OID - // we store averages in dfpl->cpus[0], and actual cores after that - maxcpu = cpus + 1; - sizeof_cp_time_array = cpus * sizeof(unsigned long) * CPUSTATES; - sysctl(MIB_kern_cp_times, 2, dfpl->cp_times_n, &sizeof_cp_time_array, NULL, 0); + // on smp systems DragonFlyBSD kernel concats all CPU states into one long array in + // kern.cp_times sysctl OID + // we store averages in dfpl->cpus[0], and actual cores after that + maxcpu = cpus + 1; + sizeof_cp_time_array = cpus * sizeof(unsigned long) * CPUSTATES; + sysctl(MIB_kern_cp_times, 2, dfpl->cp_times_n, &sizeof_cp_time_array, NULL, 0); } for (int i = 0; i < maxcpu; i++) { @@ -176,14 +176,14 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) { cp_time_o = dfpl->cp_time_o; } else { if (i == 0 ) { - // average - cp_time_n = dfpl->cp_time_n; - cp_time_o = dfpl->cp_time_o; + // average + cp_time_n = dfpl->cp_time_n; + cp_time_o = dfpl->cp_time_o; } else { - // specific smp cores - cp_times_offset = i - 1; - cp_time_n = dfpl->cp_times_n + (cp_times_offset * CPUSTATES); - cp_time_o = dfpl->cp_times_o + (cp_times_offset * CPUSTATES); + // specific smp cores + cp_times_offset = i - 1; + cp_time_n = dfpl->cp_times_n + (cp_times_offset * CPUSTATES); + cp_time_o = dfpl->cp_times_o + (cp_times_offset * CPUSTATES); } } @@ -192,9 +192,9 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) { unsigned long long total_n = 0; unsigned long long total_d = 0; for (int s = 0; s < CPUSTATES; s++) { - cp_time_d[s] = cp_time_n[s] - cp_time_o[s]; - total_o += cp_time_o[s]; - total_n += cp_time_n[s]; + cp_time_d[s] = cp_time_n[s] - cp_time_o[s]; + total_o += cp_time_o[s]; + total_n += cp_time_n[s]; } // totals @@ -203,8 +203,8 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) { // save current state as old and calc percentages for (int s = 0; s < CPUSTATES; ++s) { - cp_time_o[s] = cp_time_n[s]; - cp_time_p[s] = ((double)cp_time_d[s]) / ((double)total_d) * 100; + cp_time_o[s] = cp_time_n[s]; + cp_time_p[s] = ((double)cp_time_d[s]) / ((double)total_d) * 100; } CPUData* cpuData = &(dfpl->cpus[i]); @@ -344,8 +344,9 @@ retry: } curpos = nextpos; - } - free(jls); + } + + free(jls); } char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int jailid) { diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 5b81c610..6f8c2023 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -154,10 +154,10 @@ double Platform_setCPUValues(Meter* this, int cpu) { const CPUData* cpuData; if (cpus == 1) { - // single CPU box has everything in fpl->cpus[0] - cpuData = &(fpl->cpus[0]); + // single CPU box has everything in fpl->cpus[0] + cpuData = &(fpl->cpus[0]); } else { - cpuData = &(fpl->cpus[cpu]); + cpuData = &(fpl->cpus[cpu]); } double percent; diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index bfa046b8..8be627c9 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -124,10 +124,10 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui pl->cpuCount = MAXIMUM(cpus, 1); if (cpus == 1 ) { - fpl->cpus = xRealloc(fpl->cpus, sizeof(CPUData)); + fpl->cpus = xRealloc(fpl->cpus, sizeof(CPUData)); } else { - // on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well) - fpl->cpus = xRealloc(fpl->cpus, (pl->cpuCount + 1) * sizeof(CPUData)); + // on smp we need CPUs + 1 to store averages too (as kernel kindly provides that as well) + fpl->cpus = xRealloc(fpl->cpus, (pl->cpuCount + 1) * sizeof(CPUData)); } @@ -187,12 +187,12 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) { // get rest of CPUs if (cpus > 1) { - // on smp systems FreeBSD kernel concats all CPU states into one long array in - // kern.cp_times sysctl OID - // we store averages in fpl->cpus[0], and actual cores after that - maxcpu = cpus + 1; - sizeof_cp_time_array = cpus * sizeof(unsigned long) * CPUSTATES; - sysctl(MIB_kern_cp_times, 2, fpl->cp_times_n, &sizeof_cp_time_array, NULL, 0); + // on smp systems FreeBSD kernel concats all CPU states into one long array in + // kern.cp_times sysctl OID + // we store averages in fpl->cpus[0], and actual cores after that + maxcpu = cpus + 1; + sizeof_cp_time_array = cpus * sizeof(unsigned long) * CPUSTATES; + sysctl(MIB_kern_cp_times, 2, fpl->cp_times_n, &sizeof_cp_time_array, NULL, 0); } for (int i = 0; i < maxcpu; i++) { @@ -202,14 +202,14 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) { cp_time_o = fpl->cp_time_o; } else { if (i == 0 ) { - // average - cp_time_n = fpl->cp_time_n; - cp_time_o = fpl->cp_time_o; + // average + cp_time_n = fpl->cp_time_n; + cp_time_o = fpl->cp_time_o; } else { - // specific smp cores - cp_times_offset = i - 1; - cp_time_n = fpl->cp_times_n + (cp_times_offset * CPUSTATES); - cp_time_o = fpl->cp_times_o + (cp_times_offset * CPUSTATES); + // specific smp cores + cp_times_offset = i - 1; + cp_time_n = fpl->cp_times_n + (cp_times_offset * CPUSTATES); + cp_time_o = fpl->cp_times_o + (cp_times_offset * CPUSTATES); } } @@ -218,9 +218,9 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) { unsigned long long total_n = 0; unsigned long long total_d = 0; for (int s = 0; s < CPUSTATES; s++) { - cp_time_d[s] = cp_time_n[s] - cp_time_o[s]; - total_o += cp_time_o[s]; - total_n += cp_time_n[s]; + cp_time_d[s] = cp_time_n[s] - cp_time_o[s]; + total_o += cp_time_o[s]; + total_n += cp_time_n[s]; } // totals @@ -229,8 +229,8 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) { // save current state as old and calc percentages for (int s = 0; s < CPUSTATES; ++s) { - cp_time_o[s] = cp_time_n[s]; - cp_time_p[s] = ((double)cp_time_d[s]) / ((double)total_d) * 100; + cp_time_o[s] = cp_time_n[s]; + cp_time_p[s] = ((double)cp_time_d[s]) / ((double)total_d) * 100; } CPUData* cpuData = &(fpl->cpus[i]); diff --git a/freebsd/Platform.c b/freebsd/Platform.c index bdd49bf6..32b54293 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -165,10 +165,10 @@ double Platform_setCPUValues(Meter* this, int cpu) { const CPUData* cpuData; if (cpus == 1) { - // single CPU box has everything in fpl->cpus[0] - cpuData = &(fpl->cpus[0]); + // single CPU box has everything in fpl->cpus[0] + cpuData = &(fpl->cpus[0]); } else { - cpuData = &(fpl->cpus[cpu]); + cpuData = &(fpl->cpus[cpu]); } double percent; diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index 94b43896..a5d7eccf 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -194,11 +194,11 @@ bool LinuxProcess_setIOPriority(Process* this, Arg ioprio) { #ifdef HAVE_DELAYACCT void LinuxProcess_printDelay(float delay_percent, char* buffer, int n) { - if (isnan(delay_percent)) { - xSnprintf(buffer, n, " N/A "); - } else { - xSnprintf(buffer, n, "%4.1f ", delay_percent); - } + if (isnan(delay_percent)) { + xSnprintf(buffer, n, " N/A "); + } else { + xSnprintf(buffer, n, "%4.1f ", delay_percent); + } } #endif @@ -379,7 +379,8 @@ long LinuxProcess_compare(const void* v1, const void* v2) { default: return Process_compare(v1, v2); } - test_diff: + +test_diff: return (diff > 0) ? 1 : (diff < 0 ? -1 : 0); } diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index fb8bfc53..6065d429 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -419,20 +419,20 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna while ((line = strsep(&buf, "\n")) != NULL) { switch (line[0]) { case 'r': - if (line[1] == 'c' && String_startsWith(line+2, "har: ")) - process->io_rchar = strtoull(line+7, NULL, 10); - else if (String_startsWith(line+1, "ead_bytes: ")) { - process->io_read_bytes = strtoull(line+12, NULL, 10); + if (line[1] == 'c' && String_startsWith(line + 2, "har: ")) { + process->io_rchar = strtoull(line + 7, NULL, 10); + } else if (String_startsWith(line + 1, "ead_bytes: ")) { + process->io_read_bytes = strtoull(line + 12, NULL, 10); process->io_rate_read_bps = ((double)(process->io_read_bytes - last_read))/(((double)(now - process->io_rate_read_time))/1000); process->io_rate_read_time = now; } break; case 'w': - if (line[1] == 'c' && String_startsWith(line+2, "har: ")) - process->io_wchar = strtoull(line+7, NULL, 10); - else if (String_startsWith(line+1, "rite_bytes: ")) { - process->io_write_bytes = strtoull(line+13, NULL, 10); + if (line[1] == 'c' && String_startsWith(line + 2, "har: ")) { + process->io_wchar = strtoull(line + 7, NULL, 10); + } else if (String_startsWith(line + 1, "rite_bytes: ")) { + process->io_write_bytes = strtoull(line + 13, NULL, 10); process->io_rate_write_bps = ((double)(process->io_write_bytes - last_write))/(((double)(now - process->io_rate_write_time))/1000); process->io_rate_write_time = now; @@ -446,8 +446,8 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna } break; case 'c': - if (String_startsWith(line+1, "ancelled_write_bytes: ")) { - process->io_cancelled_write_bytes = strtoull(line+23, NULL, 10); + if (String_startsWith(line + 1, "ancelled_write_bytes: ")) { + process->io_cancelled_write_bytes = strtoull(line + 23, NULL, 10); } } } @@ -1087,7 +1087,9 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* continue; // Exception handler. - errorReadingProcess: { + +errorReadingProcess: + { if (preExisting) { ProcessList_remove(pl, proc); } else { diff --git a/linux/PressureStallMeter.c b/linux/PressureStallMeter.c index 9ac0ced2..3b5415c5 100644 --- a/linux/PressureStallMeter.c +++ b/linux/PressureStallMeter.c @@ -24,24 +24,24 @@ static const int PressureStallMeter_attributes[] = { }; static void PressureStallMeter_updateValues(Meter* this, char* buffer, int len) { - const char *file; - if (strstr(Meter_name(this), "CPU")) { - file = "cpu"; - } else if (strstr(Meter_name(this), "IO")) { - file = "io"; - } else { - file = "memory"; - } + const char* file; + if (strstr(Meter_name(this), "CPU")) { + file = "cpu"; + } else if (strstr(Meter_name(this), "IO")) { + file = "io"; + } else { + file = "memory"; + } - bool some; - if (strstr(Meter_name(this), "Some")) { - some = true; - } else { - some = false; - } + bool some; + if (strstr(Meter_name(this), "Some")) { + some = true; + } else { + some = false; + } - Platform_getPressureStall(file, some, &this->values[0], &this->values[1], &this->values[2]); - xSnprintf(buffer, len, "xxxx %.2lf%% %.2lf%% %.2lf%%", this->values[0], this->values[1], this->values[2]); + Platform_getPressureStall(file, some, &this->values[0], &this->values[1], &this->values[2]); + xSnprintf(buffer, len, "xxxx %.2lf%% %.2lf%% %.2lf%%", this->values[0], this->values[1], this->values[2]); } static void PressureStallMeter_display(const Object* cast, RichString* out) { diff --git a/openbsd/OpenBSDProcess.c b/openbsd/OpenBSDProcess.c index c43fe2fc..5eb61b16 100644 --- a/openbsd/OpenBSDProcess.c +++ b/openbsd/OpenBSDProcess.c @@ -32,127 +32,152 @@ ProcessFieldData Process_fields[] = { .name = "", .title = NULL, .description = NULL, - .flags = 0, }, + .flags = 0, + }, [PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", - .flags = 0, }, + .flags = 0, + }, [COMM] = { .name = "Command", .title = "Command ", .description = "Command line", - .flags = 0, }, + .flags = 0, + }, [STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping, R running, D disk, Z zombie, T traced, W paging)", - .flags = 0, }, + .flags = 0, + }, [PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", - .flags = 0, }, + .flags = 0, + }, [PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", - .flags = 0, }, + .flags = 0, + }, [SESSION] = { .name = "SESSION", .title = " SESN ", .description = "Process's session ID", - .flags = 0, }, + .flags = 0, + }, [TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", - .flags = 0, }, + .flags = 0, + }, [TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", - .flags = 0, }, + .flags = 0, + }, [MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", - .flags = 0, }, + .flags = 0, + }, [MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", - .flags = 0, }, + .flags = 0, + }, [PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", - .flags = 0, }, + .flags = 0, + }, [NICE] = { .name = "NICE", .title = " NI ", .description = "Nice value (the higher the value, the more it lets other processes take priority)", - .flags = 0, }, + .flags = 0, + }, [STARTTIME] = { .name = "STARTTIME", .title = "START ", .description = "Time the process was started", - .flags = 0, }, + .flags = 0, + }, [PROCESSOR] = { .name = "PROCESSOR", .title = "CPU ", .description = "Id of the CPU the process last executed on", - .flags = 0, }, + .flags = 0, + }, [M_SIZE] = { .name = "M_SIZE", .title = " VIRT ", .description = "Total program size in virtual memory", - .flags = 0, }, + .flags = 0, + }, [M_RESIDENT] = { .name = "M_RESIDENT", .title = " RES ", .description = "Resident set size, size of the text and data sections, plus stack usage", - .flags = 0, }, + .flags = 0, + }, [ST_UID] = { .name = "ST_UID", .title = " UID ", .description = "User ID of the process owner", - .flags = 0, }, + .flags = 0, + }, [PERCENT_CPU] = { .name = "PERCENT_CPU", .title = "CPU% ", .description = "Percentage of the CPU time the process used in the last sampling", - .flags = 0, }, + .flags = 0, + }, [PERCENT_MEM] = { .name = "PERCENT_MEM", .title = "MEM% ", .description = "Percentage of the memory the process is using, based on resident memory size", - .flags = 0, }, + .flags = 0, + }, [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", - .flags = 0, }, + .flags = 0, + }, [TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", - .flags = 0, }, + .flags = 0, + }, [NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", - .flags = 0, }, + .flags = 0, + }, [TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", - .flags = 0, }, + .flags = 0, + }, [LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, - .flags = 0, }, + .flags = 0, + }, }; ProcessPidColumn Process_pidColumns[] = { diff --git a/openbsd/Platform.c b/openbsd/Platform.c index df6bc0cc..d9737c39 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -254,7 +254,7 @@ char* Platform_getProcessEnv(pid_t pid) { return NULL; if ((kproc = kvm_getprocs(kt, KERN_PROC_PID, pid, - sizeof(struct kinfo_proc), &count)) == NULL) {\ + sizeof(struct kinfo_proc), &count)) == NULL) { (void) kvm_close(kt); return NULL; } @@ -278,10 +278,10 @@ char* Platform_getProcessEnv(pid_t pid) { } if (size < 2 || env[size - 1] || env[size - 2]) { - if (size + 2 < capacity) - env = xRealloc(env, capacity + 2); - env[size] = 0; - env[size+1] = 0; + if (size + 2 < capacity) + env = xRealloc(env, capacity + 2); + env[size] = 0; + env[size + 1] = 0; } (void) kvm_close(kt); diff --git a/solaris/Platform.c b/solaris/Platform.c index 87247969..be2d25ed 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -172,10 +172,10 @@ double Platform_setCPUValues(Meter* this, int cpu) { const CPUData* cpuData = NULL; if (cpus == 1) { - // single CPU box has everything in spl->cpus[0] - cpuData = &(spl->cpus[0]); + // single CPU box has everything in spl->cpus[0] + cpuData = &(spl->cpus[0]); } else { - cpuData = &(spl->cpus[cpu]); + cpuData = &(spl->cpus[cpu]); } double percent; diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index e219d1ee..cbef6c8f 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -29,16 +29,18 @@ in the source distribution for its full text. #define MAXCMDLINE 255 char* SolarisProcessList_readZoneName(kstat_ctl_t* kd, SolarisProcess* sproc) { - char* zname; - if ( sproc->zoneid == 0 ) { - zname = xStrdup(GZONE); - } else if ( kd == NULL ) { - zname = xStrdup(UZONE); - } else { - kstat_t* ks = kstat_lookup( kd, "zones", sproc->zoneid, NULL ); - zname = xStrdup(ks == NULL ? UZONE : ks->ks_name); - } - return zname; + char* zname; + + if ( sproc->zoneid == 0 ) { + zname = xStrdup(GZONE); + } else if ( kd == NULL ) { + zname = xStrdup(UZONE); + } else { + kstat_t* ks = kstat_lookup( kd, "zones", sproc->zoneid, NULL ); + zname = xStrdup(ks == NULL ? UZONE : ks->ks_name); + } + + return zname; } ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId) { @@ -78,15 +80,19 @@ static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) { assert(cpus > 0); if (cpus > 1) { - // Store values for the stats loop one extra element up in the array - // to leave room for the average to be calculated afterwards - arrskip++; + // Store values for the stats loop one extra element up in the array + // to leave room for the average to be calculated afterwards + arrskip++; } // Calculate per-CPU statistics first for (int i = 0; i < cpus; i++) { - if (spl->kd != NULL) { cpuinfo = kstat_lookup(spl->kd,"cpu",i,"sys"); } - if (cpuinfo != NULL) { kchain = kstat_read(spl->kd,cpuinfo,NULL); } + if (spl->kd != NULL) { + cpuinfo = kstat_lookup(spl->kd, "cpu", i, "sys"); + } + if (cpuinfo != NULL) { + kchain = kstat_read(spl->kd, cpuinfo, NULL); + } if (kchain != -1 ) { idletime = kstat_data_lookup(cpuinfo,"cpu_nsec_idle"); intrtime = kstat_data_lookup(cpuinfo,"cpu_nsec_intr"); @@ -170,7 +176,7 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { // Not really "buffers" but the best Solaris analogue that I can find to // "memory in use but not by programs or the kernel itself" pl->buffersMem = (totalmem_pgs->value.ui64 - pages->value.ui64) * CRT_pageSizeKB; - } else { + } else { // Fall back to basic sysconf if kstat isn't working pl->totalMem = sysconf(_SC_PHYS_PAGES) * CRT_pageSize; pl->buffersMem = 0; @@ -180,8 +186,12 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { // Part 2 - swap nswap = swapctl(SC_GETNSWP, NULL); - if (nswap > 0) { sl = xMalloc((nswap * sizeof(swapent_t)) + sizeof(int)); } - if (sl != NULL) { spathbase = xMalloc( nswap * MAXPATHLEN ); } + if (nswap > 0) { + sl = xMalloc((nswap * sizeof(swapent_t)) + sizeof(int)); + } + if (sl != NULL) { + spathbase = xMalloc( nswap * MAXPATHLEN ); + } if (spathbase != NULL) { spath = spathbase; swapdev = sl->swt_ent; @@ -211,8 +221,12 @@ static inline void SolarisProcessList_scanZfsArcstats(ProcessList* pl) { int ksrphyserr = -1; kstat_named_t *cur_kstat = NULL; - if (spl->kd != NULL) { arcstats = kstat_lookup(spl->kd, "zfs", 0, "arcstats"); } - if (arcstats != NULL) { ksrphyserr = kstat_read(spl->kd, arcstats, NULL); } + if (spl->kd != NULL) { + arcstats = kstat_lookup(spl->kd, "zfs", 0, "arcstats"); + } + if (arcstats != NULL) { + ksrphyserr = kstat_read(spl->kd, arcstats, NULL); + } if (ksrphyserr != -1) { cur_kstat = kstat_data_lookup( arcstats, "size" ); spl->zfs.size = cur_kstat->value.ui64 / 1024; diff --git a/unsupported/UnsupportedProcessList.c b/unsupported/UnsupportedProcessList.c index 33dd9fe8..24668b69 100644 --- a/unsupported/UnsupportedProcessList.c +++ b/unsupported/UnsupportedProcessList.c @@ -30,43 +30,43 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { if (pauseProcessUpdate) return; - bool preExisting = true; - Process *proc; + bool preExisting = true; + Process* proc; - proc = ProcessList_getProcess(super, 1, &preExisting, UnsupportedProcess_new); + proc = ProcessList_getProcess(super, 1, &preExisting, UnsupportedProcess_new); - /* Empty values */ - proc->time = proc->time + 10; - proc->pid = 1; - proc->ppid = 1; - proc->tgid = 0; - proc->comm = ""; - proc->basenameOffset = 0; - proc->updated = true; + /* Empty values */ + proc->time = proc->time + 10; + proc->pid = 1; + proc->ppid = 1; + proc->tgid = 0; + proc->comm = ""; + proc->basenameOffset = 0; + proc->updated = true; - proc->state = 'R'; - proc->show = true; /* Reflected in proc->settings-> "hideXXX" really */ - proc->pgrp = 0; - proc->session = 0; - proc->tty_nr = 0; - proc->tpgid = 0; - proc->st_uid = 0; - proc->flags = 0; - proc->processor = 0; + proc->state = 'R'; + proc->show = true; /* Reflected in proc->settings-> "hideXXX" really */ + proc->pgrp = 0; + proc->session = 0; + proc->tty_nr = 0; + proc->tpgid = 0; + proc->st_uid = 0; + proc->flags = 0; + proc->processor = 0; - proc->percent_cpu = 2.5; - proc->percent_mem = 2.5; - proc->user = "nobody"; + proc->percent_cpu = 2.5; + proc->percent_mem = 2.5; + proc->user = "nobody"; - proc->priority = 0; - proc->nice = 0; - proc->nlwp = 1; - proc->starttime_ctime = 1433116800; // Jun 01, 2015 - Process_fillStarttimeBuffer(proc); + proc->priority = 0; + proc->nice = 0; + proc->nlwp = 1; + proc->starttime_ctime = 1433116800; // Jun 01, 2015 + Process_fillStarttimeBuffer(proc); - proc->m_size = 100; - proc->m_resident = 100; + proc->m_size = 100; + proc->m_resident = 100; - proc->minflt = 20; - proc->majflt = 20; + proc->minflt = 20; + proc->majflt = 20; } diff --git a/zfs/openzfs_sysctl.c b/zfs/openzfs_sysctl.c index 3f8f2c25..c09d48df 100644 --- a/zfs/openzfs_sysctl.c +++ b/zfs/openzfs_sysctl.c @@ -33,21 +33,24 @@ void openzfs_sysctl_init(ZfsArcStats *stats) { len = sizeof(arcSize); if (sysctlbyname("kstat.zfs.misc.arcstats.size", &arcSize, &len, NULL, 0) == 0 && arcSize != 0) { - stats->enabled = 1; - len = 5; sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len); + stats->enabled = 1; - sysctlnametomib("kstat.zfs.misc.arcstats.c_max", MIB_kstat_zfs_misc_arcstats_c_max, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.mfu_size", MIB_kstat_zfs_misc_arcstats_mfu_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.mru_size", MIB_kstat_zfs_misc_arcstats_mru_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.anon_size", MIB_kstat_zfs_misc_arcstats_anon_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.hdr_size", MIB_kstat_zfs_misc_arcstats_hdr_size, &len); - sysctlnametomib("kstat.zfs.misc.arcstats.other_size", MIB_kstat_zfs_misc_arcstats_other_size, &len); - if (sysctlnametomib("kstat.zfs.misc.arcstats.compressed_size", MIB_kstat_zfs_misc_arcstats_compressed_size, &len) == 0) { - stats->isCompressed = 1; - sysctlnametomib("kstat.zfs.misc.arcstats.uncompressed_size", MIB_kstat_zfs_misc_arcstats_uncompressed_size, &len); - } else { - stats->isCompressed = 0; - } + len = 5; + sysctlnametomib("kstat.zfs.misc.arcstats.size", MIB_kstat_zfs_misc_arcstats_size, &len); + + sysctlnametomib("kstat.zfs.misc.arcstats.c_max", MIB_kstat_zfs_misc_arcstats_c_max, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.mfu_size", MIB_kstat_zfs_misc_arcstats_mfu_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.mru_size", MIB_kstat_zfs_misc_arcstats_mru_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.anon_size", MIB_kstat_zfs_misc_arcstats_anon_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.hdr_size", MIB_kstat_zfs_misc_arcstats_hdr_size, &len); + sysctlnametomib("kstat.zfs.misc.arcstats.other_size", MIB_kstat_zfs_misc_arcstats_other_size, &len); + + if (sysctlnametomib("kstat.zfs.misc.arcstats.compressed_size", MIB_kstat_zfs_misc_arcstats_compressed_size, &len) == 0) { + stats->isCompressed = 1; + sysctlnametomib("kstat.zfs.misc.arcstats.uncompressed_size", MIB_kstat_zfs_misc_arcstats_uncompressed_size, &len); + } else { + stats->isCompressed = 0; + } } else { stats->enabled = 0; } From 61e14d4bb25268593019e6df3eb02264b4ac8e0e Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 23:28:02 +0100 Subject: [PATCH 11/17] Spacing around operators --- Action.c | 12 +- Affinity.c | 4 +- AffinityPanel.c | 14 +- BatteryMeter.c | 2 +- CPUMeter.c | 14 +- CRT.c | 738 ++++++++++++------------- CRT.h | 2 +- ClockMeter.c | 2 +- ColumnsPanel.c | 2 +- DateMeter.c | 4 +- DateTimeMeter.c | 4 +- EnvScreen.c | 4 +- FunctionBar.c | 10 +- Header.c | 2 +- HostnameMeter.c | 2 +- IncSet.h | 2 +- InfoScreen.c | 17 +- MainPanel.c | 6 +- MainPanel.h | 2 +- Meter.c | 36 +- OpenFilesScreen.c | 2 +- Panel.c | 10 +- Panel.h | 2 +- Process.c | 22 +- Process.h | 2 +- ProcessList.c | 8 +- RichString.c | 2 +- RichString.h | 2 +- ScreenManager.c | 16 +- Settings.c | 6 +- TraceScreen.c | 11 +- UptimeMeter.c | 6 +- Vector.c | 14 +- Vector.h | 2 +- XUtils.c | 8 +- XUtils.h | 4 +- darwin/DarwinProcess.c | 12 +- darwin/DarwinProcess.h | 8 +- darwin/DarwinProcessList.c | 12 +- darwin/DarwinProcessList.h | 10 +- darwin/Platform.c | 26 +- darwin/Platform.h | 8 +- dragonflybsd/DragonFlyBSDProcess.c | 2 +- dragonflybsd/DragonFlyBSDProcessList.c | 16 +- dragonflybsd/DragonFlyBSDProcessList.h | 10 +- dragonflybsd/Platform.c | 12 +- dragonflybsd/Platform.h | 8 +- freebsd/FreeBSDProcess.c | 2 +- freebsd/FreeBSDProcessList.c | 16 +- freebsd/FreeBSDProcessList.h | 8 +- freebsd/Platform.c | 18 +- freebsd/Platform.h | 8 +- htop.c | 10 +- linux/Battery.c | 22 +- linux/IOPriorityPanel.c | 2 +- linux/LinuxProcess.h | 2 +- linux/LinuxProcessList.c | 94 ++-- linux/LinuxProcessList.h | 2 +- linux/Platform.c | 35 +- linux/Platform.h | 10 +- openbsd/Battery.c | 2 +- openbsd/OpenBSDProcessList.c | 12 +- openbsd/OpenBSDProcessList.h | 2 +- openbsd/Platform.c | 26 +- openbsd/Platform.h | 8 +- solaris/Platform.c | 32 +- solaris/Platform.h | 10 +- solaris/SolarisProcessList.c | 62 ++- solaris/SolarisProcessList.h | 2 +- unsupported/Platform.c | 8 +- unsupported/Platform.h | 8 +- zfs/ZfsCompressedArcMeter.c | 2 +- zfs/openzfs_sysctl.c | 22 +- zfs/openzfs_sysctl.h | 4 +- 74 files changed, 784 insertions(+), 765 deletions(-) diff --git a/Action.c b/Action.c index 303eeeaf..87901432 100644 --- a/Action.c +++ b/Action.c @@ -59,7 +59,7 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) } ScreenManager_delete(scr); Panel_move(panel, 0, y); - Panel_resize(panel, COLS, LINES-y-1); + Panel_resize(panel, COLS, LINES - y - 1); if (panelFocus == list && ch == 13) { if (followProcess) { Process* selected = (Process*)Panel_getSelected(panel); @@ -181,7 +181,7 @@ static Htop_Reaction sortBy(State* st) { static Htop_Reaction actionResize(State* st) { clear(); - Panel_resize(st->panel, COLS, LINES-(st->panel->y)-1); + Panel_resize(st->panel, COLS, LINES - (st->panel->y) - 1); return HTOP_REDRAW_BAR; } @@ -393,12 +393,12 @@ static Htop_Reaction actionTag(State* st) { return HTOP_OK; } -static Htop_Reaction actionRedraw(ATTR_UNUSED State *st) { +static Htop_Reaction actionRedraw(ATTR_UNUSED State* st) { clear(); return HTOP_REFRESH | HTOP_REDRAW_BAR; } -static Htop_Reaction actionTogglePauseProcessUpdate(State *st) { +static Htop_Reaction actionTogglePauseProcessUpdate(State* st) { st->pauseProcessUpdate = !st->pauseProcessUpdate; return HTOP_REFRESH | HTOP_REDRAW_BAR; } @@ -454,7 +454,7 @@ static Htop_Reaction actionHelp(State* st) { clear(); attrset(CRT_colors[HELP_BOLD]); - for (int i = 0; i < LINES-1; i++) + for (int i = 0; i < LINES - 1; i++) mvhline(i, 0, ' ', COLS); int line = 0; @@ -500,7 +500,7 @@ static Htop_Reaction actionHelp(State* st) { addattrstr(CRT_colors[BAR_SHADOW], " used/total"); addattrstr(CRT_colors[BAR_BORDER], "]"); attrset(CRT_colors[DEFAULT_COLOR]); - mvaddstr(line++,0, "Type and layout of header meters are configurable in the setup screen."); + mvaddstr(line++, 0, "Type and layout of header meters are configurable in the setup screen."); if (CRT_colorScheme == COLORSCHEME_MONOCHROME) { mvaddstr(line, 0, "In monochrome, meters display as different chars, in order: |#*@$%&."); } diff --git a/Affinity.c b/Affinity.c index 96591a65..bfa7ceb5 100644 --- a/Affinity.c +++ b/Affinity.c @@ -74,7 +74,7 @@ Affinity* Affinity_get(Process* proc, ProcessList* pl) { } bool Affinity_set(Process* proc, Arg arg) { - Affinity *this = arg.v; + Affinity* this = arg.v; hwloc_cpuset_t cpuset = hwloc_bitmap_alloc(); for (int i = 0; i < this->used; i++) { hwloc_bitmap_set(cpuset, this->cpus[i]); @@ -99,7 +99,7 @@ Affinity* Affinity_get(Process* proc, ProcessList* pl) { } bool Affinity_set(Process* proc, Arg arg) { - Affinity *this = arg.v; + Affinity* this = arg.v; cpu_set_t cpuset; CPU_ZERO(&cpuset); for (int i = 0; i < this->used; i++) { diff --git a/AffinityPanel.c b/AffinityPanel.c index e184d64b..85094b4c 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -35,7 +35,7 @@ typedef struct MaskItem_ { char* indent; /* used also as an condition whether this is a tree node */ int value; /* tri-state: 0 - off, 1 - some set, 2 - all set */ int sub_tree; /* tri-state: 0 - no sub-tree, 1 - open sub-tree, 2 - closed sub-tree */ - Vector *children; + Vector* children; #ifdef HAVE_LIBHWLOC bool ownCpuset; hwloc_bitmap_t cpuset; @@ -123,11 +123,11 @@ typedef struct AffinityPanel_ { Panel super; ProcessList* pl; bool topoView; - Vector *cpuids; + Vector* cpuids; unsigned width; #ifdef HAVE_LIBHWLOC - MaskItem *topoRoot; + MaskItem* topoRoot; hwloc_const_cpuset_t allCpuset; hwloc_bitmap_t workCpuset; #endif @@ -262,7 +262,7 @@ static HandlerResult AffinityPanel_eventHandler(Panel* super, int ch) { #ifdef HAVE_LIBHWLOC -static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, unsigned indent, MaskItem *parent) { +static MaskItem* AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, unsigned indent, MaskItem* parent) { const char* type_name = hwloc_obj_type_string(obj->type); const char* index_prefix = "#"; unsigned depth = obj->depth; @@ -294,7 +294,7 @@ static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u xSnprintf(buf, 64, "%s %s%u", type_name, index_prefix, index); - MaskItem *item = MaskItem_newMask(buf, indent_buf, obj->complete_cpuset, false); + MaskItem* item = MaskItem_newMask(buf, indent_buf, obj->complete_cpuset, false); if (parent) Vector_add(parent->children, item); @@ -316,8 +316,8 @@ static MaskItem *AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u return item; } -static MaskItem *AffinityPanel_buildTopology(AffinityPanel* this, hwloc_obj_t obj, unsigned indent, MaskItem *parent) { - MaskItem *item = AffinityPanel_addObject(this, obj, indent, parent); +static MaskItem* AffinityPanel_buildTopology(AffinityPanel* this, hwloc_obj_t obj, unsigned indent, MaskItem* parent) { + MaskItem* item = AffinityPanel_addObject(this, obj, indent, parent); if (obj->next_sibling) { indent |= (1u << obj->depth); } else { diff --git a/BatteryMeter.c b/BatteryMeter.c index c91ae997..ac126cea 100644 --- a/BatteryMeter.c +++ b/BatteryMeter.c @@ -21,7 +21,7 @@ static const int BatteryMeter_attributes[] = { BATTERY }; -static void BatteryMeter_updateValues(Meter * this, char *buffer, int len) { +static void BatteryMeter_updateValues(Meter* this, char* buffer, int len) { ACPresence isOnAC; double percent; diff --git a/CPUMeter.c b/CPUMeter.c index 4997f6f8..b1bb8f45 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -149,7 +149,7 @@ static void AllCPUsMeter_getRange(Meter* this, int* start, int* count) { } } -static void CPUMeterCommonInit(Meter *this, int ncol) { +static void CPUMeterCommonInit(Meter* this, int ncol) { int cpus = this->pl->cpuCount; CPUMeterData* data = this->meterData; if (!data) { @@ -162,13 +162,13 @@ static void CPUMeterCommonInit(Meter *this, int ncol) { AllCPUsMeter_getRange(this, &start, &count); for (int i = 0; i < count; i++) { if (!meters[i]) - meters[i] = Meter_new(this->pl, start+i+1, (const MeterClass*) Class(CPUMeter)); + meters[i] = Meter_new(this->pl, start + i + 1, (const MeterClass*) Class(CPUMeter)); Meter_init(meters[i]); } if (this->mode == 0) this->mode = BAR_METERMODE; int h = Meter_modes[this->mode]->h; - this->h = h * ((count + ncol - 1)/ ncol); + this->h = h * ((count + ncol - 1) / ncol); } static void CPUMeterCommonUpdateMode(Meter* this, int mode, int ncol) { @@ -181,7 +181,7 @@ static void CPUMeterCommonUpdateMode(Meter* this, int mode, int ncol) { for (int i = 0; i < count; i++) { Meter_setMode(meters[i], mode); } - this->h = h * ((count + ncol - 1)/ ncol); + this->h = h * ((count + ncol - 1) / ncol); } static void AllCPUsMeter_done(Meter* this) { @@ -232,11 +232,11 @@ static void CPUMeterCommonDraw(Meter* this, int x, int y, int w, int ncol) { Meter** meters = data->meters; int start, count; AllCPUsMeter_getRange(this, &start, &count); - int colwidth = (w-ncol)/ncol + 1; + int colwidth = (w - ncol) / ncol + 1; int diff = (w - (colwidth * ncol)); int nrows = (count + ncol - 1) / ncol; - for (int i = 0; i < count; i++){ - int d = (i/nrows) > diff ? diff : (i / nrows) ; // dynamic spacer + for (int i = 0; i < count; i++) { + int d = (i / nrows) > diff ? diff : (i / nrows); // dynamic spacer int xpos = x + ((i / nrows) * colwidth) + d; int ypos = y + ((i % nrows) * meters[0]->h); meters[i]->draw(meters[i], xpos, ypos, colwidth); diff --git a/CRT.c b/CRT.c index d91d0d79..38ba9da3 100644 --- a/CRT.c +++ b/CRT.c @@ -42,7 +42,7 @@ in the source distribution for its full text. #define ColorPairGrayBlack ColorPair(Magenta,Magenta) #define ColorIndexGrayBlack ColorIndex(Magenta,Magenta) -static const char *const CRT_treeStrAscii[TREE_STR_COUNT] = { +static const char* const CRT_treeStrAscii[TREE_STR_COUNT] = { "-", // TREE_STR_HORZ "|", // TREE_STR_VERT "`", // TREE_STR_RTEE @@ -54,7 +54,7 @@ static const char *const CRT_treeStrAscii[TREE_STR_COUNT] = { #ifdef HAVE_LIBNCURSESW -static const char *const CRT_treeStrUtf8[TREE_STR_COUNT] = { +static const char* const CRT_treeStrUtf8[TREE_STR_COUNT] = { "\xe2\x94\x80", // TREE_STR_HORZ ─ "\xe2\x94\x82", // TREE_STR_VERT │ "\xe2\x94\x9c", // TREE_STR_RTEE ├ @@ -70,7 +70,7 @@ bool CRT_utf8 = false; #endif -const char *const *CRT_treeStr = CRT_treeStrAscii; +const char* const* CRT_treeStr = CRT_treeStrAscii; int CRT_delay; @@ -78,82 +78,82 @@ const int* CRT_colors; int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [COLORSCHEME_DEFAULT] = { - [RESET_COLOR] = ColorPair(White,Black), - [DEFAULT_COLOR] = ColorPair(White,Black), - [FUNCTION_BAR] = ColorPair(Black,Cyan), - [FUNCTION_KEY] = ColorPair(White,Black), - [PANEL_HEADER_FOCUS] = ColorPair(Black,Green), - [PANEL_HEADER_UNFOCUS] = ColorPair(Black,Green), - [PANEL_SELECTION_FOCUS] = ColorPair(Black,Cyan), - [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), - [PANEL_SELECTION_UNFOCUS] = ColorPair(Black,White), - [FAILED_SEARCH] = ColorPair(Red,Cyan), - [PAUSED] = A_BOLD | ColorPair(Yellow,Cyan), - [UPTIME] = A_BOLD | ColorPair(Cyan,Black), - [BATTERY] = A_BOLD | ColorPair(Cyan,Black), - [LARGE_NUMBER] = A_BOLD | ColorPair(Red,Black), - [METER_TEXT] = ColorPair(Cyan,Black), - [METER_VALUE] = A_BOLD | ColorPair(Cyan,Black), - [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,Black), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White,Black), - [METER_VALUE_IOREAD] = ColorPair(Green,Black), - [METER_VALUE_IOWRITE] = ColorPair(Blue,Black), - [LED_COLOR] = ColorPair(Green,Black), - [TASKS_RUNNING] = A_BOLD | ColorPair(Green,Black), + [RESET_COLOR] = ColorPair(White, Black), + [DEFAULT_COLOR] = ColorPair(White, Black), + [FUNCTION_BAR] = ColorPair(Black, Cyan), + [FUNCTION_KEY] = ColorPair(White, Black), + [PANEL_HEADER_FOCUS] = ColorPair(Black, Green), + [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Green), + [PANEL_SELECTION_FOCUS] = ColorPair(Black, Cyan), + [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), + [PANEL_SELECTION_UNFOCUS] = ColorPair(Black, White), + [FAILED_SEARCH] = ColorPair(Red, Cyan), + [PAUSED] = A_BOLD | ColorPair(Yellow, Cyan), + [UPTIME] = A_BOLD | ColorPair(Cyan, Black), + [BATTERY] = A_BOLD | ColorPair(Cyan, Black), + [LARGE_NUMBER] = A_BOLD | ColorPair(Red, Black), + [METER_TEXT] = ColorPair(Cyan, Black), + [METER_VALUE] = A_BOLD | ColorPair(Cyan, Black), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Black), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White, Black), + [METER_VALUE_IOREAD] = ColorPair(Green, Black), + [METER_VALUE_IOWRITE] = ColorPair(Blue, Black), + [LED_COLOR] = ColorPair(Green, Black), + [TASKS_RUNNING] = A_BOLD | ColorPair(Green, Black), [PROCESS] = A_NORMAL, [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, - [PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Black), - [PROCESS_MEGABYTES] = ColorPair(Cyan,Black), - [PROCESS_GIGABYTES] = ColorPair(Green,Black), - [PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan,Black), - [PROCESS_TREE] = ColorPair(Cyan,Black), - [PROCESS_R_STATE] = ColorPair(Green,Black), - [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,Black), - [PROCESS_HIGH_PRIORITY] = ColorPair(Red,Black), - [PROCESS_LOW_PRIORITY] = ColorPair(Green,Black), - [PROCESS_THREAD] = ColorPair(Green,Black), - [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green,Black), + [PROCESS_TAG] = A_BOLD | ColorPair(Yellow, Black), + [PROCESS_MEGABYTES] = ColorPair(Cyan, Black), + [PROCESS_GIGABYTES] = ColorPair(Green, Black), + [PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan, Black), + [PROCESS_TREE] = ColorPair(Cyan, Black), + [PROCESS_R_STATE] = ColorPair(Green, Black), + [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black), + [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black), + [PROCESS_LOW_PRIORITY] = ColorPair(Green, Black), + [PROCESS_THREAD] = ColorPair(Green, Black), + [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green, Black), [BAR_BORDER] = A_BOLD, [BAR_SHADOW] = A_BOLD | ColorPairGrayBlack, - [SWAP] = ColorPair(Red,Black), - [GRAPH_1] = A_BOLD | ColorPair(Cyan,Black), - [GRAPH_2] = ColorPair(Cyan,Black), - [MEMORY_USED] = ColorPair(Green,Black), - [MEMORY_BUFFERS] = ColorPair(Blue,Black), - [MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Blue,Black), - [MEMORY_CACHE] = ColorPair(Yellow,Black), - [LOAD_AVERAGE_FIFTEEN] = ColorPair(Cyan,Black), - [LOAD_AVERAGE_FIVE] = A_BOLD | ColorPair(Cyan,Black), - [LOAD_AVERAGE_ONE] = A_BOLD | ColorPair(White,Black), + [SWAP] = ColorPair(Red, Black), + [GRAPH_1] = A_BOLD | ColorPair(Cyan, Black), + [GRAPH_2] = ColorPair(Cyan, Black), + [MEMORY_USED] = ColorPair(Green, Black), + [MEMORY_BUFFERS] = ColorPair(Blue, Black), + [MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Blue, Black), + [MEMORY_CACHE] = ColorPair(Yellow, Black), + [LOAD_AVERAGE_FIFTEEN] = ColorPair(Cyan, Black), + [LOAD_AVERAGE_FIVE] = A_BOLD | ColorPair(Cyan, Black), + [LOAD_AVERAGE_ONE] = A_BOLD | ColorPair(White, Black), [LOAD] = A_BOLD, - [HELP_BOLD] = A_BOLD | ColorPair(Cyan,Black), + [HELP_BOLD] = A_BOLD | ColorPair(Cyan, Black), [CLOCK] = A_BOLD, [DATE] = A_BOLD, [DATETIME] = A_BOLD, - [CHECK_BOX] = ColorPair(Cyan,Black), + [CHECK_BOX] = ColorPair(Cyan, Black), [CHECK_MARK] = A_BOLD, [CHECK_TEXT] = A_NORMAL, [HOSTNAME] = A_BOLD, - [CPU_NICE] = ColorPair(Blue,Black), - [CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue,Black), - [CPU_NORMAL] = ColorPair(Green,Black), - [CPU_SYSTEM] = ColorPair(Red,Black), + [CPU_NICE] = ColorPair(Blue, Black), + [CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue, Black), + [CPU_NORMAL] = ColorPair(Green, Black), + [CPU_SYSTEM] = ColorPair(Red, Black), [CPU_IOWAIT] = A_BOLD | ColorPairGrayBlack, - [CPU_IRQ] = ColorPair(Yellow,Black), - [CPU_SOFTIRQ] = ColorPair(Magenta,Black), - [CPU_STEAL] = ColorPair(Cyan,Black), - [CPU_GUEST] = ColorPair(Cyan,Black), - [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Cyan,Black), - [PRESSURE_STALL_SIXTY] = A_BOLD | ColorPair(Cyan,Black), - [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White,Black), - [ZFS_MFU] = ColorPair(Blue,Black), - [ZFS_MRU] = ColorPair(Yellow,Black), - [ZFS_ANON] = ColorPair(Magenta,Black), - [ZFS_HEADER] = ColorPair(Cyan,Black), - [ZFS_OTHER] = ColorPair(Magenta,Black), - [ZFS_COMPRESSED] = ColorPair(Blue,Black), - [ZFS_RATIO] = ColorPair(Magenta,Black), - [ZRAM] = ColorPair(Yellow,Black), + [CPU_IRQ] = ColorPair(Yellow, Black), + [CPU_SOFTIRQ] = ColorPair(Magenta, Black), + [CPU_STEAL] = ColorPair(Cyan, Black), + [CPU_GUEST] = ColorPair(Cyan, Black), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Cyan, Black), + [PRESSURE_STALL_SIXTY] = A_BOLD | ColorPair(Cyan, Black), + [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White, Black), + [ZFS_MFU] = ColorPair(Blue, Black), + [ZFS_MRU] = ColorPair(Yellow, Black), + [ZFS_ANON] = ColorPair(Magenta, Black), + [ZFS_HEADER] = ColorPair(Cyan, Black), + [ZFS_OTHER] = ColorPair(Magenta, Black), + [ZFS_COMPRESSED] = ColorPair(Blue, Black), + [ZFS_RATIO] = ColorPair(Magenta, Black), + [ZRAM] = ColorPair(Yellow, Black), }, [COLORSCHEME_MONOCHROME] = { [RESET_COLOR] = A_NORMAL, @@ -234,314 +234,314 @@ int CRT_colorSchemes[LAST_COLORSCHEME][LAST_COLORELEMENT] = { [ZRAM] = A_NORMAL, }, [COLORSCHEME_BLACKONWHITE] = { - [RESET_COLOR] = ColorPair(Black,White), - [DEFAULT_COLOR] = ColorPair(Black,White), - [FUNCTION_BAR] = ColorPair(Black,Cyan), - [FUNCTION_KEY] = ColorPair(Black,White), - [PANEL_HEADER_FOCUS] = ColorPair(Black,Green), - [PANEL_HEADER_UNFOCUS] = ColorPair(Black,Green), - [PANEL_SELECTION_FOCUS] = ColorPair(Black,Cyan), - [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), - [PANEL_SELECTION_UNFOCUS] = ColorPair(Blue,White), - [FAILED_SEARCH] = ColorPair(Red,Cyan), - [PAUSED] = A_BOLD | ColorPair(Yellow,Cyan), - [UPTIME] = ColorPair(Yellow,White), - [BATTERY] = ColorPair(Yellow,White), - [LARGE_NUMBER] = ColorPair(Red,White), - [METER_TEXT] = ColorPair(Blue,White), - [METER_VALUE] = ColorPair(Black,White), - [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,White), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow,White), - [METER_VALUE_IOREAD] = ColorPair(Green,White), - [METER_VALUE_IOWRITE] = ColorPair(Yellow,White), - [LED_COLOR] = ColorPair(Green,White), - [TASKS_RUNNING] = ColorPair(Green,White), - [PROCESS] = ColorPair(Black,White), - [PROCESS_SHADOW] = A_BOLD | ColorPair(Black,White), - [PROCESS_TAG] = ColorPair(White,Blue), - [PROCESS_MEGABYTES] = ColorPair(Blue,White), - [PROCESS_GIGABYTES] = ColorPair(Green,White), - [PROCESS_BASENAME] = ColorPair(Blue,White), - [PROCESS_TREE] = ColorPair(Green,White), - [PROCESS_R_STATE] = ColorPair(Green,White), - [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,White), - [PROCESS_HIGH_PRIORITY] = ColorPair(Red,White), - [PROCESS_LOW_PRIORITY] = ColorPair(Green,White), - [PROCESS_THREAD] = ColorPair(Blue,White), - [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue,White), - [BAR_BORDER] = ColorPair(Blue,White), - [BAR_SHADOW] = ColorPair(Black,White), - [SWAP] = ColorPair(Red,White), - [GRAPH_1] = A_BOLD | ColorPair(Blue,White), - [GRAPH_2] = ColorPair(Blue,White), - [MEMORY_USED] = ColorPair(Green,White), - [MEMORY_BUFFERS] = ColorPair(Cyan,White), - [MEMORY_BUFFERS_TEXT] = ColorPair(Cyan,White), - [MEMORY_CACHE] = ColorPair(Yellow,White), - [LOAD_AVERAGE_FIFTEEN] = ColorPair(Black,White), - [LOAD_AVERAGE_FIVE] = ColorPair(Black,White), - [LOAD_AVERAGE_ONE] = ColorPair(Black,White), - [LOAD] = ColorPair(Black,White), - [HELP_BOLD] = ColorPair(Blue,White), - [CLOCK] = ColorPair(Black,White), - [DATE] = ColorPair(Black,White), - [DATETIME] = ColorPair(Black,White), - [CHECK_BOX] = ColorPair(Blue,White), - [CHECK_MARK] = ColorPair(Black,White), - [CHECK_TEXT] = ColorPair(Black,White), - [HOSTNAME] = ColorPair(Black,White), - [CPU_NICE] = ColorPair(Cyan,White), - [CPU_NICE_TEXT] = ColorPair(Cyan,White), - [CPU_NORMAL] = ColorPair(Green,White), - [CPU_SYSTEM] = ColorPair(Red,White), - [CPU_IOWAIT] = A_BOLD | ColorPair(Black,White), - [CPU_IRQ] = ColorPair(Blue,White), - [CPU_SOFTIRQ] = ColorPair(Blue,White), - [CPU_STEAL] = ColorPair(Cyan,White), - [CPU_GUEST] = ColorPair(Cyan,White), - [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black,White), - [PRESSURE_STALL_SIXTY] = ColorPair(Black,White), - [PRESSURE_STALL_TEN] = ColorPair(Black,White), - [ZFS_MFU] = ColorPair(Cyan,White), - [ZFS_MRU] = ColorPair(Yellow,White), - [ZFS_ANON] = ColorPair(Magenta,White), - [ZFS_HEADER] = ColorPair(Yellow,White), - [ZFS_OTHER] = ColorPair(Magenta,White), - [ZFS_COMPRESSED] = ColorPair(Cyan,White), - [ZFS_RATIO] = ColorPair(Magenta,White), - [ZRAM] = ColorPair(Yellow,White) + [RESET_COLOR] = ColorPair(Black, White), + [DEFAULT_COLOR] = ColorPair(Black, White), + [FUNCTION_BAR] = ColorPair(Black, Cyan), + [FUNCTION_KEY] = ColorPair(Black, White), + [PANEL_HEADER_FOCUS] = ColorPair(Black, Green), + [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Green), + [PANEL_SELECTION_FOCUS] = ColorPair(Black, Cyan), + [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), + [PANEL_SELECTION_UNFOCUS] = ColorPair(Blue, White), + [FAILED_SEARCH] = ColorPair(Red, Cyan), + [PAUSED] = A_BOLD | ColorPair(Yellow, Cyan), + [UPTIME] = ColorPair(Yellow, White), + [BATTERY] = ColorPair(Yellow, White), + [LARGE_NUMBER] = ColorPair(Red, White), + [METER_TEXT] = ColorPair(Blue, White), + [METER_VALUE] = ColorPair(Black, White), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, White), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow, White), + [METER_VALUE_IOREAD] = ColorPair(Green, White), + [METER_VALUE_IOWRITE] = ColorPair(Yellow, White), + [LED_COLOR] = ColorPair(Green, White), + [TASKS_RUNNING] = ColorPair(Green, White), + [PROCESS] = ColorPair(Black, White), + [PROCESS_SHADOW] = A_BOLD | ColorPair(Black, White), + [PROCESS_TAG] = ColorPair(White, Blue), + [PROCESS_MEGABYTES] = ColorPair(Blue, White), + [PROCESS_GIGABYTES] = ColorPair(Green, White), + [PROCESS_BASENAME] = ColorPair(Blue, White), + [PROCESS_TREE] = ColorPair(Green, White), + [PROCESS_R_STATE] = ColorPair(Green, White), + [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, White), + [PROCESS_HIGH_PRIORITY] = ColorPair(Red, White), + [PROCESS_LOW_PRIORITY] = ColorPair(Green, White), + [PROCESS_THREAD] = ColorPair(Blue, White), + [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue, White), + [BAR_BORDER] = ColorPair(Blue, White), + [BAR_SHADOW] = ColorPair(Black, White), + [SWAP] = ColorPair(Red, White), + [GRAPH_1] = A_BOLD | ColorPair(Blue, White), + [GRAPH_2] = ColorPair(Blue, White), + [MEMORY_USED] = ColorPair(Green, White), + [MEMORY_BUFFERS] = ColorPair(Cyan, White), + [MEMORY_BUFFERS_TEXT] = ColorPair(Cyan, White), + [MEMORY_CACHE] = ColorPair(Yellow, White), + [LOAD_AVERAGE_FIFTEEN] = ColorPair(Black, White), + [LOAD_AVERAGE_FIVE] = ColorPair(Black, White), + [LOAD_AVERAGE_ONE] = ColorPair(Black, White), + [LOAD] = ColorPair(Black, White), + [HELP_BOLD] = ColorPair(Blue, White), + [CLOCK] = ColorPair(Black, White), + [DATE] = ColorPair(Black, White), + [DATETIME] = ColorPair(Black, White), + [CHECK_BOX] = ColorPair(Blue, White), + [CHECK_MARK] = ColorPair(Black, White), + [CHECK_TEXT] = ColorPair(Black, White), + [HOSTNAME] = ColorPair(Black, White), + [CPU_NICE] = ColorPair(Cyan, White), + [CPU_NICE_TEXT] = ColorPair(Cyan, White), + [CPU_NORMAL] = ColorPair(Green, White), + [CPU_SYSTEM] = ColorPair(Red, White), + [CPU_IOWAIT] = A_BOLD | ColorPair(Black, White), + [CPU_IRQ] = ColorPair(Blue, White), + [CPU_SOFTIRQ] = ColorPair(Blue, White), + [CPU_STEAL] = ColorPair(Cyan, White), + [CPU_GUEST] = ColorPair(Cyan, White), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Black, White), + [PRESSURE_STALL_SIXTY] = ColorPair(Black, White), + [PRESSURE_STALL_TEN] = ColorPair(Black, White), + [ZFS_MFU] = ColorPair(Cyan, White), + [ZFS_MRU] = ColorPair(Yellow, White), + [ZFS_ANON] = ColorPair(Magenta, White), + [ZFS_HEADER] = ColorPair(Yellow, White), + [ZFS_OTHER] = ColorPair(Magenta, White), + [ZFS_COMPRESSED] = ColorPair(Cyan, White), + [ZFS_RATIO] = ColorPair(Magenta, White), + [ZRAM] = ColorPair(Yellow, White) }, [COLORSCHEME_LIGHTTERMINAL] = { - [RESET_COLOR] = ColorPair(Blue,Black), - [DEFAULT_COLOR] = ColorPair(Blue,Black), - [FUNCTION_BAR] = ColorPair(Black,Cyan), - [FUNCTION_KEY] = ColorPair(Blue,Black), - [PANEL_HEADER_FOCUS] = ColorPair(Black,Green), - [PANEL_HEADER_UNFOCUS] = ColorPair(Black,Green), - [PANEL_SELECTION_FOCUS] = ColorPair(Black,Cyan), - [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), - [PANEL_SELECTION_UNFOCUS] = ColorPair(Blue,Black), - [FAILED_SEARCH] = ColorPair(Red,Cyan), - [PAUSED] = A_BOLD | ColorPair(Yellow,Cyan), - [UPTIME] = ColorPair(Yellow,Black), - [BATTERY] = ColorPair(Yellow,Black), - [LARGE_NUMBER] = ColorPair(Red,Black), - [METER_TEXT] = ColorPair(Blue,Black), - [METER_VALUE] = ColorPair(Blue,Black), - [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,Black), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow,Black), - [METER_VALUE_IOREAD] = ColorPair(Green,Black), - [METER_VALUE_IOWRITE] = ColorPair(Yellow,Black), - [LED_COLOR] = ColorPair(Green,Black), - [TASKS_RUNNING] = ColorPair(Green,Black), - [PROCESS] = ColorPair(Blue,Black), + [RESET_COLOR] = ColorPair(Blue, Black), + [DEFAULT_COLOR] = ColorPair(Blue, Black), + [FUNCTION_BAR] = ColorPair(Black, Cyan), + [FUNCTION_KEY] = ColorPair(Blue, Black), + [PANEL_HEADER_FOCUS] = ColorPair(Black, Green), + [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Green), + [PANEL_SELECTION_FOCUS] = ColorPair(Black, Cyan), + [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), + [PANEL_SELECTION_UNFOCUS] = ColorPair(Blue, Black), + [FAILED_SEARCH] = ColorPair(Red, Cyan), + [PAUSED] = A_BOLD | ColorPair(Yellow, Cyan), + [UPTIME] = ColorPair(Yellow, Black), + [BATTERY] = ColorPair(Yellow, Black), + [LARGE_NUMBER] = ColorPair(Red, Black), + [METER_TEXT] = ColorPair(Blue, Black), + [METER_VALUE] = ColorPair(Blue, Black), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Black), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow, Black), + [METER_VALUE_IOREAD] = ColorPair(Green, Black), + [METER_VALUE_IOWRITE] = ColorPair(Yellow, Black), + [LED_COLOR] = ColorPair(Green, Black), + [TASKS_RUNNING] = ColorPair(Green, Black), + [PROCESS] = ColorPair(Blue, Black), [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, - [PROCESS_TAG] = ColorPair(Yellow,Blue), - [PROCESS_MEGABYTES] = ColorPair(Blue,Black), - [PROCESS_GIGABYTES] = ColorPair(Green,Black), - [PROCESS_BASENAME] = ColorPair(Green,Black), - [PROCESS_TREE] = ColorPair(Blue,Black), - [PROCESS_R_STATE] = ColorPair(Green,Black), - [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,Black), - [PROCESS_HIGH_PRIORITY] = ColorPair(Red,Black), - [PROCESS_LOW_PRIORITY] = ColorPair(Green,Black), - [PROCESS_THREAD] = ColorPair(Blue,Black), - [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue,Black), - [BAR_BORDER] = ColorPair(Blue,Black), + [PROCESS_TAG] = ColorPair(Yellow, Blue), + [PROCESS_MEGABYTES] = ColorPair(Blue, Black), + [PROCESS_GIGABYTES] = ColorPair(Green, Black), + [PROCESS_BASENAME] = ColorPair(Green, Black), + [PROCESS_TREE] = ColorPair(Blue, Black), + [PROCESS_R_STATE] = ColorPair(Green, Black), + [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black), + [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black), + [PROCESS_LOW_PRIORITY] = ColorPair(Green, Black), + [PROCESS_THREAD] = ColorPair(Blue, Black), + [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue, Black), + [BAR_BORDER] = ColorPair(Blue, Black), [BAR_SHADOW] = ColorPairGrayBlack, - [SWAP] = ColorPair(Red,Black), - [GRAPH_1] = A_BOLD | ColorPair(Cyan,Black), - [GRAPH_2] = ColorPair(Cyan,Black), - [MEMORY_USED] = ColorPair(Green,Black), - [MEMORY_BUFFERS] = ColorPair(Cyan,Black), - [MEMORY_BUFFERS_TEXT] = ColorPair(Cyan,Black), - [MEMORY_CACHE] = ColorPair(Yellow,Black), - [LOAD_AVERAGE_FIFTEEN] = ColorPair(Blue,Black), - [LOAD_AVERAGE_FIVE] = ColorPair(Blue,Black), - [LOAD_AVERAGE_ONE] = ColorPair(Yellow,Black), - [LOAD] = ColorPair(Yellow,Black), - [HELP_BOLD] = ColorPair(Blue,Black), - [CLOCK] = ColorPair(Yellow,Black), - [DATE] = ColorPair(White,Black), - [DATETIME] = ColorPair(White,Black), - [CHECK_BOX] = ColorPair(Blue,Black), - [CHECK_MARK] = ColorPair(Blue,Black), - [CHECK_TEXT] = ColorPair(Blue,Black), - [HOSTNAME] = ColorPair(Yellow,Black), - [CPU_NICE] = ColorPair(Cyan,Black), - [CPU_NICE_TEXT] = ColorPair(Cyan,Black), - [CPU_NORMAL] = ColorPair(Green,Black), - [CPU_SYSTEM] = ColorPair(Red,Black), - [CPU_IOWAIT] = A_BOLD | ColorPair(Blue,Black), - [CPU_IRQ] = A_BOLD | ColorPair(Blue,Black), - [CPU_SOFTIRQ] = ColorPair(Blue,Black), - [CPU_STEAL] = ColorPair(Blue,Black), - [CPU_GUEST] = ColorPair(Blue,Black), - [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Blue,Black), - [PRESSURE_STALL_SIXTY] = ColorPair(Blue,Black), - [PRESSURE_STALL_TEN] = ColorPair(Blue,Black), - [ZFS_MFU] = ColorPair(Cyan,Black), - [ZFS_MRU] = ColorPair(Yellow,Black), - [ZFS_ANON] = A_BOLD | ColorPair(Magenta,Black), - [ZFS_HEADER] = ColorPair(Blue,Black), - [ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Black), - [ZFS_COMPRESSED] = ColorPair(Cyan,Black), - [ZFS_RATIO] = A_BOLD | ColorPair(Magenta,Black), - [ZRAM] = ColorPair(Yellow,Black), + [SWAP] = ColorPair(Red, Black), + [GRAPH_1] = A_BOLD | ColorPair(Cyan, Black), + [GRAPH_2] = ColorPair(Cyan, Black), + [MEMORY_USED] = ColorPair(Green, Black), + [MEMORY_BUFFERS] = ColorPair(Cyan, Black), + [MEMORY_BUFFERS_TEXT] = ColorPair(Cyan, Black), + [MEMORY_CACHE] = ColorPair(Yellow, Black), + [LOAD_AVERAGE_FIFTEEN] = ColorPair(Blue, Black), + [LOAD_AVERAGE_FIVE] = ColorPair(Blue, Black), + [LOAD_AVERAGE_ONE] = ColorPair(Yellow, Black), + [LOAD] = ColorPair(Yellow, Black), + [HELP_BOLD] = ColorPair(Blue, Black), + [CLOCK] = ColorPair(Yellow, Black), + [DATE] = ColorPair(White, Black), + [DATETIME] = ColorPair(White, Black), + [CHECK_BOX] = ColorPair(Blue, Black), + [CHECK_MARK] = ColorPair(Blue, Black), + [CHECK_TEXT] = ColorPair(Blue, Black), + [HOSTNAME] = ColorPair(Yellow, Black), + [CPU_NICE] = ColorPair(Cyan, Black), + [CPU_NICE_TEXT] = ColorPair(Cyan, Black), + [CPU_NORMAL] = ColorPair(Green, Black), + [CPU_SYSTEM] = ColorPair(Red, Black), + [CPU_IOWAIT] = A_BOLD | ColorPair(Blue, Black), + [CPU_IRQ] = A_BOLD | ColorPair(Blue, Black), + [CPU_SOFTIRQ] = ColorPair(Blue, Black), + [CPU_STEAL] = ColorPair(Blue, Black), + [CPU_GUEST] = ColorPair(Blue, Black), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Blue, Black), + [PRESSURE_STALL_SIXTY] = ColorPair(Blue, Black), + [PRESSURE_STALL_TEN] = ColorPair(Blue, Black), + [ZFS_MFU] = ColorPair(Cyan, Black), + [ZFS_MRU] = ColorPair(Yellow, Black), + [ZFS_ANON] = A_BOLD | ColorPair(Magenta, Black), + [ZFS_HEADER] = ColorPair(Blue, Black), + [ZFS_OTHER] = A_BOLD | ColorPair(Magenta, Black), + [ZFS_COMPRESSED] = ColorPair(Cyan, Black), + [ZFS_RATIO] = A_BOLD | ColorPair(Magenta, Black), + [ZRAM] = ColorPair(Yellow, Black), }, [COLORSCHEME_MIDNIGHT] = { - [RESET_COLOR] = ColorPair(White,Blue), - [DEFAULT_COLOR] = ColorPair(White,Blue), - [FUNCTION_BAR] = ColorPair(Black,Cyan), + [RESET_COLOR] = ColorPair(White, Blue), + [DEFAULT_COLOR] = ColorPair(White, Blue), + [FUNCTION_BAR] = ColorPair(Black, Cyan), [FUNCTION_KEY] = A_NORMAL, - [PANEL_HEADER_FOCUS] = ColorPair(Black,Cyan), - [PANEL_HEADER_UNFOCUS] = ColorPair(Black,Cyan), - [PANEL_SELECTION_FOCUS] = ColorPair(Black,White), - [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), - [PANEL_SELECTION_UNFOCUS] = A_BOLD | ColorPair(Yellow,Blue), - [FAILED_SEARCH] = ColorPair(Red,Cyan), - [PAUSED] = A_BOLD | ColorPair(Yellow,Cyan), - [UPTIME] = A_BOLD | ColorPair(Yellow,Blue), - [BATTERY] = A_BOLD | ColorPair(Yellow,Blue), - [LARGE_NUMBER] = A_BOLD | ColorPair(Red,Blue), - [METER_TEXT] = ColorPair(Cyan,Blue), - [METER_VALUE] = A_BOLD | ColorPair(Cyan,Blue), - [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,Blue), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White,Blue), - [METER_VALUE_IOREAD] = ColorPair(Green,Blue), - [METER_VALUE_IOWRITE] = ColorPair(Black,Blue), - [LED_COLOR] = ColorPair(Green,Blue), - [TASKS_RUNNING] = A_BOLD | ColorPair(Green,Blue), - [PROCESS] = ColorPair(White,Blue), - [PROCESS_SHADOW] = A_BOLD | ColorPair(Black,Blue), - [PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Blue), - [PROCESS_MEGABYTES] = ColorPair(Cyan,Blue), - [PROCESS_GIGABYTES] = ColorPair(Green,Blue), - [PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan,Blue), - [PROCESS_TREE] = ColorPair(Cyan,Blue), - [PROCESS_R_STATE] = ColorPair(Green,Blue), - [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,Blue), - [PROCESS_HIGH_PRIORITY] = ColorPair(Red,Blue), - [PROCESS_LOW_PRIORITY] = ColorPair(Green,Blue), - [PROCESS_THREAD] = ColorPair(Green,Blue), - [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green,Blue), - [BAR_BORDER] = A_BOLD | ColorPair(Yellow,Blue), - [BAR_SHADOW] = ColorPair(Cyan,Blue), - [SWAP] = ColorPair(Red,Blue), - [GRAPH_1] = A_BOLD | ColorPair(Cyan,Blue), - [GRAPH_2] = ColorPair(Cyan,Blue), - [MEMORY_USED] = A_BOLD | ColorPair(Green,Blue), - [MEMORY_BUFFERS] = A_BOLD | ColorPair(Cyan,Blue), - [MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Cyan,Blue), - [MEMORY_CACHE] = A_BOLD | ColorPair(Yellow,Blue), - [LOAD_AVERAGE_FIFTEEN] = A_BOLD | ColorPair(Black,Blue), - [LOAD_AVERAGE_FIVE] = A_NORMAL | ColorPair(White,Blue), - [LOAD_AVERAGE_ONE] = A_BOLD | ColorPair(White,Blue), - [LOAD] = A_BOLD | ColorPair(White,Blue), - [HELP_BOLD] = A_BOLD | ColorPair(Cyan,Blue), - [CLOCK] = ColorPair(White,Blue), - [DATE] = ColorPair(White,Blue), - [DATETIME] = ColorPair(White,Blue), - [CHECK_BOX] = ColorPair(Cyan,Blue), - [CHECK_MARK] = A_BOLD | ColorPair(White,Blue), - [CHECK_TEXT] = A_NORMAL | ColorPair(White,Blue), - [HOSTNAME] = ColorPair(White,Blue), - [CPU_NICE] = A_BOLD | ColorPair(Cyan,Blue), - [CPU_NICE_TEXT] = A_BOLD | ColorPair(Cyan,Blue), - [CPU_NORMAL] = A_BOLD | ColorPair(Green,Blue), - [CPU_SYSTEM] = A_BOLD | ColorPair(Red,Blue), - [CPU_IOWAIT] = A_BOLD | ColorPair(Black,Blue), - [CPU_IRQ] = A_BOLD | ColorPair(Black,Blue), - [CPU_SOFTIRQ] = ColorPair(Black,Blue), - [CPU_STEAL] = ColorPair(White,Blue), - [CPU_GUEST] = ColorPair(White,Blue), - [PRESSURE_STALL_THREEHUNDRED] = A_BOLD | ColorPair(Black,Blue), - [PRESSURE_STALL_SIXTY] = A_NORMAL | ColorPair(White,Blue), - [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White,Blue), - [ZFS_MFU] = A_BOLD | ColorPair(White,Blue), - [ZFS_MRU] = A_BOLD | ColorPair(Yellow,Blue), - [ZFS_ANON] = A_BOLD | ColorPair(Magenta,Blue), - [ZFS_HEADER] = A_BOLD | ColorPair(Yellow,Blue), - [ZFS_OTHER] = A_BOLD | ColorPair(Magenta,Blue), - [ZFS_COMPRESSED] = A_BOLD | ColorPair(White,Blue), - [ZFS_RATIO] = A_BOLD | ColorPair(Magenta,Blue), - [ZRAM] = A_BOLD | ColorPair(Yellow,Blue), + [PANEL_HEADER_FOCUS] = ColorPair(Black, Cyan), + [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Cyan), + [PANEL_SELECTION_FOCUS] = ColorPair(Black, White), + [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), + [PANEL_SELECTION_UNFOCUS] = A_BOLD | ColorPair(Yellow, Blue), + [FAILED_SEARCH] = ColorPair(Red, Cyan), + [PAUSED] = A_BOLD | ColorPair(Yellow, Cyan), + [UPTIME] = A_BOLD | ColorPair(Yellow, Blue), + [BATTERY] = A_BOLD | ColorPair(Yellow, Blue), + [LARGE_NUMBER] = A_BOLD | ColorPair(Red, Blue), + [METER_TEXT] = ColorPair(Cyan, Blue), + [METER_VALUE] = A_BOLD | ColorPair(Cyan, Blue), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Blue), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(White, Blue), + [METER_VALUE_IOREAD] = ColorPair(Green, Blue), + [METER_VALUE_IOWRITE] = ColorPair(Black, Blue), + [LED_COLOR] = ColorPair(Green, Blue), + [TASKS_RUNNING] = A_BOLD | ColorPair(Green, Blue), + [PROCESS] = ColorPair(White, Blue), + [PROCESS_SHADOW] = A_BOLD | ColorPair(Black, Blue), + [PROCESS_TAG] = A_BOLD | ColorPair(Yellow, Blue), + [PROCESS_MEGABYTES] = ColorPair(Cyan, Blue), + [PROCESS_GIGABYTES] = ColorPair(Green, Blue), + [PROCESS_BASENAME] = A_BOLD | ColorPair(Cyan, Blue), + [PROCESS_TREE] = ColorPair(Cyan, Blue), + [PROCESS_R_STATE] = ColorPair(Green, Blue), + [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Blue), + [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Blue), + [PROCESS_LOW_PRIORITY] = ColorPair(Green, Blue), + [PROCESS_THREAD] = ColorPair(Green, Blue), + [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Green, Blue), + [BAR_BORDER] = A_BOLD | ColorPair(Yellow, Blue), + [BAR_SHADOW] = ColorPair(Cyan, Blue), + [SWAP] = ColorPair(Red, Blue), + [GRAPH_1] = A_BOLD | ColorPair(Cyan, Blue), + [GRAPH_2] = ColorPair(Cyan, Blue), + [MEMORY_USED] = A_BOLD | ColorPair(Green, Blue), + [MEMORY_BUFFERS] = A_BOLD | ColorPair(Cyan, Blue), + [MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Cyan, Blue), + [MEMORY_CACHE] = A_BOLD | ColorPair(Yellow, Blue), + [LOAD_AVERAGE_FIFTEEN] = A_BOLD | ColorPair(Black, Blue), + [LOAD_AVERAGE_FIVE] = A_NORMAL | ColorPair(White, Blue), + [LOAD_AVERAGE_ONE] = A_BOLD | ColorPair(White, Blue), + [LOAD] = A_BOLD | ColorPair(White, Blue), + [HELP_BOLD] = A_BOLD | ColorPair(Cyan, Blue), + [CLOCK] = ColorPair(White, Blue), + [DATE] = ColorPair(White, Blue), + [DATETIME] = ColorPair(White, Blue), + [CHECK_BOX] = ColorPair(Cyan, Blue), + [CHECK_MARK] = A_BOLD | ColorPair(White, Blue), + [CHECK_TEXT] = A_NORMAL | ColorPair(White, Blue), + [HOSTNAME] = ColorPair(White, Blue), + [CPU_NICE] = A_BOLD | ColorPair(Cyan, Blue), + [CPU_NICE_TEXT] = A_BOLD | ColorPair(Cyan, Blue), + [CPU_NORMAL] = A_BOLD | ColorPair(Green, Blue), + [CPU_SYSTEM] = A_BOLD | ColorPair(Red, Blue), + [CPU_IOWAIT] = A_BOLD | ColorPair(Black, Blue), + [CPU_IRQ] = A_BOLD | ColorPair(Black, Blue), + [CPU_SOFTIRQ] = ColorPair(Black, Blue), + [CPU_STEAL] = ColorPair(White, Blue), + [CPU_GUEST] = ColorPair(White, Blue), + [PRESSURE_STALL_THREEHUNDRED] = A_BOLD | ColorPair(Black, Blue), + [PRESSURE_STALL_SIXTY] = A_NORMAL | ColorPair(White, Blue), + [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(White, Blue), + [ZFS_MFU] = A_BOLD | ColorPair(White, Blue), + [ZFS_MRU] = A_BOLD | ColorPair(Yellow, Blue), + [ZFS_ANON] = A_BOLD | ColorPair(Magenta, Blue), + [ZFS_HEADER] = A_BOLD | ColorPair(Yellow, Blue), + [ZFS_OTHER] = A_BOLD | ColorPair(Magenta, Blue), + [ZFS_COMPRESSED] = A_BOLD | ColorPair(White, Blue), + [ZFS_RATIO] = A_BOLD | ColorPair(Magenta, Blue), + [ZRAM] = A_BOLD | ColorPair(Yellow, Blue), }, [COLORSCHEME_BLACKNIGHT] = { - [RESET_COLOR] = ColorPair(Cyan,Black), - [DEFAULT_COLOR] = ColorPair(Cyan,Black), - [FUNCTION_BAR] = ColorPair(Black,Green), - [FUNCTION_KEY] = ColorPair(Cyan,Black), - [PANEL_HEADER_FOCUS] = ColorPair(Black,Green), - [PANEL_HEADER_UNFOCUS] = ColorPair(Black,Green), - [PANEL_SELECTION_FOCUS] = ColorPair(Black,Cyan), - [PANEL_SELECTION_FOLLOW] = ColorPair(Black,Yellow), - [PANEL_SELECTION_UNFOCUS] = ColorPair(Black,White), - [FAILED_SEARCH] = ColorPair(Red,Green), - [PAUSED] = A_BOLD | ColorPair(Yellow,Green), - [UPTIME] = ColorPair(Green,Black), - [BATTERY] = ColorPair(Green,Black), - [LARGE_NUMBER] = A_BOLD | ColorPair(Red,Black), - [METER_TEXT] = ColorPair(Cyan,Black), - [METER_VALUE] = ColorPair(Green,Black), - [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red,Black), - [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow,Black), - [METER_VALUE_IOREAD] = ColorPair(Green,Black), - [METER_VALUE_IOWRITE] = ColorPair(Blue,Black), - [LED_COLOR] = ColorPair(Green,Black), - [TASKS_RUNNING] = A_BOLD | ColorPair(Green,Black), - [PROCESS] = ColorPair(Cyan,Black), + [RESET_COLOR] = ColorPair(Cyan, Black), + [DEFAULT_COLOR] = ColorPair(Cyan, Black), + [FUNCTION_BAR] = ColorPair(Black, Green), + [FUNCTION_KEY] = ColorPair(Cyan, Black), + [PANEL_HEADER_FOCUS] = ColorPair(Black, Green), + [PANEL_HEADER_UNFOCUS] = ColorPair(Black, Green), + [PANEL_SELECTION_FOCUS] = ColorPair(Black, Cyan), + [PANEL_SELECTION_FOLLOW] = ColorPair(Black, Yellow), + [PANEL_SELECTION_UNFOCUS] = ColorPair(Black, White), + [FAILED_SEARCH] = ColorPair(Red, Green), + [PAUSED] = A_BOLD | ColorPair(Yellow, Green), + [UPTIME] = ColorPair(Green, Black), + [BATTERY] = ColorPair(Green, Black), + [LARGE_NUMBER] = A_BOLD | ColorPair(Red, Black), + [METER_TEXT] = ColorPair(Cyan, Black), + [METER_VALUE] = ColorPair(Green, Black), + [METER_VALUE_ERROR] = A_BOLD | ColorPair(Red, Black), + [METER_VALUE_NOTICE] = A_BOLD | ColorPair(Yellow, Black), + [METER_VALUE_IOREAD] = ColorPair(Green, Black), + [METER_VALUE_IOWRITE] = ColorPair(Blue, Black), + [LED_COLOR] = ColorPair(Green, Black), + [TASKS_RUNNING] = A_BOLD | ColorPair(Green, Black), + [PROCESS] = ColorPair(Cyan, Black), [PROCESS_SHADOW] = A_BOLD | ColorPairGrayBlack, - [PROCESS_TAG] = A_BOLD | ColorPair(Yellow,Black), - [PROCESS_MEGABYTES] = A_BOLD | ColorPair(Green,Black), - [PROCESS_GIGABYTES] = A_BOLD | ColorPair(Yellow,Black), - [PROCESS_BASENAME] = A_BOLD | ColorPair(Green,Black), - [PROCESS_TREE] = ColorPair(Cyan,Black), - [PROCESS_THREAD] = ColorPair(Green,Black), - [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue,Black), - [PROCESS_R_STATE] = ColorPair(Green,Black), - [PROCESS_D_STATE] = A_BOLD | ColorPair(Red,Black), - [PROCESS_HIGH_PRIORITY] = ColorPair(Red,Black), - [PROCESS_LOW_PRIORITY] = ColorPair(Green,Black), - [BAR_BORDER] = A_BOLD | ColorPair(Green,Black), - [BAR_SHADOW] = ColorPair(Cyan,Black), - [SWAP] = ColorPair(Red,Black), - [GRAPH_1] = A_BOLD | ColorPair(Green,Black), - [GRAPH_2] = ColorPair(Green,Black), - [MEMORY_USED] = ColorPair(Green,Black), - [MEMORY_BUFFERS] = ColorPair(Blue,Black), - [MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Blue,Black), - [MEMORY_CACHE] = ColorPair(Yellow,Black), - [LOAD_AVERAGE_FIFTEEN] = ColorPair(Green,Black), - [LOAD_AVERAGE_FIVE] = ColorPair(Green,Black), - [LOAD_AVERAGE_ONE] = A_BOLD | ColorPair(Green,Black), + [PROCESS_TAG] = A_BOLD | ColorPair(Yellow, Black), + [PROCESS_MEGABYTES] = A_BOLD | ColorPair(Green, Black), + [PROCESS_GIGABYTES] = A_BOLD | ColorPair(Yellow, Black), + [PROCESS_BASENAME] = A_BOLD | ColorPair(Green, Black), + [PROCESS_TREE] = ColorPair(Cyan, Black), + [PROCESS_THREAD] = ColorPair(Green, Black), + [PROCESS_THREAD_BASENAME] = A_BOLD | ColorPair(Blue, Black), + [PROCESS_R_STATE] = ColorPair(Green, Black), + [PROCESS_D_STATE] = A_BOLD | ColorPair(Red, Black), + [PROCESS_HIGH_PRIORITY] = ColorPair(Red, Black), + [PROCESS_LOW_PRIORITY] = ColorPair(Green, Black), + [BAR_BORDER] = A_BOLD | ColorPair(Green, Black), + [BAR_SHADOW] = ColorPair(Cyan, Black), + [SWAP] = ColorPair(Red, Black), + [GRAPH_1] = A_BOLD | ColorPair(Green, Black), + [GRAPH_2] = ColorPair(Green, Black), + [MEMORY_USED] = ColorPair(Green, Black), + [MEMORY_BUFFERS] = ColorPair(Blue, Black), + [MEMORY_BUFFERS_TEXT] = A_BOLD | ColorPair(Blue, Black), + [MEMORY_CACHE] = ColorPair(Yellow, Black), + [LOAD_AVERAGE_FIFTEEN] = ColorPair(Green, Black), + [LOAD_AVERAGE_FIVE] = ColorPair(Green, Black), + [LOAD_AVERAGE_ONE] = A_BOLD | ColorPair(Green, Black), [LOAD] = A_BOLD, - [HELP_BOLD] = A_BOLD | ColorPair(Cyan,Black), - [CLOCK] = ColorPair(Green,Black), - [CHECK_BOX] = ColorPair(Green,Black), - [CHECK_MARK] = A_BOLD | ColorPair(Green,Black), - [CHECK_TEXT] = ColorPair(Cyan,Black), - [HOSTNAME] = ColorPair(Green,Black), - [CPU_NICE] = ColorPair(Blue,Black), - [CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue,Black), - [CPU_NORMAL] = ColorPair(Green,Black), - [CPU_SYSTEM] = ColorPair(Red,Black), - [CPU_IOWAIT] = ColorPair(Yellow,Black), - [CPU_IRQ] = A_BOLD | ColorPair(Blue,Black), - [CPU_SOFTIRQ] = ColorPair(Blue,Black), - [CPU_STEAL] = ColorPair(Cyan,Black), - [CPU_GUEST] = ColorPair(Cyan,Black), - [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Green,Black), - [PRESSURE_STALL_SIXTY] = ColorPair(Green,Black), - [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(Green,Black), - [ZFS_MFU] = ColorPair(Blue,Black), - [ZFS_MRU] = ColorPair(Yellow,Black), - [ZFS_ANON] = ColorPair(Magenta,Black), - [ZFS_HEADER] = ColorPair(Yellow,Black), - [ZFS_OTHER] = ColorPair(Magenta,Black), - [ZFS_COMPRESSED] = ColorPair(Blue,Black), - [ZFS_RATIO] = ColorPair(Magenta,Black), - [ZRAM] = ColorPair(Yellow,Black), + [HELP_BOLD] = A_BOLD | ColorPair(Cyan, Black), + [CLOCK] = ColorPair(Green, Black), + [CHECK_BOX] = ColorPair(Green, Black), + [CHECK_MARK] = A_BOLD | ColorPair(Green, Black), + [CHECK_TEXT] = ColorPair(Cyan, Black), + [HOSTNAME] = ColorPair(Green, Black), + [CPU_NICE] = ColorPair(Blue, Black), + [CPU_NICE_TEXT] = A_BOLD | ColorPair(Blue, Black), + [CPU_NORMAL] = ColorPair(Green, Black), + [CPU_SYSTEM] = ColorPair(Red, Black), + [CPU_IOWAIT] = ColorPair(Yellow, Black), + [CPU_IRQ] = A_BOLD | ColorPair(Blue, Black), + [CPU_SOFTIRQ] = ColorPair(Blue, Black), + [CPU_STEAL] = ColorPair(Cyan, Black), + [CPU_GUEST] = ColorPair(Cyan, Black), + [PRESSURE_STALL_THREEHUNDRED] = ColorPair(Green, Black), + [PRESSURE_STALL_SIXTY] = ColorPair(Green, Black), + [PRESSURE_STALL_TEN] = A_BOLD | ColorPair(Green, Black), + [ZFS_MFU] = ColorPair(Blue, Black), + [ZFS_MRU] = ColorPair(Yellow, Black), + [ZFS_ANON] = ColorPair(Magenta, Black), + [ZFS_HEADER] = ColorPair(Yellow, Black), + [ZFS_OTHER] = ColorPair(Magenta, Black), + [ZFS_COMPRESSED] = ColorPair(Blue, Black), + [ZFS_RATIO] = ColorPair(Magenta, Black), + [ZRAM] = ColorPair(Yellow, Black), }, [COLORSCHEME_BROKENGRAY] = { 0 } // dynamically generated. }; @@ -610,7 +610,7 @@ void CRT_init(int delay, int colorScheme, bool allowUnicode) { for (int i = 0; i < LAST_COLORELEMENT; i++) { unsigned int color = CRT_colorSchemes[COLORSCHEME_DEFAULT][i]; - CRT_colorSchemes[COLORSCHEME_BROKENGRAY][i] = color == (A_BOLD | ColorPairGrayBlack) ? ColorPair(White,Black) : color; + CRT_colorSchemes[COLORSCHEME_BROKENGRAY][i] = color == (A_BOLD | ColorPairGrayBlack) ? ColorPair(White, Black) : color; } halfdelay(CRT_delay); @@ -649,7 +649,7 @@ void CRT_init(int delay, int colorScheme, bool allowUnicode) { struct sigaction act; sigemptyset (&act.sa_mask); - act.sa_flags = (int)SA_RESETHAND|SA_NODEFER; + act.sa_flags = (int)SA_RESETHAND | SA_NODEFER; act.sa_handler = CRT_handleSIGSEGV; sigaction (SIGSEGV, &act, &old_sig_handler[SIGSEGV]); sigaction (SIGFPE, &act, &old_sig_handler[SIGFPE]); @@ -732,11 +732,11 @@ void CRT_setColors(int colorScheme) { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { - if (ColorIndex(i,j) != ColorPairGrayBlack) { + if (ColorIndex(i, j) != ColorPairGrayBlack) { int bg = (colorScheme != COLORSCHEME_BLACKNIGHT) - ? (j==0 ? -1 : j) + ? (j == 0 ? -1 : j) : j; - init_pair(ColorIndex(i,j), i, bg); + init_pair(ColorIndex(i, j), i, bg); } } } diff --git a/CRT.h b/CRT.h index 49ed4ed0..fccf65c1 100644 --- a/CRT.h +++ b/CRT.h @@ -133,7 +133,7 @@ extern bool CRT_utf8; #endif -extern const char *const *CRT_treeStr; +extern const char* const* CRT_treeStr; extern int CRT_delay; diff --git a/ClockMeter.c b/ClockMeter.c index c6f2ab33..3cc9dd03 100644 --- a/ClockMeter.c +++ b/ClockMeter.c @@ -22,7 +22,7 @@ static const int ClockMeter_attributes[] = { static void ClockMeter_updateValues(Meter* this, char* buffer, int size) { time_t t = time(NULL); struct tm result; - struct tm *lt = localtime_r(&t, &result); + struct tm* lt = localtime_r(&t, &result); this->values[0] = lt->tm_hour * 60 + lt->tm_min; strftime(buffer, size, "%H:%M:%S", lt); } diff --git a/ColumnsPanel.c b/ColumnsPanel.c index 36127bd5..ffd4d0bb 100644 --- a/ColumnsPanel.c +++ b/ColumnsPanel.c @@ -139,7 +139,7 @@ void ColumnsPanel_update(Panel* super) { ColumnsPanel* this = (ColumnsPanel*) super; int size = Panel_size(super); this->settings->changed = true; - this->settings->fields = xRealloc(this->settings->fields, sizeof(ProcessField) * (size+1)); + this->settings->fields = xRealloc(this->settings->fields, sizeof(ProcessField) * (size + 1)); this->settings->flags = 0; for (int i = 0; i < size; i++) { int key = ((ListItem*) Panel_get(super, i))->key; diff --git a/DateMeter.c b/DateMeter.c index c1a097f6..bfe0cbf1 100644 --- a/DateMeter.c +++ b/DateMeter.c @@ -22,10 +22,10 @@ static const int DateMeter_attributes[] = { static void DateMeter_updateValues(Meter* this, char* buffer, int size) { time_t t = time(NULL); struct tm result; - struct tm *lt = localtime_r(&t, &result); + struct tm* lt = localtime_r(&t, &result); this->values[0] = lt->tm_yday; int year = lt->tm_year + 1900; - if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0)) { + if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) { this->total = 366; } else { diff --git a/DateTimeMeter.c b/DateTimeMeter.c index 74582191..ad5e81ea 100644 --- a/DateTimeMeter.c +++ b/DateTimeMeter.c @@ -22,9 +22,9 @@ static const int DateTimeMeter_attributes[] = { static void DateTimeMeter_updateValues(Meter* this, char* buffer, int size) { time_t t = time(NULL); struct tm result; - struct tm *lt = localtime_r(&t, &result); + struct tm* lt = localtime_r(&t, &result); int year = lt->tm_year + 1900; - if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0)) { + if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) { this->total = 366; } else { diff --git a/EnvScreen.c b/EnvScreen.c index cd8e0cb3..30faaaba 100644 --- a/EnvScreen.c +++ b/EnvScreen.c @@ -26,7 +26,7 @@ const InfoScreenClass EnvScreen_class = { EnvScreen* EnvScreen_new(Process* process) { EnvScreen* this = xMalloc(sizeof(EnvScreen)); Object_setClass(this, Class(EnvScreen)); - return (EnvScreen*) InfoScreen_init(&this->super, process, NULL, LINES-3, " "); + return (EnvScreen*) InfoScreen_init(&this->super, process, NULL, LINES - 3, " "); } void EnvScreen_delete(Object* this) { @@ -47,7 +47,7 @@ void EnvScreen_scan(InfoScreen* this) { char* env = Platform_getProcessEnv(this->process->pid); CRT_restorePrivileges(); if (env) { - for (char *p = env; *p; p = strrchr(p, 0)+1) + for (char* p = env; *p; p = strrchr(p, 0) + 1) InfoScreen_addLine(this, p); free(env); } diff --git a/FunctionBar.c b/FunctionBar.c index 9b454ac8..93456583 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -94,14 +94,14 @@ void FunctionBar_draw(const FunctionBar* this) { void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr, bool setCursor) { attrset(CRT_colors[FUNCTION_BAR]); - mvhline(LINES-1, 0, ' ', COLS); + mvhline(LINES - 1, 0, ' ', COLS); int x = 0; for (int i = 0; i < this->size; i++) { attrset(CRT_colors[FUNCTION_KEY]); - mvaddstr(LINES-1, x, this->keys.constKeys[i]); + mvaddstr(LINES - 1, x, this->keys.constKeys[i]); x += strlen(this->keys.constKeys[i]); attrset(CRT_colors[FUNCTION_BAR]); - mvaddstr(LINES-1, x, this->functions[i]); + mvaddstr(LINES - 1, x, this->functions[i]); x += strlen(this->functions[i]); } @@ -110,7 +110,7 @@ void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr attrset(CRT_colors[FUNCTION_BAR]); else attrset(attr); - mvaddstr(LINES-1, x, buffer); + mvaddstr(LINES - 1, x, buffer); attrset(CRT_colors[RESET_COLOR]); x += strlen(buffer); } @@ -130,7 +130,7 @@ void FunctionBar_append(const char* buffer, int attr) { attrset(CRT_colors[FUNCTION_BAR]); else attrset(attr); - mvaddstr(LINES-1, currentLen, buffer); + mvaddstr(LINES - 1, currentLen, buffer); attrset(CRT_colors[RESET_COLOR]); currentLen += strlen(buffer); diff --git a/Header.c b/Header.c index 3bb24c23..4448baa6 100644 --- a/Header.c +++ b/Header.c @@ -63,7 +63,7 @@ void Header_writeBackToSettings(const Header* this) { Vector* vec = this->columns[col]; int len = Vector_size(vec); - colSettings->names = xCalloc(len+1, sizeof(char*)); + colSettings->names = xCalloc(len + 1, sizeof(char*)); colSettings->modes = xCalloc(len, sizeof(int)); colSettings->len = len; diff --git a/HostnameMeter.c b/HostnameMeter.c index 6cf9e07e..000bc3fd 100644 --- a/HostnameMeter.c +++ b/HostnameMeter.c @@ -21,7 +21,7 @@ static const int HostnameMeter_attributes[] = { static void HostnameMeter_updateValues(Meter* this, char* buffer, int size) { (void) this; - gethostname(buffer, size-1); + gethostname(buffer, size - 1); } const MeterClass HostnameMeter_class = { diff --git a/IncSet.h b/IncSet.h index a6c1974e..b07840f7 100644 --- a/IncSet.h +++ b/IncSet.h @@ -22,7 +22,7 @@ typedef enum { } IncType; typedef struct IncMode_ { - char buffer[INCMODE_MAX+1]; + char buffer[INCMODE_MAX + 1]; int index; FunctionBar* bar; bool isFilter; diff --git a/InfoScreen.c b/InfoScreen.c index 7f4baa72..102f0ba7 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -65,21 +65,23 @@ void InfoScreen_addLine(InfoScreen* this, const char* line) { Vector_add(this->lines, (Object*) ListItem_new(line, 0)); const char* incFilter = IncSet_filter(this->inc); if (!incFilter || String_contains_i(line, incFilter)) - Panel_add(this->display, Vector_get(this->lines, Vector_size(this->lines)-1)); + Panel_add(this->display, Vector_get(this->lines, Vector_size(this->lines) - 1)); } void InfoScreen_appendLine(InfoScreen* this, const char* line) { - ListItem* last = (ListItem*)Vector_get(this->lines, Vector_size(this->lines)-1); + ListItem* last = (ListItem*)Vector_get(this->lines, Vector_size(this->lines) - 1); ListItem_append(last, line); const char* incFilter = IncSet_filter(this->inc); - if (incFilter && Panel_get(this->display, Panel_size(this->display)-1) != (Object*)last && String_contains_i(line, incFilter)) + if (incFilter && Panel_get(this->display, Panel_size(this->display) - 1) != (Object*)last && String_contains_i(line, incFilter)) Panel_add(this->display, (Object*)last); } void InfoScreen_run(InfoScreen* this) { Panel* panel = this->display; - if (As_InfoScreen(this)->scan) InfoScreen_scan(this); + if (As_InfoScreen(this)->scan) + InfoScreen_scan(this); + InfoScreen_draw(this); bool looping = true; @@ -88,7 +90,7 @@ void InfoScreen_run(InfoScreen* this) { Panel_draw(panel, true); if (this->inc->active) { - (void) move(LINES-1, CRT_cursorX); + (void) move(LINES - 1, CRT_cursorX); } set_escdelay(25); int ch = getch(); @@ -144,8 +146,9 @@ void InfoScreen_run(InfoScreen* this) { looping = false; break; case KEY_RESIZE: - Panel_resize(panel, COLS, LINES-2); - if (As_InfoScreen(this)->scan) InfoScreen_scan(this); + Panel_resize(panel, COLS, LINES - 2); + if (As_InfoScreen(this)->scan) + InfoScreen_scan(this); InfoScreen_draw(this); break; default: diff --git a/MainPanel.c b/MainPanel.c index 05a55e60..9322fe02 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -36,7 +36,7 @@ void MainPanel_updateTreeFunctions(MainPanel* this, bool mode) { void MainPanel_pidSearch(MainPanel* this, int ch) { Panel* super = (Panel*) this; - pid_t pid = ch-48 + this->pidSearch; + pid_t pid = ch - 48 + this->pidSearch; for (int i = 0; i < Panel_size(super); i++) { Process* p = (Process*) Panel_get(super, i); if (p && p->pid == pid) { @@ -153,7 +153,9 @@ bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Ar } if (!anyTagged) { Process* p = (Process*) Panel_getSelected(super); - if (p) ok = fn(p, arg) && ok; + if (p) { + ok &= fn(p, arg); + } } if (wasAnyTagged) *wasAnyTagged = anyTagged; diff --git a/MainPanel.h b/MainPanel.h index 3c555294..03a1affd 100644 --- a/MainPanel.h +++ b/MainPanel.h @@ -24,7 +24,7 @@ typedef struct MainPanel_ { Panel super; State* state; IncSet* inc; - Htop_Action *keys; + Htop_Action* keys; pid_t pidSearch; } MainPanel; diff --git a/Meter.c b/Meter.c index 0cf7ee0b..d17ba95a 100644 --- a/Meter.c +++ b/Meter.c @@ -48,7 +48,7 @@ Meter* Meter_new(const struct ProcessList_* pl, int param, const MeterClass* typ } int Meter_humanUnit(char* buffer, unsigned long int value, int size) { - const char * prefix = "KMGTPEZY"; + const char* prefix = "KMGTPEZY"; unsigned long int powi = 1; unsigned int written, powj = 1, precision = 2; @@ -199,7 +199,7 @@ static void BarMeterMode_draw(Meter* this, int x, int y, int w) { double value = this->values[i]; value = CLAMP(value, 0.0, this->total); if (value > 0) { - blockSizes[i] = ceil((value/this->total) * w); + blockSizes[i] = ceil((value / this->total) * w); } else { blockSizes[i] = 0; } @@ -285,11 +285,11 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { struct timeval now; gettimeofday(&now, NULL); if (!timercmp(&now, &(data->time), <)) { - struct timeval delay = { .tv_sec = CRT_delay/10, .tv_usec = (CRT_delay-((CRT_delay/10)*10)) * 100000 }; + struct timeval delay = { .tv_sec = CRT_delay / 10, .tv_usec = (CRT_delay - ((CRT_delay / 10) * 10)) * 100000 }; timeradd(&now, &delay, &(data->time)); for (int i = 0; i < nValues - 1; i++) - data->values[i] = data->values[i+1]; + data->values[i] = data->values[i + 1]; char buffer[nValues]; Meter_updateValues(this, buffer, nValues - 1); @@ -301,15 +301,15 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { data->values[nValues - 1] = value; } - int i = nValues - (w*2) + 2, k = 0; + int i = nValues - (w * 2) + 2, k = 0; if (i < 0) { - k = -i/2; + k = -i / 2; i = 0; } - for (; i < nValues - 1; i+=2, k++) { + for (; i < nValues - 1; i += 2, k++) { int pix = GraphMeterMode_pixPerRow * GRAPH_HEIGHT; int v1 = CLAMP((int) lround(data->values[i] * pix), 1, pix); - int v2 = CLAMP((int) lround(data->values[i+1] * pix), 1, pix); + int v2 = CLAMP((int) lround(data->values[i + 1] * pix), 1, pix); int colorIdx = GRAPH_1; for (int line = 0; line < GRAPH_HEIGHT; line++) { @@ -317,7 +317,7 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { int line2 = CLAMP(v2 - (GraphMeterMode_pixPerRow * (GRAPH_HEIGHT - 1 - line)), 0, GraphMeterMode_pixPerRow); attrset(CRT_colors[colorIdx]); - mvaddstr(y+line, x+k, GraphMeterMode_dots[line1 * (GraphMeterMode_pixPerRow + 1) + line2]); + mvaddstr(y + line, x + k, GraphMeterMode_dots[line1 * (GraphMeterMode_pixPerRow + 1) + line2]); colorIdx = GRAPH_2; } } @@ -327,17 +327,17 @@ static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { /* ---------- LEDMeterMode ---------- */ static const char* const LEDMeterMode_digitsAscii[] = { - " __ "," "," __ "," __ "," "," __ "," __ "," __ "," __ "," __ ", - "| |"," |"," __|"," __|","|__|","|__ ","|__ "," |","|__|","|__|", - "|__|"," |","|__ "," __|"," |"," __|","|__|"," |","|__|"," __|" + " __ ", " ", " __ ", " __ ", " ", " __ ", " __ ", " __ ", " __ ", " __ ", + "| |", " |", " __|", " __|", "|__|", "|__ ", "|__ ", " |", "|__|", "|__|", + "|__|", " |", "|__ ", " __|", " |", " __|", "|__|", " |", "|__|", " __|" }; #ifdef HAVE_LIBNCURSESW static const char* const LEDMeterMode_digitsUtf8[] = { - "┌──┐"," ┐ ","╶──┐","╶──┐","╷ ╷","┌──╴","┌──╴","╶──┐","┌──┐","┌──┐", - "│ │"," │ ","┌──┘"," ──┤","└──┤","└──┐","├──┐"," │","├──┤","└──┤", - "└──┘"," ╵ ","└──╴","╶──┘"," ╵","╶──┘","└──┘"," ╵","└──┘"," ──┘" + "┌──┐", " ┐ ", "╶──┐", "╶──┐", "╷ ╷", "┌──╴", "┌──╴", "╶──┐", "┌──┐", "┌──┐", + "│ │", " │ ", "┌──┘", " ──┤", "└──┤", "└──┐", "├──┐", " │", "├──┤", "└──┤", + "└──┘", " ╵ ", "└──╴", "╶──┘", " ╵", "╶──┘", "└──┘", " ╵", "└──┘", " ──┘" }; #endif @@ -367,9 +367,9 @@ static void LEDMeterMode_draw(Meter* this, int x, int y, int w) { int yText = #ifdef HAVE_LIBNCURSESW - CRT_utf8 ? y+1 : + CRT_utf8 ? y + 1 : #endif - y+2; + y + 2; attrset(CRT_colors[LED_COLOR]); mvaddstr(yText, x, this->caption); int xx = x + strlen(this->caption); @@ -377,7 +377,7 @@ static void LEDMeterMode_draw(Meter* this, int x, int y, int w) { for (int i = 0; i < len; i++) { char c = RichString_getCharVal(out, i); if (c >= '0' && c <= '9') { - LEDMeterMode_drawDigit(xx, y, c-48); + LEDMeterMode_drawDigit(xx, y, c - 48); xx += 4; } else { mvaddch(yText, xx, c); diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index 0de9ee03..829fafee 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -73,7 +73,7 @@ OpenFilesScreen* OpenFilesScreen_new(const Process* process) { this->pid = process->tgid; else this->pid = process->pid; - return (OpenFilesScreen*) InfoScreen_init(&this->super, process, NULL, LINES-3, " FD TYPE MODE DEVICE SIZE NODE NAME"); + return (OpenFilesScreen*) InfoScreen_init(&this->super, process, NULL, LINES - 3, " FD TYPE MODE DEVICE SIZE NODE NAME"); } void OpenFilesScreen_delete(Object* this) { diff --git a/Panel.c b/Panel.c index 4c333963..5e92c9c7 100644 --- a/Panel.c +++ b/Panel.c @@ -201,7 +201,7 @@ void Panel_setSelected(Panel* this, int selected) { } } -void Panel_splice(Panel *this, Vector* from) { +void Panel_splice(Panel* this, Vector* from) { assert (this != NULL); assert (from != NULL); @@ -295,15 +295,15 @@ void Panel_draw(Panel* this, bool focus) { Object_display(newObj, &new); int newLen = RichString_sizeVal(new); this->selectedLen = newLen; - mvhline(y+ this->oldSelected - first, x+0, ' ', this->w); + mvhline(y + this->oldSelected - first, x + 0, ' ', this->w); if (scrollH < oldLen) - RichString_printoffnVal(old, y+this->oldSelected - first, x, + RichString_printoffnVal(old, y + this->oldSelected - first, x, scrollH, MINIMUM(oldLen - scrollH, this->w)); attrset(selectionColor); - mvhline(y+this->selected - first, x+0, ' ', this->w); + mvhline(y + this->selected - first, x + 0, ' ', this->w); RichString_setAttr(&new, selectionColor); if (scrollH < newLen) - RichString_printoffnVal(new, y+this->selected - first, x, + RichString_printoffnVal(new, y + this->selected - first, x, scrollH, MINIMUM(newLen - scrollH, this->w)); attrset(CRT_colors[RESET_COLOR]); RichString_end(new); diff --git a/Panel.h b/Panel.h index 604750a5..1ea5c7b8 100644 --- a/Panel.h +++ b/Panel.h @@ -111,7 +111,7 @@ void Panel_setSelected(Panel* this, int selected); void Panel_draw(Panel* this, bool focus); -void Panel_splice(Panel *this, Vector* from); +void Panel_splice(Panel* this, Vector* from); bool Panel_onKey(Panel* this, int key); diff --git a/Process.c b/Process.c index 11b99b8b..af7bf79d 100644 --- a/Process.c +++ b/Process.c @@ -74,7 +74,7 @@ void Process_humanNumber(RichString* str, unsigned long long number, bool colori RichString_appendn(str, processColor, buffer, len); } else if (number < 100000) { //2 digit MB, 3 digit KB - len = snprintf(buffer, 10, "%2llu", number/1000); + len = snprintf(buffer, 10, "%2llu", number / 1000); RichString_appendn(str, processMegabytesColor, buffer, len); number %= 1000; len = snprintf(buffer, 10, "%03llu ", number); @@ -87,7 +87,7 @@ void Process_humanNumber(RichString* str, unsigned long long number, bool colori } else if (number < 10000 * ONE_K) { //1 digit GB, 3 digit MB number /= ONE_K; - len = snprintf(buffer, 10, "%1llu", number/1000); + len = snprintf(buffer, 10, "%1llu", number / 1000); RichString_appendn(str, processGigabytesColor, buffer, len); number %= 1000; len = snprintf(buffer, 10, "%03lluM ", number); @@ -95,7 +95,7 @@ void Process_humanNumber(RichString* str, unsigned long long number, bool colori } else if (number < 100000 * ONE_K) { //2 digit GB, 1 digit MB number /= 100 * ONE_K; - len = snprintf(buffer, 10, "%2llu", number/10); + len = snprintf(buffer, 10, "%2llu", number / 10); RichString_appendn(str, processGigabytesColor, buffer, len); number %= 10; len = snprintf(buffer, 10, ".%1lluG ", number); @@ -108,14 +108,14 @@ void Process_humanNumber(RichString* str, unsigned long long number, bool colori } else if (number < 10000ULL * ONE_M) { //1 digit TB, 3 digit GB number /= ONE_M; - len = snprintf(buffer, 10, "%1llu", number/1000); + len = snprintf(buffer, 10, "%1llu", number / 1000); RichString_appendn(str, largeNumberColor, buffer, len); number %= 1000; len = snprintf(buffer, 10, "%03lluG ", number); RichString_appendn(str, processGigabytesColor, buffer, len); } else { //2 digit TB and above - len = snprintf(buffer, 10, "%4.1lfT ", (double)number/ONE_G); + len = snprintf(buffer, 10, "%4.1lfT ", (double)number / ONE_G); RichString_appendn(str, largeNumberColor, buffer, len); } } @@ -142,18 +142,18 @@ void Process_colorNumber(RichString* str, unsigned long long number, bool colori } else if (number >= 100LL * ONE_DECIMAL_T) { xSnprintf(buffer, 13, "%11llu ", number / ONE_DECIMAL_M); RichString_appendn(str, largeNumberColor, buffer, 8); - RichString_appendn(str, processMegabytesColor, buffer+8, 4); + RichString_appendn(str, processMegabytesColor, buffer + 8, 4); } else if (number >= 10LL * ONE_DECIMAL_G) { xSnprintf(buffer, 13, "%11llu ", number / ONE_DECIMAL_K); RichString_appendn(str, largeNumberColor, buffer, 5); - RichString_appendn(str, processMegabytesColor, buffer+5, 3); - RichString_appendn(str, processColor, buffer+8, 4); + RichString_appendn(str, processMegabytesColor, buffer + 5, 3); + RichString_appendn(str, processColor, buffer + 8, 4); } else { xSnprintf(buffer, 13, "%11llu ", number); RichString_appendn(str, largeNumberColor, buffer, 2); - RichString_appendn(str, processMegabytesColor, buffer+2, 3); - RichString_appendn(str, processColor, buffer+5, 3); - RichString_appendn(str, processShadowColor, buffer+8, 4); + RichString_appendn(str, processMegabytesColor, buffer + 2, 3); + RichString_appendn(str, processColor, buffer + 5, 3); + RichString_appendn(str, processShadowColor, buffer + 8, 4); } } diff --git a/Process.h b/Process.h index b2c82080..465fed68 100644 --- a/Process.h +++ b/Process.h @@ -119,7 +119,7 @@ extern ProcessFieldData Process_fields[]; extern ProcessPidColumn Process_pidColumns[]; extern char Process_pidFormat[20]; -typedef Process*(*Process_New)(const struct Settings_*); +typedef Process* (* Process_New)(const struct Settings_*); typedef void (*Process_WriteField)(const Process*, RichString*, ProcessField); typedef struct ProcessClass_ { diff --git a/ProcessList.c b/ProcessList.c index dac86cb8..ff4aa9b3 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -131,9 +131,9 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i Vector_add(this->processes2, process); else Vector_insert(this->processes2, 0, process); - assert(Vector_size(this->processes2) == s+1); (void)s; + assert(Vector_size(this->processes2) == s + 1); (void)s; int nextIndent = indent | (1 << level); - ProcessList_buildTree(this, process->pid, level+1, (i < size - 1) ? nextIndent : indent, direction, show ? process->showChildren : false); + ProcessList_buildTree(this, process->pid, level + 1, (i < size - 1) ? nextIndent : indent, direction, show ? process->showChildren : false); if (i == size - 1) process->indent = -nextIndent; else @@ -143,8 +143,8 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i } static long ProcessList_treeProcessCompare(const void* v1, const void* v2) { - const Process *p1 = (const Process*)v1; - const Process *p2 = (const Process*)v2; + const Process* p1 = (const Process*)v1; + const Process* p2 = (const Process*)v2; return p1->pid - p2->pid; } diff --git a/RichString.c b/RichString.c index bda39181..99c535b1 100644 --- a/RichString.c +++ b/RichString.c @@ -48,7 +48,7 @@ static void RichString_setLen(RichString* this, int len) { #ifdef HAVE_LIBNCURSESW static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) { - wchar_t data[len+1]; + wchar_t data[len + 1]; len = mbstowcs(data, data_c, len); if (len < 0) return; diff --git a/RichString.h b/RichString.h index 11be4137..5bcda602 100644 --- a/RichString.h +++ b/RichString.h @@ -38,7 +38,7 @@ in the source distribution for its full text. typedef struct RichString_ { int chlen; CharType* chptr; - CharType chstr[RICHSTRING_MAXLEN+1]; + CharType chstr[RICHSTRING_MAXLEN + 1]; } RichString; void RichString_setAttrn(RichString* this, int attrs, int start, int finish); diff --git a/ScreenManager.c b/ScreenManager.c index bc5f66ac..f586d04a 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -58,7 +58,7 @@ void ScreenManager_add(ScreenManager* this, Panel* item, int size) { if (size > 0) { Panel_resize(item, size, height); } else { - Panel_resize(item, COLS-this->x1+this->x2-lastX, height); + Panel_resize(item, COLS - this->x1 + this->x2 - lastX, height); } Panel_move(item, lastX, this->y1); } @@ -85,18 +85,18 @@ void ScreenManager_resize(ScreenManager* this, int x1, int y1, int x2, int y2) { int lastX = 0; for (int i = 0; i < panels - 1; i++) { Panel* panel = (Panel*) Vector_get(this->panels, i); - Panel_resize(panel, panel->w, LINES-y1+y2); + Panel_resize(panel, panel->w, LINES - y1 + y2); Panel_move(panel, lastX, y1); lastX = panel->x + panel->w + 1; } - Panel* panel = (Panel*) Vector_get(this->panels, panels-1); - Panel_resize(panel, COLS-x1+x2-lastX, LINES-y1+y2); + Panel* panel = (Panel*) Vector_get(this->panels, panels - 1); + Panel_resize(panel, COLS - x1 + x2 - lastX, LINES - y1 + y2); Panel_move(panel, lastX, y1); } // TODO: VERTICAL } -static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTimeout, bool* redraw, bool *rescan, bool *timedOut) { +static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTimeout, bool* redraw, bool* rescan, bool* timedOut) { ProcessList* pl = this->header->pl; struct timeval tv; @@ -127,7 +127,7 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus) { Panel* panel = (Panel*) Vector_get(this->panels, i); Panel_draw(panel, i == focus); if (this->orientation == HORIZONTAL) { - mvvline(panel->y, panel->x+panel->w, ' ', panel->h+1); + mvvline(panel->y, panel->x + panel->w, ' ', panel->h + 1); } } } @@ -182,11 +182,11 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { } else { for (int i = 0; i < this->panelCount; i++) { Panel* panel = (Panel*) Vector_get(this->panels, i); - if (mevent.x >= panel->x && mevent.x <= panel->x+panel->w) { + if (mevent.x >= panel->x && mevent.x <= panel->x + panel->w) { if (mevent.y == panel->y) { ch = EVENT_HEADER_CLICK(mevent.x - panel->x); break; - } else if (mevent.y > panel->y && mevent.y <= panel->y+panel->h) { + } else if (mevent.y > panel->y && mevent.y <= panel->y + panel->h) { ch = KEY_MOUSE; if (panel == panelFocus || this->allowFocusChange) { focus = i; diff --git a/Settings.c b/Settings.c index 2cb560ed..2e274e94 100644 --- a/Settings.c +++ b/Settings.c @@ -217,7 +217,7 @@ static void writeFields(FILE* fd, ProcessField* fields, const char* name) { const char* sep = ""; for (int i = 0; fields[i]; i++) { // This "-1" is for compatibility with the older enum format. - fprintf(fd, "%s%d", sep, (int) fields[i]-1); + fprintf(fd, "%s%d", sep, (int) fields[i] - 1); sep = " "; } fprintf(fd, "\n"); @@ -255,7 +255,7 @@ bool Settings_write(Settings* this) { fprintf(fd, "# The parser is also very primitive, and not human-friendly.\n"); writeFields(fd, this->fields, "fields"); // This "-1" is for compatibility with the older enum format. - fprintf(fd, "sort_key=%d\n", (int) this->sortKey-1); + fprintf(fd, "sort_key=%d\n", (int) this->sortKey - 1); fprintf(fd, "sort_direction=%d\n", (int) this->direction); fprintf(fd, "hide_threads=%d\n", (int) this->hideThreads); fprintf(fd, "hide_kernel_threads=%d\n", (int) this->hideKernelThreads); @@ -311,7 +311,7 @@ Settings* Settings_new(int initialCpuCount) { #ifdef HAVE_LIBHWLOC this->topologyAffinity = false; #endif - this->fields = xCalloc(Platform_numberOfFields+1, sizeof(ProcessField)); + this->fields = xCalloc(Platform_numberOfFields + 1, sizeof(ProcessField)); // TODO: turn 'fields' into a Vector, // (and ProcessFields into proper objects). this->flags = 0; diff --git a/TraceScreen.c b/TraceScreen.c index 18dad58c..7346a0f8 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -52,7 +52,7 @@ TraceScreen* TraceScreen_new(Process* process) { this->tracing = true; FunctionBar* fuBar = FunctionBar_new(TraceScreenFunctions, TraceScreenKeys, TraceScreenEvents); CRT_disableDelay(); - return (TraceScreen*) InfoScreen_init(&this->super, process, fuBar, LINES-2, ""); + return (TraceScreen*) InfoScreen_init(&this->super, process, fuBar, LINES - 2, ""); } void TraceScreen_delete(Object* cast) { @@ -141,8 +141,9 @@ void TraceScreen_updateTrace(InfoScreen* super) { FD_SET(fd_strace, &fds); struct timeval tv; - tv.tv_sec = 0; tv.tv_usec = 500; - int ready = select(fd_strace+1, &fds, NULL, NULL, &tv); + tv.tv_sec = 0; + tv.tv_usec = 500; + int ready = select(fd_strace + 1, &fds, NULL, NULL, &tv); size_t nread = 0; if (ready > 0 && FD_ISSET(fd_strace, &fds)) nread = fread(buffer, 1, sizeof(buffer) - 1, this->strace); @@ -158,10 +159,10 @@ void TraceScreen_updateTrace(InfoScreen* super) { } else { InfoScreen_addLine(&this->super, line); } - line = buffer+i+1; + line = buffer + i + 1; } } - if (line < buffer+nread) { + if (line < buffer + nread) { InfoScreen_addLine(&this->super, line); buffer[nread] = '\0'; this->contLine = true; diff --git a/UptimeMeter.c b/UptimeMeter.c index 89e34175..79070286 100644 --- a/UptimeMeter.c +++ b/UptimeMeter.c @@ -24,9 +24,9 @@ static void UptimeMeter_updateValues(Meter* this, char* buffer, int len) { return; } int seconds = totalseconds % 60; - int minutes = (totalseconds/60) % 60; - int hours = (totalseconds/3600) % 24; - int days = (totalseconds/86400); + int minutes = (totalseconds / 60) % 60; + int hours = (totalseconds / 3600) % 24; + int days = (totalseconds / 86400); this->values[0] = days; if (days > this->total) { this->total = days; diff --git a/Vector.c b/Vector.c index ea276671..eb80e145 100644 --- a/Vector.c +++ b/Vector.c @@ -118,7 +118,8 @@ static int partition(Object** array, int left, int right, int pivotIndex, Object static void quickSort(Object** array, int left, int right, Object_Compare compare) { if (left >= right) return; - int pivotIndex = (left+right) / 2; + + int pivotIndex = (left + right) / 2; int pivotNewIndex = partition(array, left, right, pivotIndex, compare); quickSort(array, left, pivotNewIndex - 1, compare); quickSort(array, pivotNewIndex + 1, right, compare); @@ -148,17 +149,18 @@ static void combSort(Object** array, int left, int right, Object_Compare compare */ static void insertionSort(Object** array, int left, int right, Object_Compare compare) { - for (int i = left+1; i <= right; i++) { + for (int i = left + 1; i <= right; i++) { Object* t = array[i]; int j = i - 1; while (j >= left) { //comparisons++; if (compare(array[j], t) <= 0) break; - array[j+1] = array[j]; + + array[j + 1] = array[j]; j--; } - array[j+1] = t; + array[j + 1] = t; } } @@ -260,7 +262,7 @@ void Vector_set(Vector* this, int idx, void* data_) { Vector_checkArraySize(this); if (idx >= this->items) { - this->items = idx+1; + this->items = idx + 1; } else { if (this->owner) { Object* removed = this->array[idx]; @@ -293,7 +295,7 @@ void Vector_add(Vector* this, void* data_) { assert(Vector_isConsistent(this)); int i = this->items; Vector_set(this, this->items, data); - assert(this->items == i+1); (void)(i); + assert(this->items == i + 1); (void)(i); assert(Vector_isConsistent(this)); } diff --git a/Vector.h b/Vector.h index 70df3e4a..70688152 100644 --- a/Vector.h +++ b/Vector.h @@ -17,7 +17,7 @@ in the source distribution for its full text. #endif typedef struct Vector_ { - Object **array; + Object** array; const ObjectClass* type; int arraySize; int growthRate; diff --git a/XUtils.c b/XUtils.c index 811fa50f..dcc8b390 100644 --- a/XUtils.c +++ b/XUtils.c @@ -59,7 +59,7 @@ char* String_cat(const char* s1, const char* s2) { const size_t l2 = strlen(s2); char* out = xMalloc(l1 + l2 + 1); memcpy(out, s1, l1); - memcpy(out+l1, s2, l2); + memcpy(out + l1, s2, l2); out[l1 + l2] = '\0'; return out; } @@ -70,7 +70,7 @@ char* String_trim(const char* in) { } size_t len = strlen(in); - while (len > 0 && (in[len-1] == ' ' || in[len-1] == '\t' || in[len-1] == '\n')) { + while (len > 0 && (in[len - 1] == ' ' || in[len - 1] == '\t' || in[len - 1] == '\n')) { len--; } @@ -126,12 +126,12 @@ char* String_getToken(const char* line, const unsigned short int numMatch) { for (size_t i = 0; i < len; i++) { char lastState = inWord; - inWord = line[i] == ' ' ? 0:1; + inWord = line[i] == ' ' ? 0 : 1; if (lastState == 0 && inWord == 1) count++; - if (inWord == 1){ + if (inWord == 1) { if (count == numMatch && line[i] != ' ' && line[i] != '\0' && line[i] != '\n' && line[i] != (char)EOF) { match[foundCount] = line[i]; foundCount++; diff --git a/XUtils.h b/XUtils.h index 591e98bb..a978a0ed 100644 --- a/XUtils.h +++ b/XUtils.h @@ -54,10 +54,10 @@ char* String_getToken(const char* line, unsigned short int numMatch); char* String_readLine(FILE* fd); ATTR_FORMAT(printf, 2, 3) -int xAsprintf(char **strp, const char* fmt, ...); +int xAsprintf(char** strp, const char* fmt, ...); ATTR_FORMAT(printf, 3, 4) -int xSnprintf(char *buf, int len, const char* fmt, ...); +int xSnprintf(char* buf, int len, const char* fmt, ...); char* xStrdup(const char* str) ATTR_NONNULL; diff --git a/darwin/DarwinProcess.c b/darwin/DarwinProcess.c index a92f2661..c06ec4a6 100644 --- a/darwin/DarwinProcess.c +++ b/darwin/DarwinProcess.c @@ -52,7 +52,7 @@ bool Process_isThread(const Process* this) { return false; } -char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) { +char* DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) { /* This function is from the old Mac version of htop. Originally from ps? */ int mib[3], argmax, nargs, c = 0; size_t size; @@ -68,7 +68,7 @@ char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset) { } /* Allocate space for the arguments. */ - procargs = ( char * ) xMalloc( argmax ); + procargs = (char*)xMalloc(argmax); if ( procargs == NULL ) { goto ERROR_A; } @@ -195,8 +195,8 @@ ERROR_A: return retval; } -void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool exists) { - struct extern_proc *ep = &ps->kp_proc; +void DarwinProcess_setFromKInfoProc(Process* proc, struct kinfo_proc* ps, bool exists) { + struct extern_proc* ep = &ps->kp_proc; /* UNSET HERE : * @@ -241,7 +241,7 @@ void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool e proc->updated = true; } -void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl) { +void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessList* dpl) { struct proc_taskinfo pti; if (sizeof(pti) == proc_pidinfo(proc->super.pid, PROC_PIDTASKINFO, 0, &pti, sizeof(pti))) { @@ -280,7 +280,7 @@ void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList * Based on: http://stackoverflow.com/questions/6788274/ios-mac-cpu-usage-for-thread * and https://github.com/max-horvath/htop-osx/blob/e86692e869e30b0bc7264b3675d2a4014866ef46/ProcessList.c */ -void DarwinProcess_scanThreads(DarwinProcess *dp) { +void DarwinProcess_scanThreads(DarwinProcess* dp) { Process* proc = (Process*) dp; kern_return_t ret; diff --git a/darwin/DarwinProcess.h b/darwin/DarwinProcess.h index 1d9dc34a..627a6bcb 100644 --- a/darwin/DarwinProcess.h +++ b/darwin/DarwinProcess.h @@ -28,17 +28,17 @@ void Process_delete(Object* cast); bool Process_isThread(const Process* this); -char *DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset); +char* DarwinProcess_getCmdLine(struct kinfo_proc* k, int* basenameOffset); -void DarwinProcess_setFromKInfoProc(Process *proc, struct kinfo_proc *ps, bool exists); +void DarwinProcess_setFromKInfoProc(Process* proc, struct kinfo_proc* ps, bool exists); -void DarwinProcess_setFromLibprocPidinfo(DarwinProcess *proc, DarwinProcessList *dpl); +void DarwinProcess_setFromLibprocPidinfo(DarwinProcess* proc, DarwinProcessList* dpl); /* * Scan threads for process state information. * Based on: http://stackoverflow.com/questions/6788274/ios-mac-cpu-usage-for-thread * and https://github.com/max-horvath/htop-osx/blob/e86692e869e30b0bc7264b3675d2a4014866ef46/ProcessList.c */ -void DarwinProcess_scanThreads(DarwinProcess *dp); +void DarwinProcess_scanThreads(DarwinProcess* dp); #endif diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index bb7c56db..673d9e61 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -27,7 +27,7 @@ struct kern { short int version[3]; }; -void GetKernelVersion(struct kern *k) { +void GetKernelVersion(struct kern* k) { static short int version_[3] = {0}; if (!version_[0]) { // just in case it fails someday @@ -64,7 +64,7 @@ int CompareKernelVersion(short int major, short int minor, short int component) return 0; } -void ProcessList_getHostInfo(host_basic_info_data_t *p) { +void ProcessList_getHostInfo(host_basic_info_data_t* p) { mach_msg_type_number_t info_size = HOST_BASIC_INFO_COUNT; if (0 != host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)p, &info_size)) { @@ -72,7 +72,7 @@ void ProcessList_getHostInfo(host_basic_info_data_t *p) { } } -void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) { +void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t* p) { if (NULL != p && NULL != *p) { if (0 != munmap(*p, vm_page_size)) { CRT_fatalError("Unable to free old CPU load information\n"); @@ -81,7 +81,7 @@ void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p) { } } -unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p) { +unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t* p) { mach_msg_type_number_t info_size = sizeof(processor_cpu_load_info_t); unsigned cpu_count; @@ -101,9 +101,9 @@ void ProcessList_getVMStats(vm_statistics_t p) { } } -struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count) { +struct kinfo_proc* ProcessList_getKInfoProcs(size_t* count) { int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL, 0 }; - struct kinfo_proc *processes = NULL; + struct kinfo_proc* processes = NULL; /* Note the two calls to sysctl(). One to get length and one to get the * data. This -does- mean that the second call could end up with a missing diff --git a/darwin/DarwinProcessList.h b/darwin/DarwinProcessList.h index 44a847dc..bdcbb183 100644 --- a/darwin/DarwinProcessList.h +++ b/darwin/DarwinProcessList.h @@ -9,7 +9,7 @@ in the source distribution for its full text. struct kern; -void GetKernelVersion(struct kern *k); +void GetKernelVersion(struct kern* k); /* compare the given os version with the one installed returns: 0 if equals the installed version @@ -37,15 +37,15 @@ typedef struct DarwinProcessList_ { ZfsArcStats zfs; } DarwinProcessList; -void ProcessList_getHostInfo(host_basic_info_data_t *p); +void ProcessList_getHostInfo(host_basic_info_data_t* p); -void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t *p); +void ProcessList_freeCPULoadInfo(processor_cpu_load_info_t* p); -unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t *p); +unsigned ProcessList_allocateCPULoadInfo(processor_cpu_load_info_t* p); void ProcessList_getVMStats(vm_statistics_t p); -struct kinfo_proc *ProcessList_getKInfoProcs(size_t *count); +struct kinfo_proc* ProcessList_getKInfoProcs(size_t* count); ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); diff --git a/darwin/Platform.c b/darwin/Platform.c index c5a22da4..e48fbbd3 100644 --- a/darwin/Platform.c +++ b/darwin/Platform.c @@ -176,7 +176,7 @@ ProcessPidColumn Process_pidColumns[] = { }; static double Platform_setCPUAverageValues(Meter* mtr) { - const ProcessList *dpl = mtr->pl; + const ProcessList* dpl = mtr->pl; int cpus = dpl->cpuCount; double sumNice = 0.0; double sumNormal = 0.0; @@ -200,9 +200,9 @@ double Platform_setCPUValues(Meter* mtr, int cpu) { return Platform_setCPUAverageValues(mtr); } - const DarwinProcessList *dpl = (const DarwinProcessList *)mtr->pl; - const processor_cpu_load_info_t prev = &dpl->prev_load[cpu-1]; - const processor_cpu_load_info_t curr = &dpl->curr_load[cpu-1]; + const DarwinProcessList* dpl = (const DarwinProcessList*)mtr->pl; + const processor_cpu_load_info_t prev = &dpl->prev_load[cpu - 1]; + const processor_cpu_load_info_t curr = &dpl->curr_load[cpu - 1]; double total = 0; /* Take the sums */ @@ -228,7 +228,7 @@ double Platform_setCPUValues(Meter* mtr, int cpu) { } void Platform_setMemoryValues(Meter* mtr) { - const DarwinProcessList *dpl = (const DarwinProcessList *)mtr->pl; + const DarwinProcessList* dpl = (const DarwinProcessList*)mtr->pl; const struct vm_statistics* vm = &dpl->vm_stats; double page_K = (double)vm_page_size / (double)1024; @@ -283,14 +283,14 @@ char* Platform_getProcessEnv(pid_t pid) { p += sizeof(int); // skip exe - p = strchr(p, 0)+1; + p = strchr(p, 0) + 1; // skip padding while (!*p && p < endp) ++p; // skip argv - for (; argc-- && p < endp; p = strrchr(p, 0)+1) + for (; argc-- && p < endp; p = strrchr(p, 0) + 1) ; // skip padding @@ -298,10 +298,10 @@ char* Platform_getProcessEnv(pid_t pid) { ++p; size_t size = endp - p; - env = xMalloc(size+2); + env = xMalloc(size + 2); memcpy(env, p, size); env[size] = 0; - env[size+1] = 0; + env[size + 1] = 0; } } free(buf); @@ -317,10 +317,10 @@ bool Platform_getDiskIO(DiskIOData* data) { return false; } -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted) { +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted) { // TODO *bytesReceived = 0; *packetsReceived = 0; diff --git a/darwin/Platform.h b/darwin/Platform.h index 471b38a9..7d3f4197 100644 --- a/darwin/Platform.h +++ b/darwin/Platform.h @@ -51,9 +51,9 @@ char* Platform_getProcessEnv(pid_t pid); bool Platform_getDiskIO(DiskIOData* data); -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted); +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted); #endif diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c index 6650cb7e..457a488a 100644 --- a/dragonflybsd/DragonFlyBSDProcess.c +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -92,7 +92,7 @@ void DragonFlyBSDProcess_writeField(const Process* this, RichString* str, Proces // add Platform-specific fields here case PID: xSnprintf(buffer, n, Process_pidFormat, (fp->kernel ? -1 : this->pid)); break; case JID: xSnprintf(buffer, n, Process_pidFormat, fp->jid); break; - case JAIL:{ + case JAIL: { xSnprintf(buffer, n, "%-11s ", fp->jname); if (buffer[11] != '\0') { buffer[11] = ' '; diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 90bc7f7a..d3acf73d 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -149,8 +149,8 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) { size_t sizeof_cp_time_array; - unsigned long *cp_time_n; // old clicks state - unsigned long *cp_time_o; // current clicks state + unsigned long* cp_time_n; // old clicks state + unsigned long* cp_time_o; // current clicks state unsigned long cp_time_d[CPUSTATES]; double cp_time_p[CPUSTATES]; @@ -296,9 +296,9 @@ char* DragonFlyBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kpro static inline void DragonFlyBSDProcessList_scanJails(DragonFlyBSDProcessList* dfpl) { size_t len; - char *jls; /* Jail list */ - char *curpos; - char *nextpos; + char* jls; /* Jail list */ + char* curpos; + char* nextpos; if (sysctlbyname("jail.list", NULL, &len, NULL, 0) == -1) { fprintf(stderr, "initial sysctlbyname / jail.list failed\n"); @@ -329,7 +329,7 @@ retry: curpos = jls; while (curpos) { int jailid; - char *str_hostname; + char* str_hostname; nextpos = strchr(curpos, '\n'); if (nextpos) *nextpos++ = 0; @@ -337,7 +337,7 @@ retry: jailid = atoi(strtok(curpos, " ")); str_hostname = strtok(NULL, " "); - char *jname = (char *) (Hashtable_get(dfpl->jails, jailid)); + char* jname = (char*) (Hashtable_get(dfpl->jails, jailid)); if (jname == NULL) { jname = xStrdup(str_hostname); Hashtable_put(dfpl->jails, jailid, jname); @@ -353,7 +353,7 @@ char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int ja char* hostname; char* jname; - if (jailid != 0 && dfpl->jails && (hostname = (char *)Hashtable_get(dfpl->jails, jailid))) { + if (jailid != 0 && dfpl->jails && (hostname = (char*)Hashtable_get(dfpl->jails, jailid))) { jname = xStrdup(hostname); } else { jname = xStrdup("-"); diff --git a/dragonflybsd/DragonFlyBSDProcessList.h b/dragonflybsd/DragonFlyBSDProcessList.h index f3965fd3..ff65a636 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.h +++ b/dragonflybsd/DragonFlyBSDProcessList.h @@ -42,13 +42,13 @@ typedef struct DragonFlyBSDProcessList_ { CPUData* cpus; - unsigned long *cp_time_o; - unsigned long *cp_time_n; + unsigned long* cp_time_o; + unsigned long* cp_time_n; - unsigned long *cp_times_o; - unsigned long *cp_times_n; + unsigned long* cp_times_o; + unsigned long* cp_times_n; - Hashtable *jails; + Hashtable* jails; } DragonFlyBSDProcessList; ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, uid_t userId); diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 6f8c2023..5e9fe335 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -169,11 +169,11 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[CPU_METER_KERNEL] = cpuData->systemPercent; v[CPU_METER_IRQ] = cpuData->irqPercent; this->curItems = 4; - percent = v[0]+v[1]+v[2]+v[3]; + percent = v[0] + v[1] + v[2] + v[3]; } else { v[2] = cpuData->systemAllPercent; this->curItems = 3; - percent = v[0]+v[1]+v[2]; + percent = v[0] + v[1] + v[2]; } percent = CLAMP(percent, 0.0, 100.0); @@ -212,10 +212,10 @@ bool Platform_getDiskIO(DiskIOData* data) { return false; } -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted) { +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted) { // TODO *bytesReceived = 0; *packetsReceived = 0; diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index 6c884719..e31fbeac 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -43,9 +43,9 @@ char* Platform_getProcessEnv(pid_t pid); bool Platform_getDiskIO(DiskIOData* data); -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted); +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted); #endif diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index fee2c2c8..a4516d04 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -83,7 +83,7 @@ static void FreeBSDProcess_writeField(const Process* this, RichString* str, Proc switch ((int) field) { // add FreeBSD-specific fields here case JID: xSnprintf(buffer, n, Process_pidFormat, fp->jid); break; - case JAIL:{ + case JAIL: { xSnprintf(buffer, n, "%-11s ", fp->jname); if (buffer[11] != '\0') { buffer[11] = ' '; diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 8be627c9..4594b992 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -175,8 +175,8 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) { size_t sizeof_cp_time_array; - unsigned long *cp_time_n; // old clicks state - unsigned long *cp_time_o; // current clicks state + unsigned long* cp_time_n; // old clicks state + unsigned long* cp_time_o; // current clicks state unsigned long cp_time_d[CPUSTATES]; double cp_time_p[CPUSTATES]; @@ -415,18 +415,18 @@ static char* FreeBSDProcessList_readJailName(const struct kinfo_proc* kproc) { char* jname; char jnamebuf[MAXHOSTNAMELEN]; - if (kproc->ki_jid != 0 ){ + if (kproc->ki_jid != 0 ) { memset(jnamebuf, 0, sizeof(jnamebuf)); IGNORE_WCASTQUAL_BEGIN - *(const void **)&jiov[0].iov_base = "jid"; + *(const void**)&jiov[0].iov_base = "jid"; jiov[0].iov_len = sizeof("jid"); jiov[1].iov_base = (void*) &kproc->ki_jid; jiov[1].iov_len = sizeof(kproc->ki_jid); - *(const void **)&jiov[2].iov_base = "name"; + *(const void**)&jiov[2].iov_base = "name"; jiov[2].iov_len = sizeof("name"); jiov[3].iov_base = jnamebuf; jiov[3].iov_len = sizeof(jnamebuf); - *(const void **)&jiov[4].iov_base = "errmsg"; + *(const void**)&jiov[4].iov_base = "errmsg"; jiov[4].iov_len = sizeof("errmsg"); jiov[5].iov_base = jail_errmsg; jiov[5].iov_len = JAIL_ERRMSGLEN; @@ -446,8 +446,8 @@ IGNORE_WCASTQUAL_END return NULL; } } else { - jnamebuf[0]='-'; - jnamebuf[1]='\0'; + jnamebuf[0] = '-'; + jnamebuf[1] = '\0'; jname = xStrdup(jnamebuf); } return jname; diff --git a/freebsd/FreeBSDProcessList.h b/freebsd/FreeBSDProcessList.h index e97444bd..cbe4742c 100644 --- a/freebsd/FreeBSDProcessList.h +++ b/freebsd/FreeBSDProcessList.h @@ -48,11 +48,11 @@ typedef struct FreeBSDProcessList_ { Hashtable* ttys; - unsigned long *cp_time_o; - unsigned long *cp_time_n; + unsigned long* cp_time_o; + unsigned long* cp_time_n; - unsigned long *cp_times_o; - unsigned long *cp_times_n; + unsigned long* cp_times_o; + unsigned long* cp_times_n; } FreeBSDProcessList; diff --git a/freebsd/Platform.c b/freebsd/Platform.c index 32b54293..a8edd036 100644 --- a/freebsd/Platform.c +++ b/freebsd/Platform.c @@ -180,11 +180,11 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[CPU_METER_KERNEL] = cpuData->systemPercent; v[CPU_METER_IRQ] = cpuData->irqPercent; this->curItems = 4; - percent = v[0]+v[1]+v[2]+v[3]; + percent = v[0] + v[1] + v[2] + v[3]; } else { v[2] = cpuData->systemAllPercent; this->curItems = 3; - percent = v[0]+v[1]+v[2]; + percent = v[0] + v[1] + v[2]; } percent = CLAMP(percent, 0.0, 100.0); @@ -234,10 +234,10 @@ char* Platform_getProcessEnv(pid_t pid) { return NULL; } - if (env[capacity-1] || env[capacity-2]) { - env = xRealloc(env, capacity+2); + if (env[capacity - 1] || env[capacity - 2]) { + env = xRealloc(env, capacity + 2); env[capacity] = 0; - env[capacity+1] = 0; + env[capacity + 1] = 0; } return env; @@ -283,10 +283,10 @@ bool Platform_getDiskIO(DiskIOData* data) { return true; } -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted) { +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted) { int r; // get number of interfaces diff --git a/freebsd/Platform.h b/freebsd/Platform.h index 894b3e25..c396f2af 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -46,9 +46,9 @@ char* Platform_getProcessEnv(pid_t pid); bool Platform_getDiskIO(DiskIOData* data); -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted); +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted); #endif diff --git a/htop.c b/htop.c index 2e11a949..76754462 100644 --- a/htop.c +++ b/htop.c @@ -106,10 +106,10 @@ static CommandLineSettings parseArguments(int argc, char** argv) { {"tree", no_argument, 0, 't'}, {"pid", required_argument, 0, 'p'}, {"filter", required_argument, 0, 'F'}, - {0,0,0,0} + {0, 0, 0, 0} }; - int opt, opti=0; + int opt, opti = 0; /* Parse arguments */ while ((opt = getopt_long(argc, argv, "hVMCs:td:u::Up:F:", long_opts, &opti))) { if (opt == EOF) break; @@ -218,7 +218,7 @@ static void millisleep(unsigned long millisec) { .tv_sec = 0, .tv_nsec = millisec * 1000000L }; - while (nanosleep(&req,&req)==-1) { + while (nanosleep(&req, &req) == -1) { continue; } } @@ -242,7 +242,7 @@ static void setCommFilter(State* state, char** commFilter) { int main(int argc, char** argv) { - char *lc_ctype = getenv("LC_CTYPE"); + char* lc_ctype = getenv("LC_CTYPE"); if (lc_ctype != NULL) setlocale(LC_CTYPE, lc_ctype); else if ((lc_ctype = getenv("LC_ALL"))) @@ -318,7 +318,7 @@ int main(int argc, char** argv) { ScreenManager_run(scr, NULL, NULL); attron(CRT_colors[RESET_COLOR]); - mvhline(LINES-1, 0, ' ', COLS); + mvhline(LINES - 1, 0, ' ', COLS); attroff(CRT_colors[RESET_COLOR]); refresh(); diff --git a/linux/Battery.c b/linux/Battery.c index c185258a..326f35fd 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -37,7 +37,7 @@ Linux battery readings written by Ian P. Hands (iphands@gmail.com, ihands@redhat // but I think this is on the way out so I did not rewrite it. // The /sys implementation below does things the right way. -static unsigned long int parseBatInfo(const char *fileName, const unsigned short int lineNum, const unsigned short int wordNum) { +static unsigned long int parseBatInfo(const char* fileName, const unsigned short int lineNum, const unsigned short int wordNum) { const char batteryPath[] = PROCDIR "/acpi/battery/"; DIR* batteryDir = opendir(batteryPath); if (!batteryDir) @@ -81,7 +81,7 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short if (!line) break; - char *foundNumStr = String_getToken(line, wordNum); + char* foundNumStr = String_getToken(line, wordNum); const unsigned long int foundNum = atoi(foundNumStr); free(foundNumStr); free(line); @@ -98,8 +98,8 @@ static unsigned long int parseBatInfo(const char *fileName, const unsigned short static ACPresence procAcpiCheck(void) { ACPresence isOn = AC_ERROR; - const char *power_supplyPath = PROCDIR "/acpi/ac_adapter"; - DIR *dir = opendir(power_supplyPath); + const char* power_supplyPath = PROCDIR "/acpi/ac_adapter"; + DIR* dir = opendir(power_supplyPath); if (!dir) { return AC_ERROR; } @@ -115,7 +115,7 @@ static ACPresence procAcpiCheck(void) { continue; char statePath[256]; - xSnprintf((char *) statePath, sizeof statePath, "%s/%s/state", power_supplyPath, entryName); + xSnprintf(statePath, sizeof(statePath), "%s/%s/state", power_supplyPath, entryName); FILE* file = fopen(statePath, "r"); if (!file) { isOn = AC_ERROR; @@ -125,7 +125,7 @@ static ACPresence procAcpiCheck(void) { fclose(file); if (!line) continue; - char *isOnline = String_getToken(line, 2); + char* isOnline = String_getToken(line, 2); free(line); if (String_eq(isOnline, "on-line")) { @@ -165,14 +165,14 @@ static void Battery_getProcData(double* level, ACPresence* isOnAC) { // READ FROM /sys // ---------------------------------------- -static inline ssize_t xread(int fd, void *buf, size_t count) { +static inline ssize_t xread(int fd, void* buf, size_t count) { // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. size_t alreadyRead = 0; for (;;) { ssize_t res = read(fd, buf, count); if (res == -1 && errno == EINTR) continue; if (res > 0) { - buf = ((char*)buf)+res; + buf = ((char*)buf) + res; count -= res; alreadyRead += res; } @@ -186,7 +186,7 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { *level = NAN; *isOnAC = AC_ERROR; - DIR *dir = opendir(SYS_POWERSUPPLY_DIR); + DIR* dir = opendir(SYS_POWERSUPPLY_DIR); if (!dir) return; @@ -226,8 +226,8 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { return; } buffer[buflen] = '\0'; - char *buf = buffer; - char *line = NULL; + char* buf = buffer; + char* line = NULL; bool full = false; bool now = false; int fullSize = 0; diff --git a/linux/IOPriorityPanel.c b/linux/IOPriorityPanel.c index 50f57c10..9f85e792 100644 --- a/linux/IOPriorityPanel.c +++ b/linux/IOPriorityPanel.c @@ -30,7 +30,7 @@ Panel* IOPriorityPanel_new(IOPriority currPrio) { for (int c = 0; classes[c].name; c++) { for (int i = 0; i < 8; i++) { char name[50]; - xSnprintf(name, sizeof(name)-1, "%s %d %s", classes[c].name, i, i == 0 ? "(High)" : (i == 7 ? "(Low)" : "")); + xSnprintf(name, sizeof(name) - 1, "%s %d %s", classes[c].name, i, i == 0 ? "(High)" : (i == 7 ? "(Low)" : "")); IOPriority ioprio = IOPriority_tuple(classes[c].klass, i); Panel_add(this, (Object*) ListItem_new(name, ioprio)); if (currPrio == ioprio) Panel_setSelected(this, Panel_size(this) - 1); diff --git a/linux/LinuxProcess.h b/linux/LinuxProcess.h index 3f978346..1285529a 100644 --- a/linux/LinuxProcess.h +++ b/linux/LinuxProcess.h @@ -152,7 +152,7 @@ typedef struct LinuxProcess_ { #endif unsigned long ctxt_total; unsigned long ctxt_diff; - char *secattr; + char* secattr; } LinuxProcess; #define Process_isKernelThread(_process) (((const LinuxProcess*)(_process))->isKernelThread) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 6065d429..6e7906d5 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -51,14 +51,14 @@ in the source distribution for its full text. #endif -static ssize_t xread(int fd, void *buf, size_t count) { +static ssize_t xread(int fd, void* buf, size_t count) { // Read some bytes. Retry on EINTR and when we don't get as many bytes as we requested. size_t alreadyRead = 0; for (;;) { ssize_t res = read(fd, buf, count); if (res == -1 && errno == EINTR) continue; if (res > 0) { - buf = ((char*)buf)+res; + buf = ((char*)buf) + res; count -= res; alreadyRead += res; } @@ -284,17 +284,17 @@ static inline unsigned long long LinuxProcess_adjustTime(unsigned long long t) { return t * jiffytime * 100; } -static bool LinuxProcessList_readStatFile(Process *process, const char* dirname, const char* name, char* command, int* commLen) { +static bool LinuxProcessList_readStatFile(Process* process, const char* dirname, const char* name, char* command, int* commLen) { LinuxProcess* lp = (LinuxProcess*) process; const int commLenIn = *commLen; *commLen = 0; - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; xSnprintf(filename, MAX_NAME, "%s/%s/stat", dirname, name); int fd = open(filename, O_RDONLY); if (fd == -1) return false; - static char buf[MAX_READ+1]; + static char buf[MAX_READ + 1]; int size = xread(fd, buf, MAX_READ); close(fd); @@ -302,11 +302,11 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname, buf[size] = '\0'; assert(process->pid == atoi(buf)); - char *location = strchr(buf, ' '); + char* location = strchr(buf, ' '); if (!location) return false; location += 2; - char *end = strrchr(location, ')'); + char* end = strrchr(location, ')'); if (!end) return false; int commsize = MINIMUM(end - location, commLenIn - 1); @@ -352,14 +352,15 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname, location += 1; process->nlwp = strtol(location, &location, 10); location += 1; - location = strchr(location, ' ')+1; + location = strchr(location, ' ') + 1; if (process->starttime_ctime == 0) { process->starttime_ctime = btime + LinuxProcess_adjustTime(strtoll(location, &location, 10)) / 100; } else { - location = strchr(location, ' ')+1; + location = strchr(location, ' ') + 1; } location += 1; - for (int i=0; i<15; i++) location = strchr(location, ' ')+1; + for (int i = 0; i < 15; i++) + location = strchr(location, ' ') + 1; process->exit_signal = strtol(location, &location, 10); location += 1; assert(location != NULL); @@ -372,7 +373,7 @@ static bool LinuxProcessList_readStatFile(Process *process, const char* dirname, static bool LinuxProcessList_statProcessDir(Process* process, const char* dirname, char* name) { - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; filename[MAX_NAME] = '\0'; xSnprintf(filename, MAX_NAME, "%s/%s", dirname, name); @@ -387,7 +388,7 @@ static bool LinuxProcessList_statProcessDir(Process* process, const char* dirnam #ifdef HAVE_TASKSTATS static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirname, char* name, unsigned long long now) { - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; filename[MAX_NAME] = '\0'; xSnprintf(filename, MAX_NAME, "%s/%s/io", dirname, name); @@ -414,8 +415,8 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna buffer[buflen] = '\0'; unsigned long long last_read = process->io_read_bytes; unsigned long long last_write = process->io_write_bytes; - char *buf = buffer; - char *line = NULL; + char* buf = buffer; + char* line = NULL; while ((line = strsep(&buf, "\n")) != NULL) { switch (line[0]) { case 'r': @@ -424,7 +425,7 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna } else if (String_startsWith(line + 1, "ead_bytes: ")) { process->io_read_bytes = strtoull(line + 12, NULL, 10); process->io_rate_read_bps = - ((double)(process->io_read_bytes - last_read))/(((double)(now - process->io_rate_read_time))/1000); + ((double)(process->io_read_bytes - last_read)) / (((double)(now - process->io_rate_read_time)) / 1000); process->io_rate_read_time = now; } break; @@ -434,15 +435,15 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna } else if (String_startsWith(line + 1, "rite_bytes: ")) { process->io_write_bytes = strtoull(line + 13, NULL, 10); process->io_rate_write_bps = - ((double)(process->io_write_bytes - last_write))/(((double)(now - process->io_rate_write_time))/1000); + ((double)(process->io_write_bytes - last_write)) / (((double)(now - process->io_rate_write_time)) / 1000); process->io_rate_write_time = now; } break; case 's': - if (line[4] == 'r' && String_startsWith(line+1, "yscr: ")) { - process->io_syscr = strtoull(line+7, NULL, 10); - } else if (String_startsWith(line+1, "yscw: ")) { - process->io_syscw = strtoull(line+7, NULL, 10); + if (line[4] == 'r' && String_startsWith(line + 1, "yscr: ")) { + process->io_syscr = strtoull(line + 7, NULL, 10); + } else if (String_startsWith(line + 1, "yscw: ")) { + process->io_syscw = strtoull(line + 7, NULL, 10); } break; case 'c': @@ -458,7 +459,7 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna static bool LinuxProcessList_readStatmFile(LinuxProcess* process, const char* dirname, const char* name) { - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; xSnprintf(filename, sizeof(filename), "%s/%s/statm", dirname, name); FILE* statmfile = fopen(filename, "r"); if (!statmfile) @@ -529,7 +530,7 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d return; } - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; xSnprintf(filename, sizeof(filename), "%s/%s/status", dirname, name); FILE* file = fopen(filename, "r"); if (!file) { @@ -618,7 +619,7 @@ static void LinuxProcessList_readOpenVZData(LinuxProcess* process, const char* d #ifdef HAVE_CGROUP static void LinuxProcessList_readCGroupFile(LinuxProcess* process, const char* dirname, const char* name) { - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; xSnprintf(filename, MAX_NAME, "%s/%s/cgroup", dirname, name); FILE* file = fopen(filename, "r"); if (!file) { @@ -634,7 +635,7 @@ static void LinuxProcessList_readCGroupFile(LinuxProcess* process, const char* d int left = PROC_LINE_LENGTH; while (!feof(file) && left > 0) { char buffer[PROC_LINE_LENGTH + 1]; - char *ok = fgets(buffer, PROC_LINE_LENGTH, file); + char* ok = fgets(buffer, PROC_LINE_LENGTH, file); if (!ok) break; char* group = strchr(buffer, ':'); if (!group) break; @@ -656,7 +657,7 @@ static void LinuxProcessList_readCGroupFile(LinuxProcess* process, const char* d #ifdef HAVE_VSERVER static void LinuxProcessList_readVServerData(LinuxProcess* process, const char* dirname, const char* name) { - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; xSnprintf(filename, MAX_NAME, "%s/%s/status", dirname, name); FILE* file = fopen(filename, "r"); if (!file) @@ -687,7 +688,7 @@ static void LinuxProcessList_readVServerData(LinuxProcess* process, const char* #endif static void LinuxProcessList_readOomData(LinuxProcess* process, const char* dirname, const char* name) { - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; xSnprintf(filename, MAX_NAME, "%s/%s/oom_score", dirname, name); FILE* file = fopen(filename, "r"); if (!file) { @@ -705,7 +706,7 @@ static void LinuxProcessList_readOomData(LinuxProcess* process, const char* dirn } static void LinuxProcessList_readCtxtData(LinuxProcess* process, const char* dirname, const char* name) { - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; xSnprintf(filename, MAX_NAME, "%s/%s/status", dirname, name); FILE* file = fopen(filename, "r"); if (!file) @@ -731,7 +732,7 @@ static void LinuxProcessList_readCtxtData(LinuxProcess* process, const char* dir } static void LinuxProcessList_readSecattrData(LinuxProcess* process, const char* dirname, const char* name) { - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; xSnprintf(filename, sizeof(filename), "%s/%s/attr/current", dirname, name); FILE* file = fopen(filename, "r"); if (!file) { @@ -740,14 +741,14 @@ static void LinuxProcessList_readSecattrData(LinuxProcess* process, const char* return; } char buffer[PROC_LINE_LENGTH + 1]; - char *res = fgets(buffer, sizeof(buffer), file); + char* res = fgets(buffer, sizeof(buffer), file); fclose(file); if (!res) { free(process->secattr); process->secattr = NULL; return; } - char *newline = strchr(buffer, '\n'); + char* newline = strchr(buffer, '\n'); if (newline) *newline = '\0'; if (process->secattr && String_eq(process->secattr, buffer)) @@ -758,10 +759,10 @@ static void LinuxProcessList_readSecattrData(LinuxProcess* process, const char* #ifdef HAVE_DELAYACCT -static int handleNetlinkMsg(struct nl_msg *nlmsg, void *linuxProcess) { - struct nlmsghdr *nlhdr; - struct nlattr *nlattrs[TASKSTATS_TYPE_MAX + 1]; - struct nlattr *nlattr; +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; @@ -777,24 +778,25 @@ static int handleNetlinkMsg(struct nl_msg *nlmsg, void *linuxProcess) { memcpy(&stats, nla_data(nla_next(nla_data(nlattr), &rem)), sizeof(stats)); assert(lp->super.pid == (pid_t)stats.ac_pid); - timeDelta = (stats.ac_etime*1000 - lp->delay_read_time); - #define BOUNDS(x) isnan(x) ? 0.0 : ((x) > 100) ? 100.0 : (x) + 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; + lp->delay_read_time = stats.ac_etime * 1000; } return NL_OK; } static void LinuxProcessList_readDelayAcctData(LinuxProcessList* this, LinuxProcess* process) { - struct nl_msg *msg; + struct nl_msg* msg; if (nl_socket_modify_cb(this->netlink_socket, NL_CB_VALID, NL_CB_CUSTOM, handleNetlinkMsg, process) < 0) { return; @@ -837,13 +839,13 @@ static void setCommand(Process* process, const char* command, int len) { } static bool LinuxProcessList_readCmdlineFile(Process* process, const char* dirname, const char* name) { - char filename[MAX_NAME+1]; + char filename[MAX_NAME + 1]; xSnprintf(filename, MAX_NAME, "%s/%s/cmdline", dirname, name); int fd = open(filename, O_RDONLY); if (fd == -1) return false; - char command[4096+1]; // max cmdline length on Linux + char command[4096 + 1]; // max cmdline length on Linux int amtRead = xread(fd, command, sizeof(command) - 1); close(fd); int tokenEnd = 0; @@ -927,7 +929,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* const Settings* settings = pl->settings; #ifdef HAVE_TASKSTATS - unsigned long long now = tv.tv_sec*1000LL+tv.tv_usec/1000LL; + unsigned long long now = tv.tv_sec * 1000LL + tv.tv_usec / 1000LL; #endif dir = opendir(dirname); @@ -964,7 +966,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* LinuxProcess* lp = (LinuxProcess*) proc; - char subdirname[MAX_NAME+1]; + char subdirname[MAX_NAME + 1]; xSnprintf(subdirname, MAX_NAME, "%s/%s/task", dirname, name); LinuxProcessList_recurseProcTree(this, subdirname, proc, period, tv); @@ -976,11 +978,11 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* if (! LinuxProcessList_readStatmFile(lp, dirname, name)) goto errorReadingProcess; - if ((settings->flags & PROCESS_FLAG_LINUX_SMAPS) && !Process_isKernelThread(proc)){ - if (!parent){ + if ((settings->flags & PROCESS_FLAG_LINUX_SMAPS) && !Process_isKernelThread(proc)) { + if (!parent) { // Read smaps file of each process only every second pass to improve performance static int smaps_flag = 0; - if ((pid & 1) == smaps_flag){ + if ((pid & 1) == smaps_flag) { LinuxProcessList_readSmapsFile(lp, dirname, name, this->haveSmapsRollup); } if (pid == 1) { @@ -993,7 +995,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* proc->show = ! ((hideKernelThreads && Process_isKernelThread(proc)) || (hideUserlandThreads && Process_isUserlandThread(proc))); - char command[MAX_NAME+1]; + char command[MAX_NAME + 1]; unsigned long long int lasttimes = (lp->utime + lp->stime); int commLen = sizeof(command); unsigned int tty_nr = proc->tty_nr; diff --git a/linux/LinuxProcessList.h b/linux/LinuxProcessList.h index 1795543f..6ecf2103 100644 --- a/linux/LinuxProcessList.h +++ b/linux/LinuxProcessList.h @@ -64,7 +64,7 @@ typedef struct LinuxProcessList_ { bool haveSmapsRollup; #ifdef HAVE_DELAYACCT - struct nl_sock *netlink_socket; + struct nl_sock* netlink_socket; int netlink_family; #endif diff --git a/linux/Platform.c b/linux/Platform.c index 674952b0..3da3f029 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -169,8 +169,11 @@ int Platform_getUptime() { void Platform_getLoadAverage(double* one, double* five, double* fifteen) { int activeProcs, totalProcs, lastProc; - *one = 0; *five = 0; *fifteen = 0; - FILE *fd = fopen(PROCDIR "/loadavg", "r"); + *one = 0; + *five = 0; + *fifteen = 0; + + FILE* fd = fopen(PROCDIR "/loadavg", "r"); if (fd) { int total = fscanf(fd, "%32lf %32lf %32lf %32d/%32d %32d", one, five, fifteen, &activeProcs, &totalProcs, &lastProc); @@ -207,15 +210,15 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[CPU_METER_IOWAIT] = cpuData->ioWaitPeriod / total * 100.0; this->curItems = 8; if (this->pl->settings->accountGuestInCPUMeter) { - percent = v[0]+v[1]+v[2]+v[3]+v[4]+v[5]+v[6]; + percent = v[0] + v[1] + v[2] + v[3] + v[4] + v[5] + v[6]; } else { - percent = v[0]+v[1]+v[2]+v[3]+v[4]; + percent = v[0] + v[1] + v[2] + v[3] + v[4]; } } else { v[2] = cpuData->systemAllPeriod / total * 100.0; v[3] = (cpuData->stealPeriod + cpuData->guestPeriod) / total * 100.0; this->curItems = 4; - percent = v[0]+v[1]+v[2]+v[3]; + percent = v[0] + v[1] + v[2] + v[3]; } percent = CLAMP(percent, 0.0, 100.0); if (isnan(percent)) percent = 0.0; @@ -275,7 +278,7 @@ char* Platform_getProcessEnv(pid_t pid) { if (!fd) return NULL; - char *env = NULL; + char* env = NULL; size_t capacity = 0; size_t size = 0; @@ -299,16 +302,16 @@ char* Platform_getProcessEnv(pid_t pid) { env = xRealloc(env, size + 2); env[size] = '\0'; - env[size+1] = '\0'; + env[size + 1] = '\0'; return env; } -void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred) { +void Platform_getPressureStall(const char* file, bool some, double* ten, double* sixty, double* threehundred) { *ten = *sixty = *threehundred = 0; - char procname[128+1]; + char procname[128 + 1]; xSnprintf(procname, 128, PROCDIR "/pressure/%s", file); - FILE *fd = fopen(procname, "r"); + FILE* fd = fopen(procname, "r"); if (!fd) { *ten = *sixty = *threehundred = NAN; return; @@ -323,7 +326,7 @@ void Platform_getPressureStall(const char *file, bool some, double* ten, double* } bool Platform_getDiskIO(DiskIOData* data) { - FILE *fd = fopen(PROCDIR "/diskstats", "r"); + FILE* fd = fopen(PROCDIR "/diskstats", "r"); if (!fd) return false; @@ -367,11 +370,11 @@ bool Platform_getDiskIO(DiskIOData* data) { return true; } -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted) { - FILE *fd = fopen(PROCDIR "/net/dev", "r"); +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted) { + FILE* fd = fopen(PROCDIR "/net/dev", "r"); if (!fd) return false; diff --git a/linux/Platform.h b/linux/Platform.h index b61a4db8..8b2b3bb9 100644 --- a/linux/Platform.h +++ b/linux/Platform.h @@ -47,13 +47,13 @@ void Platform_setZfsArcValues(Meter* this); void Platform_setZfsCompressedArcValues(Meter* this); char* Platform_getProcessEnv(pid_t pid); -void Platform_getPressureStall(const char *file, bool some, double* ten, double* sixty, double* threehundred); +void Platform_getPressureStall(const char* file, bool some, double* ten, double* sixty, double* threehundred); bool Platform_getDiskIO(DiskIOData* data); -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted); +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted); #endif diff --git a/openbsd/Battery.c b/openbsd/Battery.c index 232b1255..b72253e0 100644 --- a/openbsd/Battery.c +++ b/openbsd/Battery.c @@ -53,7 +53,7 @@ void Battery_getData(double* level, ACPresence* isOnAC) { mib[4] = 3; if (sysctl(mib, 5, &s, &slen, NULL, 0) != -1) { double charge = s.value; - *level = 100*(charge / last_full_capacity); + *level = 100 * (charge / last_full_capacity); if (charge >= last_full_capacity) { *level = 100; } diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index 86e2dca6..bfac535d 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -56,7 +56,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui } for (i = 0; i <= pl->cpuCount; i++) { - CPUData *d = opl->cpus + i; + CPUData* d = opl->cpus + i; d->totalTime = 1; d->totalPeriod = 1; } @@ -134,7 +134,7 @@ static inline void OpenBSDProcessList_scanMemoryInfo(ProcessList* pl) { */ } -char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) { +char* OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) { char *s, **arg; size_t len = 0, n; int i; @@ -163,7 +163,7 @@ char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in n = strlcat(s, arg[i], len); if (i == 0) { /* TODO: rename all basenameEnd to basenameLen, make size_t */ - *basenameEnd = MINIMUM(n, len-1); + *basenameEnd = MINIMUM(n, len - 1); } /* the trailing space should get truncated anyway */ strlcat(s, " ", len); @@ -175,9 +175,9 @@ char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, in /* * Taken from OpenBSD's ps(1). */ -static double getpcpu(const struct kinfo_proc *kp) { +static double getpcpu(const struct kinfo_proc* kp) { if (fscale == 0) - return (0.0); + return 0.0; #define fxtofl(fixpt) ((double)(fixpt) / fscale) @@ -232,7 +232,7 @@ static inline void OpenBSDProcessList_scanProcs(OpenBSDProcessList* this) { proc->m_size = kproc->p_vm_dsize; proc->m_resident = kproc->p_vm_rssize; proc->percent_mem = (proc->m_resident * CRT_pageSizeKB) / (double)(this->super.totalMem) * 100.0; - proc->percent_cpu = CLAMP(getpcpu(kproc), 0.0, this->super.cpuCount*100.0); + proc->percent_cpu = CLAMP(getpcpu(kproc), 0.0, this->super.cpuCount * 100.0); //proc->nlwp = kproc->p_numthreads; //proc->time = kproc->p_rtime_sec + ((kproc->p_rtime_usec + 500000) / 10); proc->nice = kproc->p_nice - 20; diff --git a/openbsd/OpenBSDProcessList.h b/openbsd/OpenBSDProcessList.h index 7ee48c63..1b40faf1 100644 --- a/openbsd/OpenBSDProcessList.h +++ b/openbsd/OpenBSDProcessList.h @@ -43,7 +43,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui void ProcessList_delete(ProcessList* this); -char *OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd); +char* OpenBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd); void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); diff --git a/openbsd/Platform.c b/openbsd/Platform.c index d9737c39..21a33d1e 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -162,7 +162,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { const CPUData* cpuData = &(pl->cpus[cpu]); double total = cpuData->totalPeriod == 0 ? 1 : cpuData->totalPeriod; double totalPercent; - double *v = this->values; + double* v = this->values; v[CPU_METER_NICE] = cpuData->nicePeriod / total * 100.0; v[CPU_METER_NORMAL] = cpuData->userPeriod / total * 100.0; @@ -175,11 +175,11 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[CPU_METER_IOWAIT] = 0.0; v[CPU_METER_FREQUENCY] = NAN; this->curItems = 8; - totalPercent = v[0]+v[1]+v[2]+v[3]; + totalPercent = v[0] + v[1] + v[2] + v[3]; } else { v[2] = cpuData->sysAllPeriod / total * 100.0; v[3] = 0.0; // No steal nor guest on OpenBSD - totalPercent = v[0]+v[1]+v[2]; + totalPercent = v[0] + v[1] + v[2]; this->curItems = 4; } @@ -208,7 +208,7 @@ void Platform_setMemoryValues(Meter* this) { */ void Platform_setSwapValues(Meter* this) { const ProcessList* pl = this->pl; - struct swapent *swdev; + struct swapent* swdev; unsigned long long int total, used; int nswap, rnswap, i; nswap = swapctl(SWAP_NSWAP, 0, 0); @@ -243,11 +243,11 @@ void Platform_setSwapValues(Meter* this) { char* Platform_getProcessEnv(pid_t pid) { char errbuf[_POSIX2_LINE_MAX]; - char *env; - char **ptr; + char* env; + char** ptr; int count; - kvm_t *kt; - struct kinfo_proc *kproc; + kvm_t* kt; + struct kinfo_proc* kproc; size_t capacity = 4096, size = 0; if ((kt = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf)) == NULL) @@ -265,7 +265,7 @@ char* Platform_getProcessEnv(pid_t pid) { } env = xMalloc(capacity); - for (char **p = ptr; *p; p++) { + for (char** p = ptr; *p; p++) { size_t len = strlen(*p) + 1; if (size + len > capacity) { @@ -294,10 +294,10 @@ bool Platform_getDiskIO(DiskIOData* data) { return false; } -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted) { +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted) { // TODO *bytesReceived = 0; *packetsReceived = 0; diff --git a/openbsd/Platform.h b/openbsd/Platform.h index 8cb5bdf3..7e3261a9 100644 --- a/openbsd/Platform.h +++ b/openbsd/Platform.h @@ -44,9 +44,9 @@ char* Platform_getProcessEnv(pid_t pid); bool Platform_getDiskIO(DiskIOData* data); -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted); +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted); #endif diff --git a/solaris/Platform.c b/solaris/Platform.c index be2d25ed..69777726 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -130,7 +130,7 @@ extern char Process_pidFormat[20]; int Platform_getUptime() { int boot_time = 0; int curr_time = time(NULL); - struct utmpx * ent; + struct utmpx* ent; while (( ent = getutxent() )) { if ( !strcmp("system boot", ent->ut_line )) { @@ -140,7 +140,7 @@ int Platform_getUptime() { endutxent(); - return (curr_time-boot_time); + return (curr_time - boot_time); } void Platform_getLoadAverage(double* one, double* five, double* fifteen) { @@ -151,9 +151,9 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { } int Platform_getMaxPid() { - kstat_ctl_t *kc = NULL; - kstat_t *kshandle = NULL; - kvar_t *ksvar = NULL; + kstat_ctl_t* kc = NULL; + kstat_t* kshandle = NULL; + kvar_t* ksvar = NULL; int vproc = 32778; // Reasonable Solaris default kc = kstat_open(); if (kc != NULL) { kshandle = kstat_lookup(kc,"unix",0,"var"); } @@ -187,11 +187,11 @@ double Platform_setCPUValues(Meter* this, int cpu) { v[CPU_METER_KERNEL] = cpuData->systemPercent; v[CPU_METER_IRQ] = cpuData->irqPercent; this->curItems = 4; - percent = v[0]+v[1]+v[2]+v[3]; + percent = v[0] + v[1] + v[2] + v[3]; } else { v[2] = cpuData->systemAllPercent; this->curItems = 3; - percent = v[0]+v[1]+v[2]; + percent = v[0] + v[1] + v[2]; } percent = CLAMP(percent, 0.0, 100.0); @@ -228,8 +228,8 @@ void Platform_setZfsCompressedArcValues(Meter* this) { ZfsCompressedArcMeter_readStats(this, &(spl->zfs)); } -static int Platform_buildenv(void *accum, struct ps_prochandle *Phandle, uintptr_t addr, const char *str) { - envAccum *accump = accum; +static int Platform_buildenv(void* accum, struct ps_prochandle* Phandle, uintptr_t addr, const char* str) { + envAccum* accump = accum; (void) Phandle; (void) addr; size_t thissz = strlen(str); @@ -247,16 +247,16 @@ char* Platform_getProcessEnv(pid_t pid) { envAccum envBuilder; pid_t realpid = pid / 1024; int graberr; - struct ps_prochandle *Phandle; + struct ps_prochandle* Phandle; - if ((Phandle = Pgrab(realpid,PGRAB_RDONLY,&graberr)) == NULL) + if ((Phandle = Pgrab(realpid, PGRAB_RDONLY, &graberr)) == NULL) return "Unable to read process environment."; envBuilder.capacity = 4096; envBuilder.size = 0; envBuilder.env = xMalloc(envBuilder.capacity); - (void) Penv_iter(Phandle,Platform_buildenv,&envBuilder); + (void) Penv_iter(Phandle, Platform_buildenv, &envBuilder); Prelease(Phandle, 0); @@ -270,10 +270,10 @@ bool Platform_getDiskIO(DiskIOData* data) { return false; } -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted) { +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted) { // TODO *bytesReceived = 0; *packetsReceived = 0; diff --git a/solaris/Platform.h b/solaris/Platform.h index 8718dbfe..701bc77d 100644 --- a/solaris/Platform.h +++ b/solaris/Platform.h @@ -27,7 +27,7 @@ typedef struct envAccum_ { size_t capacity; size_t size; size_t bytes; - char *env; + char* env; } envAccum; extern double plat_loadavg[3]; @@ -66,9 +66,9 @@ char* Platform_getProcessEnv(pid_t pid); bool Platform_getDiskIO(DiskIOData* data); -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted); +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted); #endif diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index cbef6c8f..31507506 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -64,12 +64,12 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) { const SolarisProcessList* spl = (SolarisProcessList*) pl; int cpus = pl->cpuCount; - kstat_t *cpuinfo = NULL; + kstat_t* cpuinfo = NULL; int kchain = 0; - kstat_named_t *idletime = NULL; - kstat_named_t *intrtime = NULL; - kstat_named_t *krnltime = NULL; - kstat_named_t *usertime = NULL; + kstat_named_t* idletime = NULL; + kstat_named_t* intrtime = NULL; + kstat_named_t* krnltime = NULL; + kstat_named_t* usertime = NULL; double idlebuf = 0; double intrbuf = 0; double krnlbuf = 0; @@ -94,16 +94,16 @@ static inline void SolarisProcessList_scanCPUTime(ProcessList* pl) { kchain = kstat_read(spl->kd, cpuinfo, NULL); } if (kchain != -1 ) { - idletime = kstat_data_lookup(cpuinfo,"cpu_nsec_idle"); - intrtime = kstat_data_lookup(cpuinfo,"cpu_nsec_intr"); - krnltime = kstat_data_lookup(cpuinfo,"cpu_nsec_kernel"); - usertime = kstat_data_lookup(cpuinfo,"cpu_nsec_user"); + idletime = kstat_data_lookup(cpuinfo, "cpu_nsec_idle"); + intrtime = kstat_data_lookup(cpuinfo, "cpu_nsec_intr"); + krnltime = kstat_data_lookup(cpuinfo, "cpu_nsec_kernel"); + usertime = kstat_data_lookup(cpuinfo, "cpu_nsec_user"); } assert( (idletime != NULL) && (intrtime != NULL) && (krnltime != NULL) && (usertime != NULL) ); - CPUData* cpuData = &(spl->cpus[i+arrskip]); + CPUData* cpuData = &(spl->cpus[i + arrskip]); totaltime = (idletime->value.ui64 - cpuData->lidle) + (intrtime->value.ui64 - cpuData->lintr) + (krnltime->value.ui64 - cpuData->lkrnl) @@ -158,9 +158,11 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { // Part 1 - physical memory if (spl->kd != NULL && meminfo == NULL) { // Look up the kstat chain just one, it never changes - meminfo = kstat_lookup(spl->kd,"unix",0,"system_pages"); + meminfo = kstat_lookup(spl->kd, "unix", 0, "system_pages"); + } + if (meminfo != NULL) { + ksrphyserr = kstat_read(spl->kd, meminfo, NULL); } - if (meminfo != NULL) { ksrphyserr = kstat_read(spl->kd,meminfo,NULL); } if (ksrphyserr != -1) { totalmem_pgs = kstat_data_lookup(meminfo, "physmem"); freemem_pgs = kstat_data_lookup(meminfo, "freemem"); @@ -276,13 +278,13 @@ void ProcessList_delete(ProcessList* pl) { * system for more info. */ -int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *listptr) { +int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo, void* listptr) { bool preExisting; pid_t getpid; // Setup process list - ProcessList *pl = (ProcessList*) listptr; - SolarisProcessList *spl = (SolarisProcessList*) listptr; + ProcessList* pl = (ProcessList*) listptr; + SolarisProcessList* spl = (SolarisProcessList*) listptr; id_t lwpid_real = _lwpsinfo->pr_lwpid; if (lwpid_real > 1023) return 0; @@ -293,8 +295,8 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * } else { getpid = lwpid; } - Process *proc = ProcessList_getProcess(pl, getpid, &preExisting, SolarisProcess_new); - SolarisProcess *sproc = (SolarisProcess*) proc; + Process* proc = ProcessList_getProcess(pl, getpid, &preExisting, SolarisProcess_new); + SolarisProcess* sproc = (SolarisProcess*) proc; // Common code pass 1 proc->show = false; @@ -309,22 +311,22 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * // NOTE: This 'percentage' is a 16-bit BINARY FRACTIONS where 1.0 = 0x8000 // Source: https://docs.oracle.com/cd/E19253-01/816-5174/proc-4/index.html // (accessed on 18 November 2017) - proc->percent_mem = ((uint16_t)_psinfo->pr_pctmem/(double)32768)*(double)100.0; + proc->percent_mem = ((uint16_t)_psinfo->pr_pctmem / (double)32768) * (double)100.0; proc->st_uid = _psinfo->pr_euid; proc->pgrp = _psinfo->pr_pgid; proc->nlwp = _psinfo->pr_nlwp; proc->tty_nr = _psinfo->pr_ttydev; - proc->m_resident = _psinfo->pr_rssize/CRT_pageSizeKB; - proc->m_size = _psinfo->pr_size/CRT_pageSizeKB; + proc->m_resident = _psinfo->pr_rssize / CRT_pageSizeKB; + proc->m_size = _psinfo->pr_size / CRT_pageSizeKB; if (!preExisting) { sproc->realpid = _psinfo->pr_pid; sproc->lwpid = lwpid_real; sproc->zoneid = _psinfo->pr_zoneid; - sproc->zname = SolarisProcessList_readZoneName(spl->kd,sproc); + sproc->zname = SolarisProcessList_readZoneName(spl->kd, sproc); proc->user = UsersTable_getRef(pl->usersTable, proc->st_uid); proc->comm = xStrdup(_psinfo->pr_fname); - proc->commLen = strnlen(_psinfo->pr_fname,PRFNSZ); + proc->commLen = strnlen(_psinfo->pr_fname, PRFNSZ); } // End common code pass 1 @@ -334,7 +336,7 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * proc->tgid = (_psinfo->pr_ppid * 1024); sproc->realppid = _psinfo->pr_ppid; // See note above (in common section) about this BINARY FRACTION - proc->percent_cpu = ((uint16_t)_psinfo->pr_pctcpu/(double)32768)*(double)100.0; + proc->percent_cpu = ((uint16_t)_psinfo->pr_pctcpu / (double)32768) * (double)100.0; proc->time = _psinfo->pr_time.tv_sec; if (!preExisting) { // Tasks done only for NEW processes sproc->is_lwp = false; @@ -344,7 +346,7 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * // Update proc and thread counts based on settings if (sproc->kernel && !pl->settings->hideKernelThreads) { pl->kernelThreads += proc->nlwp; - pl->totalTasks += proc->nlwp+1; + pl->totalTasks += proc->nlwp + 1; if (proc->state == 'O') pl->runningTasks++; } else if (!sproc->kernel) { if (proc->state == 'O') pl->runningTasks++; @@ -352,12 +354,12 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * pl->totalTasks++; } else { pl->userlandThreads += proc->nlwp; - pl->totalTasks += proc->nlwp+1; + pl->totalTasks += proc->nlwp + 1; } } proc->show = !(pl->settings->hideKernelThreads && sproc->kernel); } else { // We are not in the master LWP, so jump to the LWP handling code - proc->percent_cpu = ((uint16_t)_lwpsinfo->pr_pctcpu/(double)32768)*(double)100.0; + proc->percent_cpu = ((uint16_t)_lwpsinfo->pr_pctcpu / (double)32768) * (double)100.0; proc->time = _lwpsinfo->pr_time.tv_sec; if (!preExisting) { // Tasks done only for NEW LWPs sproc->is_lwp = true; @@ -369,8 +371,12 @@ int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void * } // Top-level process only gets this for the representative LWP - if (sproc->kernel && !pl->settings->hideKernelThreads) proc->show = true; - if (!sproc->kernel && !pl->settings->hideUserlandThreads) proc->show = true; + if (sproc->kernel && !pl->settings->hideKernelThreads) { + proc->show = true; + } + if (!sproc->kernel && !pl->settings->hideUserlandThreads) { + proc->show = true; + } } // Top-level LWP or subordinate LWP // Common code pass 2 diff --git a/solaris/SolarisProcessList.h b/solaris/SolarisProcessList.h index 3a653eed..f800d9da 100644 --- a/solaris/SolarisProcessList.h +++ b/solaris/SolarisProcessList.h @@ -58,7 +58,7 @@ void ProcessList_delete(ProcessList* pl); * system for more info. */ -int SolarisProcessList_walkproc(psinfo_t *_psinfo, lwpsinfo_t *_lwpsinfo, void *listptr); +int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo, void* listptr); void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); diff --git a/unsupported/Platform.c b/unsupported/Platform.c index 3f8cefa6..afc5bf35 100644 --- a/unsupported/Platform.c +++ b/unsupported/Platform.c @@ -146,10 +146,10 @@ bool Platform_getDiskIO(DiskIOData* data) { return false; } -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted) { +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted) { *bytesReceived = 0; *packetsReceived = 0; *bytesTransmitted = 0; diff --git a/unsupported/Platform.h b/unsupported/Platform.h index 902b6a9b..91ac7481 100644 --- a/unsupported/Platform.h +++ b/unsupported/Platform.h @@ -50,9 +50,9 @@ char* Platform_getProcessEnv(pid_t pid); bool Platform_getDiskIO(DiskIOData* data); -bool Platform_getNetworkIO(unsigned long int *bytesReceived, - unsigned long int *packetsReceived, - unsigned long int *bytesTransmitted, - unsigned long int *packetsTransmitted); +bool Platform_getNetworkIO(unsigned long int* bytesReceived, + unsigned long int* packetsReceived, + unsigned long int* bytesTransmitted, + unsigned long int* packetsTransmitted); #endif diff --git a/zfs/ZfsCompressedArcMeter.c b/zfs/ZfsCompressedArcMeter.c index 993d80e2..d0278a9d 100644 --- a/zfs/ZfsCompressedArcMeter.c +++ b/zfs/ZfsCompressedArcMeter.c @@ -33,7 +33,7 @@ void ZfsCompressedArcMeter_readStats(Meter* this, const ZfsArcStats* stats) { } static void ZfsCompressedArcMeter_printRatioString(const Meter* this, char* buffer, int size) { - xSnprintf(buffer, size, "%.2f:1", this->total/this->values[0]); + xSnprintf(buffer, size, "%.2f:1", this->total / this->values[0]); } static void ZfsCompressedArcMeter_updateValues(Meter* this, char* buffer, int size) { diff --git a/zfs/openzfs_sysctl.c b/zfs/openzfs_sysctl.c index c09d48df..59d7469f 100644 --- a/zfs/openzfs_sysctl.c +++ b/zfs/openzfs_sysctl.c @@ -27,7 +27,7 @@ static int MIB_kstat_zfs_misc_arcstats_uncompressed_size[5]; #include "zfs/ZfsArcStats.h" }*/ -void openzfs_sysctl_init(ZfsArcStats *stats) { +void openzfs_sysctl_init(ZfsArcStats* stats) { size_t len; unsigned long long int arcSize; @@ -56,45 +56,45 @@ void openzfs_sysctl_init(ZfsArcStats *stats) { } } -void openzfs_sysctl_updateArcStats(ZfsArcStats *stats) { +void openzfs_sysctl_updateArcStats(ZfsArcStats* stats) { size_t len; if (stats->enabled) { len = sizeof(stats->size); - sysctl(MIB_kstat_zfs_misc_arcstats_size, 5, &(stats->size), &len , NULL, 0); + sysctl(MIB_kstat_zfs_misc_arcstats_size, 5, &(stats->size), &len, NULL, 0); stats->size /= 1024; len = sizeof(stats->max); - sysctl(MIB_kstat_zfs_misc_arcstats_c_max, 5, &(stats->max), &len , NULL, 0); + sysctl(MIB_kstat_zfs_misc_arcstats_c_max, 5, &(stats->max), &len, NULL, 0); stats->max /= 1024; len = sizeof(stats->MFU); - sysctl(MIB_kstat_zfs_misc_arcstats_mfu_size, 5, &(stats->MFU), &len , NULL, 0); + sysctl(MIB_kstat_zfs_misc_arcstats_mfu_size, 5, &(stats->MFU), &len, NULL, 0); stats->MFU /= 1024; len = sizeof(stats->MRU); - sysctl(MIB_kstat_zfs_misc_arcstats_mru_size, 5, &(stats->MRU), &len , NULL, 0); + sysctl(MIB_kstat_zfs_misc_arcstats_mru_size, 5, &(stats->MRU), &len, NULL, 0); stats->MRU /= 1024; len = sizeof(stats->anon); - sysctl(MIB_kstat_zfs_misc_arcstats_anon_size, 5, &(stats->anon), &len , NULL, 0); + sysctl(MIB_kstat_zfs_misc_arcstats_anon_size, 5, &(stats->anon), &len, NULL, 0); stats->anon /= 1024; len = sizeof(stats->header); - sysctl(MIB_kstat_zfs_misc_arcstats_hdr_size, 5, &(stats->header), &len , NULL, 0); + sysctl(MIB_kstat_zfs_misc_arcstats_hdr_size, 5, &(stats->header), &len, NULL, 0); stats->header /= 1024; len = sizeof(stats->other); - sysctl(MIB_kstat_zfs_misc_arcstats_other_size, 5, &(stats->other), &len , NULL, 0); + sysctl(MIB_kstat_zfs_misc_arcstats_other_size, 5, &(stats->other), &len, NULL, 0); stats->other /= 1024; if (stats->isCompressed) { len = sizeof(stats->compressed); - sysctl(MIB_kstat_zfs_misc_arcstats_compressed_size, 5, &(stats->compressed), &len , NULL, 0); + sysctl(MIB_kstat_zfs_misc_arcstats_compressed_size, 5, &(stats->compressed), &len, NULL, 0); stats->compressed /= 1024; len = sizeof(stats->uncompressed); - sysctl(MIB_kstat_zfs_misc_arcstats_uncompressed_size, 5, &(stats->uncompressed), &len , NULL, 0); + sysctl(MIB_kstat_zfs_misc_arcstats_uncompressed_size, 5, &(stats->uncompressed), &len, NULL, 0); stats->uncompressed /= 1024; } } diff --git a/zfs/openzfs_sysctl.h b/zfs/openzfs_sysctl.h index 1bc5d3e0..b49128e3 100644 --- a/zfs/openzfs_sysctl.h +++ b/zfs/openzfs_sysctl.h @@ -9,8 +9,8 @@ in the source distribution for its full text. #include "zfs/ZfsArcStats.h" -void openzfs_sysctl_init(ZfsArcStats *stats); +void openzfs_sysctl_init(ZfsArcStats* stats); -void openzfs_sysctl_updateArcStats(ZfsArcStats *stats); +void openzfs_sysctl_updateArcStats(ZfsArcStats* stats); #endif From 45869513bfebba80cc2ab42e4218f68b34b1e6ac Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sun, 1 Nov 2020 01:09:51 +0100 Subject: [PATCH 12/17] Embracing branches --- Action.c | 64 ++++++++--- Affinity.c | 7 +- AffinityPanel.c | 33 ++++-- CPUMeter.c | 3 + CRT.c | 16 ++- CategoriesPanel.c | 1 + CheckItem.c | 15 ++- ColorsPanel.c | 1 + CommandScreen.c | 4 +- FunctionBar.c | 10 +- Hashtable.c | 9 +- Header.c | 9 +- IncSet.c | 37 +++++-- InfoScreen.c | 11 +- MainPanel.c | 9 +- Meter.c | 29 +++-- Object.c | 6 +- OpenFilesScreen.c | 14 ++- Panel.c | 22 ++-- Process.c | 43 +++++--- ProcessList.c | 46 ++++++-- RichString.c | 4 +- ScreenManager.c | 52 ++++++--- Settings.c | 16 ++- TraceScreen.c | 12 +- Vector.c | 32 ++++-- darwin/DarwinProcessList.c | 9 +- dragonflybsd/Battery.c | 10 +- dragonflybsd/DragonFlyBSDProcess.c | 5 +- dragonflybsd/DragonFlyBSDProcessList.c | 14 ++- dragonflybsd/Platform.c | 4 +- freebsd/Battery.c | 10 +- freebsd/FreeBSDProcess.c | 5 +- freebsd/FreeBSDProcessList.c | 36 ++++-- htop.c | 19 ++-- linux/Battery.c | 43 ++++++-- linux/IOPriorityPanel.c | 14 ++- linux/LinuxProcess.c | 6 +- linux/LinuxProcessList.c | 146 ++++++++++++++++++------- linux/Platform.c | 21 +++- linux/SELinuxMeter.c | 21 ++-- openbsd/OpenBSDProcessList.c | 3 +- openbsd/Platform.c | 7 +- solaris/Platform.c | 25 +++-- solaris/SolarisProcessList.c | 27 +++-- unsupported/UnsupportedProcessList.c | 3 +- 46 files changed, 656 insertions(+), 277 deletions(-) diff --git a/Action.c b/Action.c index 87901432..8a6e2cbe 100644 --- a/Action.c +++ b/Action.c @@ -65,13 +65,13 @@ Object* Action_pickFromVector(State* st, Panel* list, int x, bool followProcess) Process* selected = (Process*)Panel_getSelected(panel); if (selected && selected->pid == pid) return Panel_getSelected(list); - else - beep(); + + beep(); } else { return Panel_getSelected(list); } - } + return NULL; } @@ -93,7 +93,7 @@ static void Action_runSetup(State* st) { static bool changePriority(MainPanel* panel, int delta) { bool anyTagged; - bool ok = MainPanel_foreachProcess(panel, Process_changePriorityBy, (Arg){ .i = delta }, &anyTagged); + bool ok = MainPanel_foreachProcess(panel, Process_changePriorityBy, (Arg) { .i = delta }, &anyTagged); if (!ok) beep(); return anyTagged; @@ -128,14 +128,18 @@ static void tagAllChildren(Panel* panel, Process* parent) { static bool expandCollapse(Panel* panel) { Process* p = (Process*) Panel_getSelected(panel); - if (!p) return false; + if (!p) + return false; + p->showChildren = !p->showChildren; return true; } static bool collapseIntoParent(Panel* panel) { Process* p = (Process*) Panel_getSelected(panel); - if (!p) return false; + if (!p) + return false; + pid_t ppid = Process_getParentPid(p); for (int i = 0; i < Panel_size(panel); i++) { Process* q = (Process*) Panel_get(panel, i); @@ -165,6 +169,7 @@ static Htop_Reaction sortBy(State* st) { Panel_add(sortPanel, (Object*) ListItem_new(name, fields[i])); if (fields[i] == st->settings->sortKey) Panel_setSelected(sortPanel, i); + free(name); } ListItem* field = (ListItem*) Action_pickFromVector(st, sortPanel, 15, false); @@ -172,8 +177,10 @@ static Htop_Reaction sortBy(State* st) { reaction |= Action_setSortKey(st->settings, field->key); } Object_delete(sortPanel); + if (st->pauseProcessUpdate) ProcessList_sort(st->pl); + return reaction | HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR; } @@ -215,7 +222,10 @@ static Htop_Reaction actionToggleProgramPath(State* st) { static Htop_Reaction actionToggleTreeView(State* st) { st->settings->treeView = !st->settings->treeView; - if (st->settings->treeView) st->settings->direction = 1; + if (st->settings->treeView) { + st->settings->direction = 1; + } + ProcessList_expandTree(st->pl); return HTOP_REFRESH | HTOP_SAVE_SETTINGS | HTOP_KEEP_FOLLOWING | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR; } @@ -286,13 +296,18 @@ static Htop_Reaction actionQuit(ATTR_UNUSED State* st) { static Htop_Reaction actionSetAffinity(State* st) { if (st->pl->cpuCount == 1) return HTOP_OK; + #if (defined(HAVE_LIBHWLOC) || defined(HAVE_LINUX_AFFINITY)) Panel* panel = st->panel; Process* p = (Process*) Panel_getSelected(panel); - if (!p) return HTOP_OK; + if (!p) + return HTOP_OK; + Affinity* affinity1 = Affinity_get(p, st->pl); - if (!affinity1) return HTOP_OK; + if (!affinity1) + return HTOP_OK; + int width; Panel* affinityPanel = AffinityPanel_new(st->pl, affinity1, &width); width += 1; /* we add a gap between the panels */ @@ -301,8 +316,9 @@ static Htop_Reaction actionSetAffinity(State* st) { void* set = Action_pickFromVector(st, affinityPanel, width, true); if (set) { Affinity* affinity2 = AffinityPanel_getAffinity(affinityPanel, st->pl); - bool ok = MainPanel_foreachProcess((MainPanel*)panel, Affinity_set, (Arg){ .v = affinity2 }, NULL); - if (!ok) beep(); + bool ok = MainPanel_foreachProcess((MainPanel*)panel, Affinity_set, (Arg) { .v = affinity2 }, NULL); + if (!ok) + beep(); Affinity_delete(affinity2); } Object_delete(affinityPanel); @@ -318,7 +334,7 @@ static Htop_Reaction actionKill(State* st) { Panel_setHeader(st->panel, "Sending..."); Panel_draw(st->panel, true); refresh(); - MainPanel_foreachProcess((MainPanel*)st->panel, Process_sendSignal, (Arg){ .i = sgn->key }, NULL); + MainPanel_foreachProcess((MainPanel*)st->panel, Process_sendSignal, (Arg) { .i = sgn->key }, NULL); napms(500); } } @@ -362,7 +378,9 @@ static Htop_Reaction actionSetup(State* st) { static Htop_Reaction actionLsof(State* st) { Process* p = (Process*) Panel_getSelected(st->panel); - if (!p) return HTOP_OK; + if (!p) + return HTOP_OK; + OpenFilesScreen* ofs = OpenFilesScreen_new(p); InfoScreen_run((InfoScreen*)ofs); OpenFilesScreen_delete((Object*)ofs); @@ -373,7 +391,9 @@ static Htop_Reaction actionLsof(State* st) { static Htop_Reaction actionStrace(State* st) { Process* p = (Process*) Panel_getSelected(st->panel); - if (!p) return HTOP_OK; + if (!p) + return HTOP_OK; + TraceScreen* ts = TraceScreen_new(p); bool ok = TraceScreen_forkTracer(ts); if (ok) { @@ -387,7 +407,9 @@ static Htop_Reaction actionStrace(State* st) { static Htop_Reaction actionTag(State* st) { Process* p = (Process*) Panel_getSelected(st->panel); - if (!p) return HTOP_OK; + if (!p) + return HTOP_OK; + Process_toggleTag(p); Panel_onKey(st->panel, KEY_DOWN); return HTOP_OK; @@ -555,14 +577,18 @@ static Htop_Reaction actionUntagAll(State* st) { static Htop_Reaction actionTagAllChildren(State* st) { Process* p = (Process*) Panel_getSelected(st->panel); - if (!p) return HTOP_OK; + if (!p) + return HTOP_OK; + tagAllChildren(st->panel, p); return HTOP_OK; } static Htop_Reaction actionShowEnvScreen(State* st) { Process* p = (Process*) Panel_getSelected(st->panel); - if (!p) return HTOP_OK; + if (!p) + return HTOP_OK; + EnvScreen* es = EnvScreen_new(p); InfoScreen_run((InfoScreen*)es); EnvScreen_delete((Object*)es); @@ -573,7 +599,9 @@ static Htop_Reaction actionShowEnvScreen(State* st) { static Htop_Reaction actionShowCommandScreen(State* st) { Process* p = (Process*) Panel_getSelected(st->panel); - if (!p) return HTOP_OK; + if (!p) + return HTOP_OK; + CommandScreen* cmdScr = CommandScreen_new(p); InfoScreen_run((InfoScreen*)cmdScr); CommandScreen_delete((Object*)cmdScr); diff --git a/Affinity.c b/Affinity.c index bfa7ceb5..6fb5846c 100644 --- a/Affinity.c +++ b/Affinity.c @@ -89,11 +89,14 @@ bool Affinity_set(Process* proc, Arg arg) { Affinity* Affinity_get(Process* proc, ProcessList* pl) { cpu_set_t cpuset; bool ok = (sched_getaffinity(proc->pid, sizeof(cpu_set_t), &cpuset) == 0); - if (!ok) return NULL; + if (!ok) + return NULL; + Affinity* affinity = Affinity_new(pl); for (int i = 0; i < pl->cpuCount; i++) { - if (CPU_ISSET(i, &cpuset)) + if (CPU_ISSET(i, &cpuset)) { Affinity_add(affinity, i); + } } return affinity; } diff --git a/AffinityPanel.c b/AffinityPanel.c index 85094b4c..9c2a6e7c 100644 --- a/AffinityPanel.c +++ b/AffinityPanel.c @@ -60,12 +60,13 @@ static void MaskItem_display(const Object* cast, RichString* out) { const MaskItem* this = (const MaskItem*)cast; assert (this != NULL); RichString_append(out, CRT_colors[CHECK_BOX], "["); - if (this->value == 2) + if (this->value == 2) { RichString_append(out, CRT_colors[CHECK_MARK], "x"); - else if (this->value == 1) + } else if (this->value == 1) { RichString_append(out, CRT_colors[CHECK_MARK], "o"); - else + } else { RichString_append(out, CRT_colors[CHECK_MARK], " "); + } RichString_append(out, CRT_colors[CHECK_BOX], "]"); RichString_append(out, CRT_colors[CHECK_TEXT], " "); if (this->indent) { @@ -178,11 +179,12 @@ static void AffinityPanel_update(AffinityPanel* this, bool keepSelected) { Panel_prune(super); #ifdef HAVE_LIBHWLOC - if (this->topoView) + if (this->topoView) { AffinityPanel_updateTopo(this, this->topoRoot); - else { - for (int i = 0; i < Vector_size(this->cpuids); i++) + } else { + for (int i = 0; i < Vector_size(this->cpuids); i++) { AffinityPanel_updateItem(this, (MaskItem*) Vector_get(this->cpuids, i)); + } } #else Panel_splice(super, this->cpuids); @@ -304,14 +306,16 @@ static MaskItem* AffinityPanel_addObject(AffinityPanel* this, hwloc_obj_t obj, u hwloc_bitmap_and(result, obj->complete_cpuset, this->workCpuset); int weight = hwloc_bitmap_weight(result); hwloc_bitmap_free(result); - if (weight == 0 || weight == (hwloc_bitmap_weight(this->workCpuset) + hwloc_bitmap_weight(obj->complete_cpuset))) + if (weight == 0 || weight == (hwloc_bitmap_weight(this->workCpuset) + hwloc_bitmap_weight(obj->complete_cpuset))) { item->sub_tree = 2; + } } /* "[x] " + "|- " * depth + ("- ")?(if root node) + name */ unsigned width = 4 + 3 * depth + (2 * !depth) + strlen(buf); - if (width > this->width) + if (width > this->width) { this->width = width; + } return item; } @@ -323,8 +327,10 @@ static MaskItem* AffinityPanel_buildTopology(AffinityPanel* this, hwloc_obj_t ob } else { indent &= ~(1u << obj->depth); } - for (unsigned i = 0; i < obj->arity; i++) + + for (unsigned i = 0; i < obj->arity; i++) { AffinityPanel_buildTopology(this, obj->children[i], indent, item); + } return parent == NULL ? item : NULL; } @@ -382,8 +388,9 @@ Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity, int* width) { char number[16]; xSnprintf(number, 9, "CPU %d", Settings_cpuId(pl->settings, i)); unsigned cpu_width = 4 + strlen(number); - if (cpu_width > this->width) + if (cpu_width > this->width) { this->width = cpu_width; + } bool isSet = false; if (curCpu < affinity->used && affinity->cpus[curCpu] == i) { @@ -402,8 +409,9 @@ Panel* AffinityPanel_new(ProcessList* pl, Affinity* affinity, int* width) { this->topoRoot = AffinityPanel_buildTopology(this, hwloc_get_root_obj(pl->topology), 0, NULL); #endif - if (width) + if (width) { *width = this->width; + } AffinityPanel_update(this, false); @@ -422,8 +430,9 @@ Affinity* AffinityPanel_getAffinity(Panel* super, ProcessList* pl) { #else for (int i = 0; i < this->pl->cpuCount; i++) { MaskItem* item = (MaskItem*)Vector_get(this->cpuids, i); - if (item->value) + if (item->value) { Affinity_add(affinity, item->cpu); + } } #endif diff --git a/CPUMeter.c b/CPUMeter.c index b1bb8f45..ff129cd2 100644 --- a/CPUMeter.c +++ b/CPUMeter.c @@ -163,10 +163,13 @@ static void CPUMeterCommonInit(Meter* this, int ncol) { for (int i = 0; i < count; i++) { if (!meters[i]) meters[i] = Meter_new(this->pl, start + i + 1, (const MeterClass*) Class(CPUMeter)); + Meter_init(meters[i]); } + if (this->mode == 0) this->mode = BAR_METERMODE; + int h = Meter_modes[this->mode]->h; this->h = h * ((count + ncol - 1) / ncol); } diff --git a/CRT.c b/CRT.c index 38ba9da3..08f1cef3 100644 --- a/CRT.c +++ b/CRT.c @@ -619,13 +619,18 @@ void CRT_init(int delay, int colorScheme, bool allowUnicode) { keypad(stdscr, true); mouseinterval(0); curs_set(0); - if (has_colors()) + + if (has_colors()) { start_color(); + } + CRT_termType = getenv("TERM"); - if (String_eq(CRT_termType, "linux")) + if (String_eq(CRT_termType, "linux")) { CRT_scrollHAmount = 20; - else + } else { CRT_scrollHAmount = 5; + } + if (String_startsWith(CRT_termType, "xterm") || String_eq(CRT_termType, "vt220")) { define_key("\033[H", KEY_HOME); define_key("\033[F", KEY_END); @@ -670,10 +675,11 @@ void CRT_init(int delay, int colorScheme, bool allowUnicode) { setlocale(LC_CTYPE, ""); #ifdef HAVE_LIBNCURSESW - if (allowUnicode && String_eq(nl_langinfo(CODESET), "UTF-8")) + if (allowUnicode && String_eq(nl_langinfo(CODESET), "UTF-8")) { CRT_utf8 = true; - else + } else { CRT_utf8 = false; + } #else (void) allowUnicode; #endif diff --git a/CategoriesPanel.c b/CategoriesPanel.c index d6c25a69..2dc1c3bf 100644 --- a/CategoriesPanel.c +++ b/CategoriesPanel.c @@ -97,6 +97,7 @@ static HandlerResult CategoriesPanel_eventHandler(Panel* super, int ch) { int size = ScreenManager_size(this->scr); for (int i = 1; i < size; i++) ScreenManager_remove(this->scr, 1); + switch (selected) { case 0: CategoriesPanel_makeMetersPage(this); diff --git a/CheckItem.c b/CheckItem.c index 5c79ab13..5fcae96b 100644 --- a/CheckItem.c +++ b/CheckItem.c @@ -26,10 +26,11 @@ static void CheckItem_display(const Object* cast, RichString* out) { const CheckItem* this = (const CheckItem*)cast; assert (this != NULL); RichString_write(out, CRT_colors[CHECK_BOX], "["); - if (CheckItem_get(this)) + if (CheckItem_get(this)) { RichString_append(out, CRT_colors[CHECK_MARK], "x"); - else + } else { RichString_append(out, CRT_colors[CHECK_MARK], " "); + } RichString_append(out, CRT_colors[CHECK_BOX], "] "); RichString_append(out, CRT_colors[CHECK_TEXT], this->text); } @@ -56,15 +57,17 @@ CheckItem* CheckItem_newByVal(char* text, bool value) { } void CheckItem_set(CheckItem* this, bool value) { - if (this->ref) + if (this->ref) { *(this->ref) = value; - else + } else { this->value = value; + } } bool CheckItem_get(const CheckItem* this) { - if (this->ref) + if (this->ref) { return *(this->ref); - else + } else { return this->value; + } } diff --git a/ColorsPanel.c b/ColorsPanel.c index 24e63b0e..9da71545 100644 --- a/ColorsPanel.c +++ b/ColorsPanel.c @@ -64,6 +64,7 @@ static HandlerResult ColorsPanel_eventHandler(Panel* super, int ch) { for (int i = 0; ColorSchemeNames[i] != NULL; i++) CheckItem_set((CheckItem*)Panel_get(super, i), false); CheckItem_set((CheckItem*)Panel_get(super, mark), true); + this->settings->colorScheme = mark; result = HANDLED; } diff --git a/CommandScreen.c b/CommandScreen.c index 7997a64a..578b3ae1 100644 --- a/CommandScreen.c +++ b/CommandScreen.c @@ -21,7 +21,9 @@ static void CommandScreen_scan(InfoScreen* this) { int line_offset = 0, last_spc = -1, len; for (; *p != '\0'; p++, line_offset++) { line[line_offset] = *p; - if (*p == ' ') last_spc = line_offset; + if (*p == ' ') { + last_spc = line_offset; + } if (line_offset == COLS) { len = (last_spc == -1) ? line_offset : last_spc; diff --git a/FunctionBar.c b/FunctionBar.c index 93456583..627bc777 100644 --- a/FunctionBar.c +++ b/FunctionBar.c @@ -106,10 +106,11 @@ void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr } if (buffer) { - if (attr == -1) + if (attr == -1) { attrset(CRT_colors[FUNCTION_BAR]); - else + } else { attrset(attr); + } mvaddstr(LINES - 1, x, buffer); attrset(CRT_colors[RESET_COLOR]); x += strlen(buffer); @@ -126,10 +127,11 @@ void FunctionBar_drawExtra(const FunctionBar* this, const char* buffer, int attr } void FunctionBar_append(const char* buffer, int attr) { - if (attr == -1) + if (attr == -1) { attrset(CRT_colors[FUNCTION_BAR]); - else + } else { attrset(attr); + } mvaddstr(LINES - 1, currentLen, buffer); attrset(CRT_colors[RESET_COLOR]); diff --git a/Hashtable.c b/Hashtable.c index a086227c..92337822 100644 --- a/Hashtable.c +++ b/Hashtable.c @@ -70,6 +70,7 @@ void Hashtable_delete(Hashtable* this) { while (walk != NULL) { if (this->owner) free(walk->value); + HashtableItem* savedWalk = walk; walk = savedWalk->next; free(savedWalk); @@ -90,10 +91,13 @@ void Hashtable_put(Hashtable* this, unsigned int key, void* value) { } else if ((*bucketPtr)->key == key) { if (this->owner && (*bucketPtr)->value != value) free((*bucketPtr)->value); + (*bucketPtr)->value = value; break; - } else + } else { bucketPtr = &((*bucketPtr)->next); + } + assert(Hashtable_isConsistent(this)); } @@ -134,8 +138,9 @@ void* Hashtable_get(Hashtable* this, unsigned int key) { } else if (bucketPtr->key == key) { assert(Hashtable_isConsistent(this)); return bucketPtr->value; - } else + } else { bucketPtr = bucketPtr->next; + } } } diff --git a/Header.c b/Header.c index 4448baa6..0b522f54 100644 --- a/Header.c +++ b/Header.c @@ -88,7 +88,8 @@ MeterModeId Header_addMeterByName(Header* this, char* name, int column) { int param = 0; if (paren) { int ok = sscanf(paren, "(%10d)", ¶m); - if (!ok) param = 0; + if (!ok) + param = 0; *paren = '\0'; } MeterModeId mode = TEXT_METERMODE; @@ -100,8 +101,10 @@ MeterModeId Header_addMeterByName(Header* this, char* name, int column) { break; } } + if (paren) *paren = '('; + return mode; } @@ -110,6 +113,7 @@ void Header_setMode(Header* this, int i, MeterModeId mode, int column) { if (i >= Vector_size(meters)) return; + Meter* meter = (Meter*) Vector_get(meters, i); Meter_setMode(meter, mode); } @@ -153,8 +157,9 @@ void Header_reinit(Header* this) { Header_forEachColumn(this, col) { for (int i = 0; i < Vector_size(this->columns[col]); i++) { Meter* meter = (Meter*) Vector_get(this->columns[col], i); - if (Meter_initFn(meter)) + if (Meter_initFn(meter)) { Meter_init(meter); + } } } } diff --git a/IncSet.c b/IncSet.c index 3deda737..d280caf4 100644 --- a/IncSet.c +++ b/IncSet.c @@ -79,7 +79,10 @@ static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) { ListItem* line = (ListItem*)Vector_get(lines, i); if (String_contains_i(line->value, incFilter)) { Panel_add(panel, (Object*)line); - if (selected == (Object*)line) Panel_setSelected(panel, n); + if (selected == (Object*)line) { + Panel_setSelected(panel, n); + } + n++; } } @@ -87,7 +90,9 @@ static void updateWeakPanel(IncSet* this, Panel* panel, Vector* lines) { for (int i = 0; i < Vector_size(lines); i++) { Object* line = Vector_get(lines, i); Panel_add(panel, line); - if (selected == line) Panel_setSelected(panel, i); + if (selected == line) { + Panel_setSelected(panel, i); + } } } } @@ -115,10 +120,17 @@ static bool IncMode_find(IncMode* mode, Panel* panel, IncMode_GetPanelValue getP int here = Panel_getSelectedIndex(panel); int i = here; for (;;) { - i+=step; - if (i == size) i = 0; - if (i == -1) i = size - 1; - if (i == here) return false; + i += step; + if (i == size) { + i = 0; + } + if (i == -1) { + i = size - 1; + } + if (i == here) { + return false; + } + if (String_contains_i(getPanelValue(panel, i), mode->buffer)) { Panel_setSelected(panel, i); return true; @@ -137,12 +149,15 @@ bool IncSet_prev(IncSet* this, IncType type, Panel* panel, IncMode_GetPanelValue bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue getPanelValue, Vector* lines) { if (ch == ERR) return true; + IncMode* mode = this->active; int size = Panel_size(panel); bool filterChanged = false; bool doSearch = true; if (ch == KEY_F(3)) { - if (size == 0) return true; + if (size == 0) + return true; + IncMode_find(mode, panel, getPanelValue, 1); doSearch = false; } else if (0 < ch && ch < 255 && isprint((unsigned char)ch)) { @@ -152,7 +167,9 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue mode->buffer[mode->index] = 0; if (mode->isFilter) { filterChanged = true; - if (mode->index == 1) this->filtering = true; + if (mode->index == 1) { + this->filtering = true; + } } } } else if ((ch == KEY_BACKSPACE || ch == 127)) { @@ -199,9 +216,7 @@ bool IncSet_handleKey(IncSet* this, int ch, Panel* panel, IncMode_GetPanelValue const char* IncSet_getListItemValue(Panel* panel, int i) { ListItem* l = (ListItem*) Panel_get(panel, i); - if (l) - return l->value; - return ""; + return l ? l->value : ""; } void IncSet_activate(IncSet* this, IncType type, Panel* panel) { diff --git a/InfoScreen.c b/InfoScreen.c index 102f0ba7..b7cbd4c6 100644 --- a/InfoScreen.c +++ b/InfoScreen.c @@ -64,16 +64,18 @@ void InfoScreen_drawTitled(InfoScreen* this, const char* fmt, ...) { void InfoScreen_addLine(InfoScreen* this, const char* line) { Vector_add(this->lines, (Object*) ListItem_new(line, 0)); const char* incFilter = IncSet_filter(this->inc); - if (!incFilter || String_contains_i(line, incFilter)) + if (!incFilter || String_contains_i(line, incFilter)) { Panel_add(this->display, Vector_get(this->lines, Vector_size(this->lines) - 1)); + } } void InfoScreen_appendLine(InfoScreen* this, const char* line) { ListItem* last = (ListItem*)Vector_get(this->lines, Vector_size(this->lines) - 1); ListItem_append(last, line); const char* incFilter = IncSet_filter(this->inc); - if (incFilter && Panel_get(this->display, Panel_size(this->display) - 1) != (Object*)last && String_contains_i(line, incFilter)) + if (incFilter && Panel_get(this->display, Panel_size(this->display) - 1) != (Object*)last && String_contains_i(line, incFilter)) { Panel_add(this->display, (Object*)last); + } } void InfoScreen_run(InfoScreen* this) { @@ -133,7 +135,9 @@ void InfoScreen_run(InfoScreen* this) { break; case KEY_F(5): clear(); - if (As_InfoScreen(this)->scan) InfoScreen_scan(this); + if (As_InfoScreen(this)->scan) + InfoScreen_scan(this); + InfoScreen_draw(this); break; case '\014': // Ctrl+L @@ -149,6 +153,7 @@ void InfoScreen_run(InfoScreen* this) { Panel_resize(panel, COLS, LINES - 2); if (As_InfoScreen(this)->scan) InfoScreen_scan(this); + InfoScreen_draw(this); break; default: diff --git a/MainPanel.c b/MainPanel.c index 9322fe02..be59abd3 100644 --- a/MainPanel.c +++ b/MainPanel.c @@ -100,8 +100,9 @@ static HandlerResult MainPanel_eventHandler(Panel* super, int ch) { if (reaction & HTOP_REDRAW_BAR) { MainPanel_updateTreeFunctions(this, this->state->settings->treeView); IncSet_drawBar(this->inc); - if (this->state->pauseProcessUpdate) + if (this->state->pauseProcessUpdate) { FunctionBar_append("PAUSED", CRT_colors[PAUSED]); + } } if (reaction & HTOP_UPDATE_PANELHDR) { ProcessList_printHeader(this->state->pl, Panel_getHeader(super)); @@ -135,9 +136,7 @@ int MainPanel_selectedPid(MainPanel* this) { const char* MainPanel_getValue(MainPanel* this, int i) { Process* p = (Process*) Panel_get((Panel*)this, i); - if (p) - return p->comm; - return ""; + return p ? p->comm : ""; } bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Arg arg, bool* wasAnyTagged) { @@ -157,8 +156,10 @@ bool MainPanel_foreachProcess(MainPanel* this, MainPanel_ForeachProcessFn fn, Ar ok &= fn(p, arg); } } + if (wasAnyTagged) *wasAnyTagged = anyTagged; + return ok; } diff --git a/Meter.c b/Meter.c index d17ba95a..cf8ccc52 100644 --- a/Meter.c +++ b/Meter.c @@ -41,8 +41,9 @@ Meter* Meter_new(const struct ProcessList_* pl, int param, const MeterClass* typ this->values = type->maxItems ? xCalloc(type->maxItems, sizeof(double)) : NULL; this->total = type->total; this->caption = xStrdup(type->caption); - if (Meter_initFn(this)) + if (Meter_initFn(this)) { Meter_init(this); + } Meter_setMode(this, type->defaultMode); return this; } @@ -81,6 +82,7 @@ int Meter_humanUnit(char* buffer, unsigned long int value, int size) { void Meter_delete(Object* cast) { if (!cast) return; + Meter* this = (Meter*) cast; if (Meter_doneFn(this)) { Meter_done(this); @@ -105,15 +107,20 @@ static inline void Meter_displayBuffer(const Meter* this, const char* buffer, Ri } void Meter_setMode(Meter* this, int modeIndex) { - if (modeIndex > 0 && modeIndex == this->mode) + if (modeIndex > 0 && modeIndex == this->mode) { return; - if (!modeIndex) + } + + if (!modeIndex) { modeIndex = 1; + } + assert(modeIndex < LAST_METERMODE); if (Meter_defaultMode(this) == CUSTOM_METERMODE) { this->draw = Meter_drawFn(this); - if (Meter_updateModeFn(this)) + if (Meter_updateModeFn(this)) { Meter_updateMode(this, modeIndex); + } } else { assert(modeIndex >= 1); free(this->drawData); @@ -128,15 +135,17 @@ void Meter_setMode(Meter* this, int modeIndex) { ListItem* Meter_toListItem(Meter* this, bool moving) { char mode[21]; - if (this->mode) + if (this->mode) { xSnprintf(mode, 20, " [%s]", Meter_modes[this->mode]->uiName); - else + } else { mode[0] = '\0'; + } char number[11]; - if (this->param > 0) + if (this->param > 0) { xSnprintf(number, 10, " %d", this->param); - else + } else { number[0] = '\0'; + } char buffer[51]; xSnprintf(buffer, 50, "%s%s%s", Meter_uiName(this), number, mode); ListItem* li = ListItem_new(buffer, 0); @@ -261,7 +270,9 @@ static int GraphMeterMode_pixPerRow; static void GraphMeterMode_draw(Meter* this, int x, int y, int w) { - if (!this->drawData) this->drawData = xCalloc(1, sizeof(GraphData)); + if (!this->drawData) { + this->drawData = xCalloc(1, sizeof(GraphData)); + } GraphData* data = this->drawData; const int nValues = METER_BUFFER_LEN; diff --git a/Object.c b/Object.c index 01b6c4ce..975c8d48 100644 --- a/Object.c +++ b/Object.c @@ -20,12 +20,16 @@ const ObjectClass Object_class = { bool Object_isA(const Object* o, const ObjectClass* klass) { if (!o) return false; + const ObjectClass* type = o->klass; while (type) { - if (type == klass) + if (type == klass) { return true; + } + type = type->extends; } + return false; } diff --git a/OpenFilesScreen.c b/OpenFilesScreen.c index 829fafee..cd309648 100644 --- a/OpenFilesScreen.c +++ b/OpenFilesScreen.c @@ -69,10 +69,11 @@ static const char* getDataForType(const OpenFiles_Data* data, char type) { OpenFilesScreen* OpenFilesScreen_new(const Process* process) { OpenFilesScreen* this = xMalloc(sizeof(OpenFilesScreen)); Object_setClass(this, Class(OpenFilesScreen)); - if (Process_isThread(process)) + if (Process_isThread(process)) { this->pid = process->tgid; - else + } else { this->pid = process->pid; + } return (OpenFilesScreen*) InfoScreen_init(&this->super, process, NULL, LINES - 3, " FD TYPE MODE DEVICE SIZE NODE NAME"); } @@ -106,8 +107,10 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { dup2(fdpair[1], STDOUT_FILENO); close(fdpair[1]); int fdnull = open("/dev/null", O_WRONLY); - if (fdnull < 0) + if (fdnull < 0) { exit(1); + } + dup2(fdnull, STDERR_FILENO); close(fdnull); char buffer[32] = {0}; @@ -182,10 +185,11 @@ static OpenFiles_ProcessData* OpenFilesScreen_getProcessData(pid_t pid) { return pdata; } - if (!WIFEXITED(wstatus)) + if (!WIFEXITED(wstatus)) { pdata->error = 1; - else + } else { pdata->error = WEXITSTATUS(wstatus); + } return pdata; } diff --git a/Panel.c b/Panel.c index 5e92c9c7..870f89cc 100644 --- a/Panel.c +++ b/Panel.c @@ -97,8 +97,10 @@ void Panel_move(Panel* this, int x, int y) { void Panel_resize(Panel* this, int w, int h) { assert (this != NULL); - if (RichString_sizeVal(this->header) > 0) + if (RichString_sizeVal(this->header) > 0) { h--; + } + this->w = w; this->h = h; this->needsRedraw = true; @@ -145,33 +147,38 @@ Object* Panel_remove(Panel* this, int i) { this->needsRedraw = true; Object* removed = Vector_remove(this->items, i); - if (this->selected > 0 && this->selected >= Vector_size(this->items)) + if (this->selected > 0 && this->selected >= Vector_size(this->items)) { this->selected--; + } + return removed; } Object* Panel_getSelected(Panel* this) { assert (this != NULL); - if (Vector_size(this->items) > 0) + if (Vector_size(this->items) > 0) { return Vector_get(this->items, this->selected); - else + } else { return NULL; + } } void Panel_moveSelectedUp(Panel* this) { assert (this != NULL); Vector_moveUp(this->items, this->selected); - if (this->selected > 0) + if (this->selected > 0) { this->selected--; + } } void Panel_moveSelectedDown(Panel* this) { assert (this != NULL); Vector_moveDown(this->items, this->selected); - if (this->selected + 1 < Vector_size(this->items)) + if (this->selected + 1 < Vector_size(this->items)) { this->selected++; + } } int Panel_getSelectedIndex(Panel* this) { @@ -193,8 +200,9 @@ void Panel_setSelected(Panel* this, int selected) { if (selected >= size) { selected = size - 1; } - if (selected < 0) + if (selected < 0) { selected = 0; + } this->selected = selected; if (Panel_eventHandlerFn(this)) { Panel_eventHandler(this, EVENT_SET_SELECTED); diff --git a/Process.c b/Process.c index af7bf79d..72360e39 100644 --- a/Process.c +++ b/Process.c @@ -43,7 +43,9 @@ static char Process_titleBuffer[20][20]; void Process_setupColumnWidths() { int maxPid = Platform_getMaxPid(); - if (maxPid == -1) return; + if (maxPid == -1) + return; + int digits = ceil(log10(maxPid)); assert(digits < 20); for (int i = 0; Process_pidColumns[i].label; i++) { @@ -201,10 +203,11 @@ static inline void Process_writeCommand(const Process* this, int attr, int basea } } if (!finish) { - if (this->settings->showProgramPath) + if (this->settings->showProgramPath) { start += basename; - else + } else { comm += basename; + } finish = this->basenameOffset - basename; } finish += start - 1; @@ -212,8 +215,9 @@ static inline void Process_writeCommand(const Process* this, int attr, int basea RichString_append(str, attr, comm); - if (this->settings->highlightBaseName) + if (this->settings->highlightBaseName) { RichString_setAttrn(str, baseattr, start, finish); + } } void Process_outputRate(RichString* str, char* buffer, int n, double rate, int coloring) { @@ -285,15 +289,19 @@ void Process_writeField(const Process* this, RichString* str, ProcessField field bool lastItem = (this->indent < 0); int indent = (this->indent < 0 ? -this->indent : this->indent); - for (int i = 0; i < 32; i++) - if (indent & (1U << i)) + for (int i = 0; i < 32; i++) { + if (indent & (1U << i)) { maxIndent = i + 1; + } + } + for (int i = 0; i < maxIndent - 1; i++) { int written, ret; - if (indent & (1 << i)) + if (indent & (1 << i)) { ret = snprintf(buf, n, "%s ", CRT_treeStr[TREE_STR_VERT]); - else + } else { ret = snprintf(buf, n, " "); + } if (ret < 0 || ret >= n) { written = n; } else { @@ -377,10 +385,15 @@ void Process_display(const Object* cast, RichString* out) { RichString_prune(out); for (int i = 0; fields[i]; i++) As_Process(this)->writeField(this, out, fields[i]); - if (this->settings->shadowOtherUsers && (int)this->st_uid != Process_getuid) + + if (this->settings->shadowOtherUsers && (int)this->st_uid != Process_getuid) { RichString_setAttr(out, CRT_colors[PROCESS_SHADOW]); - if (this->tag == true) + } + + if (this->tag == true) { RichString_setAttr(out, CRT_colors[PROCESS_TAG]); + } + assert(out->chlen > 0); } @@ -406,7 +419,10 @@ void Process_init(Process* this, const struct Settings_* settings) { this->show = true; this->updated = false; this->basenameOffset = -1; - if (Process_getuid == -1) Process_getuid = getuid(); + + if (Process_getuid == -1) { + Process_getuid = getuid(); + } } void Process_toggleTag(Process* this) { @@ -483,10 +499,11 @@ long Process_compare(const void* v1, const void* v2) { case SESSION: return (p1->session - p2->session); case STARTTIME: { - if (p1->starttime_ctime == p2->starttime_ctime) + if (p1->starttime_ctime == p2->starttime_ctime) { return (p1->pid - p2->pid); - else + } else { return (p1->starttime_ctime - p2->starttime_ctime); + } } case STATE: return (Process_sortState(p1->state) - Process_sortState(p2->state)); diff --git a/ProcessList.c b/ProcessList.c index ff4aa9b3..2323c99a 100644 --- a/ProcessList.c +++ b/ProcessList.c @@ -70,11 +70,15 @@ void ProcessList_printHeader(ProcessList* this, RichString* header) { const ProcessField* fields = this->settings->fields; for (int i = 0; fields[i]; i++) { const char* field = Process_fields[fields[i]].title; - if (!field) field = "- "; - if (!this->settings->treeView && this->settings->sortKey == fields[i]) + if (!field) { + field = "- "; + } + + if (!this->settings->treeView && this->settings->sortKey == fields[i]) { RichString_append(header, CRT_colors[PANEL_SELECTION_FOCUS], field); - else + } else { RichString_append(header, CRT_colors[PANEL_HEADER_FOCUS], field); + } } } @@ -93,12 +97,18 @@ void ProcessList_add(ProcessList* this, Process* p) { void ProcessList_remove(ProcessList* this, Process* p) { assert(Vector_indexOf(this->processes, p, Process_pidCompare) != -1); assert(Hashtable_get(this->processTable, p->pid) != NULL); + Process* pp = Hashtable_remove(this->processTable, p->pid); assert(pp == p); (void)pp; + unsigned int pid = p->pid; int idx = Vector_indexOf(this->processes, p, Process_pidCompare); assert(idx != -1); - if (idx >= 0) Vector_remove(this->processes, idx); + + if (idx >= 0) { + Vector_remove(this->processes, idx); + } + assert(Hashtable_get(this->processTable, pid) == NULL); (void)pid; assert(Hashtable_count(this->processTable) == Vector_count(this->processes)); } @@ -124,20 +134,27 @@ static void ProcessList_buildTree(ProcessList* this, pid_t pid, int level, int i int size = Vector_size(children); for (int i = 0; i < size; i++) { Process* process = (Process*) (Vector_get(children, i)); - if (!show) + if (!show) { process->show = false; + } + int s = Vector_size(this->processes2); - if (direction == 1) + if (direction == 1) { Vector_add(this->processes2, process); - else + } else { Vector_insert(this->processes2, 0, process); + } + assert(Vector_size(this->processes2) == s + 1); (void)s; + int nextIndent = indent | (1 << level); ProcessList_buildTree(this, process->pid, level + 1, (i < size - 1) ? nextIndent : indent, direction, show ? process->showChildren : false); - if (i == size - 1) + + if (i == size - 1) { process->indent = -nextIndent; - else + } else { process->indent = nextIndent; + } } Vector_delete(children); } @@ -180,6 +197,7 @@ void ProcessList_sort(ProcessList* this) { // root. if (process->pid == ppid) r = 0; + while (l < r) { int c = (l + r) / 2; pid_t pid = ((Process*)(Vector_get(this->processes, c)))->pid; @@ -219,7 +237,10 @@ ProcessField ProcessList_keyAt(ProcessList* this, int at) { ProcessField field; for (int i = 0; (field = fields[i]); i++) { const char* title = Process_fields[field].title; - if (!title) title = "- "; + if (!title) { + title = "- "; + } + int len = strlen(title); if (at >= x && at <= x + len) { return field; @@ -306,9 +327,10 @@ void ProcessList_scan(ProcessList* this, bool pauseProcessUpdate) { for (int i = Vector_size(this->processes) - 1; i >= 0; i--) { Process* p = (Process*) Vector_get(this->processes, i); - if (p->updated == false) + if (p->updated == false) { ProcessList_remove(this, p); - else + } else { p->updated = false; + } } } diff --git a/RichString.c b/RichString.c index 99c535b1..904b44b6 100644 --- a/RichString.c +++ b/RichString.c @@ -52,6 +52,7 @@ static inline void RichString_writeFrom(RichString* this, int attrs, const char* len = mbstowcs(data, data_c, len); if (len < 0) return; + int newLen = from + len; RichString_setLen(this, newLen); for (int i = from, j = 0; i < newLen; i++, j++) { @@ -84,8 +85,9 @@ int RichString_findChar(RichString* this, char c, int start) { static inline void RichString_writeFrom(RichString* this, int attrs, const char* data_c, int from, int len) { int newLen = from + len; RichString_setLen(this, newLen); - for (int i = from, j = 0; i < newLen; i++, j++) + for (int i = from, j = 0; i < newLen; i++, j++) { this->chptr[i] = (data_c[j] >= 32 ? data_c[j] : '?') | attrs; + } this->chptr[newLen] = 0; } diff --git a/ScreenManager.c b/ScreenManager.c index f586d04a..b8e1713a 100644 --- a/ScreenManager.c +++ b/ScreenManager.c @@ -103,8 +103,12 @@ static void checkRecalculation(ScreenManager* this, double* oldTime, int* sortTi gettimeofday(&tv, NULL); double newTime = ((double)tv.tv_sec * 10) + ((double)tv.tv_usec / 100000); *timedOut = (newTime - *oldTime > this->settings->delay); - *rescan = *rescan || *timedOut; - if (newTime < *oldTime) *rescan = true; // clock was adjusted? + *rescan |= *timedOut; + + if (newTime < *oldTime) { + *rescan = true; // clock was adjusted? + } + if (*rescan) { *oldTime = newTime; ProcessList_scan(pl, this->state->pauseProcessUpdate); @@ -134,8 +138,9 @@ static void ScreenManager_drawPanels(ScreenManager* this, int focus) { static Panel* setCurrentPanel(const ScreenManager* this, Panel* panel) { FunctionBar_draw(panel->currentBar); - if (panel == this->state->panel && this->state->pauseProcessUpdate) + if (panel == this->state->panel && this->state->pauseProcessUpdate) { FunctionBar_append("PAUSED", CRT_colors[PAUSED]); + } return panel; } @@ -218,8 +223,9 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { if (closeTimeout == 100) { break; } - } else + } else { closeTimeout = 0; + } redraw = false; continue; } @@ -261,14 +267,21 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { if (this->panelCount < 2) { goto defaultHandler; } - if (!this->allowFocusChange) + + if (!this->allowFocusChange) { break; - tryLeft: - if (focus > 0) + } + +tryLeft: + if (focus > 0) { focus--; + } + panelFocus = setCurrentPanel(this, (Panel*) Vector_get(this->panels, focus)); - if (Panel_size(panelFocus) == 0 && focus > 0) + if (Panel_size(panelFocus) == 0 && focus > 0) { goto tryLeft; + } + break; case KEY_RIGHT: case KEY_CTRL('F'): @@ -276,14 +289,20 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { if (this->panelCount < 2) { goto defaultHandler; } - if (!this->allowFocusChange) + if (!this->allowFocusChange) { break; - tryRight: - if (focus < this->panelCount - 1) + } + +tryRight: + if (focus < this->panelCount - 1) { focus++; + } + panelFocus = setCurrentPanel(this, (Panel*) Vector_get(this->panels, focus)); - if (Panel_size(panelFocus) == 0 && focus < this->panelCount - 1) + if (Panel_size(panelFocus) == 0 && focus < this->panelCount - 1) { goto tryRight; + } + break; case KEY_F(10): case 'q': @@ -291,15 +310,18 @@ void ScreenManager_run(ScreenManager* this, Panel** lastFocus, int* lastKey) { quit = true; continue; default: - defaultHandler: +defaultHandler: sortTimeout = resetSortTimeout; Panel_onKey(panelFocus, ch); break; } } - if (lastFocus) + if (lastFocus) { *lastFocus = panelFocus; - if (lastKey) + } + + if (lastKey) { *lastKey = ch; + } } diff --git a/Settings.c b/Settings.c index 2e274e94..1ecee569 100644 --- a/Settings.c +++ b/Settings.c @@ -116,6 +116,7 @@ static bool Settings_read(Settings* this, const char* fileName, int initialCpuCo CRT_restorePrivileges(); if (!fd) return false; + bool didReadMeters = false; bool didReadFields = false; for (;;) { @@ -182,8 +183,9 @@ static bool Settings_read(Settings* this, const char* fileName, int initialCpuCo this->delay = atoi(option[1]); } else if (String_eq(option[0], "color_scheme")) { this->colorScheme = atoi(option[1]); - if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) + if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME) { this->colorScheme = 0; + } } else if (String_eq(option[0], "enable_mouse")) { this->enableMouse = atoi(option[1]); } else if (String_eq(option[0], "left_meters")) { @@ -327,7 +329,9 @@ Settings* Settings_new(int initialCpuCount) { this->filename = xStrdup(rcfile); } else { const char* home = getenv("HOME"); - if (!home) home = ""; + if (!home) + home = ""; + const char* xdgConfigHome = getenv("XDG_CONFIG_HOME"); char* configDir = NULL; char* htopDir = NULL; @@ -363,8 +367,9 @@ Settings* Settings_new(int initialCpuCount) { ok = Settings_read(this, legacyDotfile, initialCpuCount); if (ok) { // Transition to new location and delete old configuration file - if (Settings_write(this)) + if (Settings_write(this)) { unlink(legacyDotfile); + } } free(legacyDotfile); } @@ -389,8 +394,9 @@ Settings* Settings_new(int initialCpuCount) { } void Settings_invertSortOrder(Settings* this) { - if (this->direction == 1) + if (this->direction == 1) { this->direction = -1; - else + } else { this->direction = 1; + } } diff --git a/TraceScreen.c b/TraceScreen.c index 7346a0f8..b1277488 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -61,8 +61,11 @@ void TraceScreen_delete(Object* cast) { kill(this->child, SIGTERM); waitpid(this->child, NULL, 0); } - if (this->strace) + + if (this->strace) { fclose(this->strace); + } + CRT_enableDelay(); free(InfoScreen_done((InfoScreen*)this)); } @@ -144,9 +147,11 @@ void TraceScreen_updateTrace(InfoScreen* super) { tv.tv_sec = 0; tv.tv_usec = 500; int ready = select(fd_strace + 1, &fds, NULL, NULL, &tv); + size_t nread = 0; if (ready > 0 && FD_ISSET(fd_strace, &fds)) nread = fread(buffer, 1, sizeof(buffer) - 1, this->strace); + if (nread && this->tracing) { const char* line = buffer; buffer[nread] = '\0'; @@ -167,8 +172,9 @@ void TraceScreen_updateTrace(InfoScreen* super) { buffer[nread] = '\0'; this->contLine = true; } - if (this->follow) - Panel_setSelected(this->super.display, Panel_size(this->super.display)-1); + if (this->follow) { + Panel_setSelected(this->super.display, Panel_size(this->super.display) - 1); + } } } diff --git a/Vector.c b/Vector.c index eb80e145..09d1612e 100644 --- a/Vector.c +++ b/Vector.c @@ -17,8 +17,10 @@ in the source distribution for its full text. Vector* Vector_new(const ObjectClass* type, bool owner, int size) { Vector* this; - if (size == DEFAULT_SIZE) + if (size == DEFAULT_SIZE) { size = 10; + } + assert(size > 0); this = xMalloc(sizeof(Vector)); this->growthRate = size; @@ -32,9 +34,11 @@ Vector* Vector_new(const ObjectClass* type, bool owner, int size) { void Vector_delete(Vector* this) { if (this->owner) { - for (int i = 0; i < this->items; i++) - if (this->array[i]) + for (int i = 0; i < this->items; i++) { + if (this->array[i]) { Object_delete(this->array[i]); + } + } } free(this->array); free(this); @@ -45,9 +49,11 @@ void Vector_delete(Vector* this) { static bool Vector_isConsistent(const Vector* this) { assert(this->items <= this->arraySize); if (this->owner) { - for (int i = 0; i < this->items; i++) - if (this->array[i] && !Object_isA(this->array[i], this->type)) + for (int i = 0; i < this->items; i++) { + if (this->array[i] && !Object_isA(this->array[i], this->type)) { return false; + } + } return true; } else { return true; @@ -57,8 +63,9 @@ static bool Vector_isConsistent(const Vector* this) { int Vector_count(const Vector* this) { int items = 0; for (int i = 0; i < this->items; i++) { - if (this->array[i]) + if (this->array[i]) { items++; + } } assert(items == this->items); return items; @@ -230,15 +237,18 @@ Object* Vector_remove(Vector* this, int idx) { if (this->owner) { Object_delete(removed); return NULL; - } else + } else { return removed; + } } void Vector_moveUp(Vector* this, int idx) { assert(idx >= 0 && idx < this->items); assert(Vector_isConsistent(this)); + if (idx == 0) return; + Object* temp = this->array[idx]; this->array[idx] = this->array[idx - 1]; this->array[idx - 1] = temp; @@ -247,8 +257,10 @@ void Vector_moveUp(Vector* this, int idx) { void Vector_moveDown(Vector* this, int idx) { assert(idx >= 0 && idx < this->items); assert(Vector_isConsistent(this)); + if (idx == this->items - 1) return; + Object* temp = this->array[idx]; this->array[idx] = this->array[idx + 1]; this->array[idx + 1] = temp; @@ -307,8 +319,9 @@ int Vector_indexOf(const Vector* this, const void* search_, Object_Compare compa for (int i = 0; i < this->items; i++) { const Object* o = this->array[i]; assert(o); - if (compare(search, o) == 0) + if (compare(search, o) == 0) { return i; + } } return -1; } @@ -321,6 +334,7 @@ void Vector_splice(Vector* this, Vector* from) { int olditems = this->items; this->items += from->items; Vector_checkArraySize(this); - for (int j = 0; j < from->items; j++) + for (int j = 0; j < from->items; j++) { this->array[olditems + j] = from->array[j]; + } } diff --git a/darwin/DarwinProcessList.c b/darwin/DarwinProcessList.c index 673d9e61..99f49d5c 100644 --- a/darwin/DarwinProcessList.c +++ b/darwin/DarwinProcessList.c @@ -110,15 +110,18 @@ struct kinfo_proc* ProcessList_getKInfoProcs(size_t* count) { * process entry or two. */ *count = 0; - if (sysctl(mib, 4, NULL, count, NULL, 0) < 0) + if (sysctl(mib, 4, NULL, count, NULL, 0) < 0) { CRT_fatalError("Unable to get size of kproc_infos"); + } processes = xMalloc(*count); - if (processes == NULL) + if (processes == NULL) { CRT_fatalError("Out of memory for kproc_infos"); + } - if (sysctl(mib, 4, processes, count, NULL, 0) < 0) + if (sysctl(mib, 4, processes, count, NULL, 0) < 0) { CRT_fatalError("Unable to get kinfo_procs"); + } *count = *count / sizeof(struct kinfo_proc); diff --git a/dragonflybsd/Battery.c b/dragonflybsd/Battery.c index 4bae3aa5..1a690ee3 100644 --- a/dragonflybsd/Battery.c +++ b/dragonflybsd/Battery.c @@ -14,15 +14,17 @@ in the source distribution for its full text. void Battery_getData(double* level, ACPresence* isOnAC) { int life; size_t life_len = sizeof(life); - if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) + if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) { *level = NAN; - else + } else { *level = life; + } int acline; size_t acline_len = sizeof(acline); - if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) + if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) { *isOnAC = AC_ERROR; - else + } else { *isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT; + } } diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c index 457a488a..bd209327 100644 --- a/dragonflybsd/DragonFlyBSDProcess.c +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -131,8 +131,9 @@ long DragonFlyBSDProcess_compare(const void* v1, const void* v2) { bool Process_isThread(const Process* this) { const DragonFlyBSDProcess* fp = (const DragonFlyBSDProcess*) this; - if (fp->kernel == 1 ) + if (fp->kernel == 1 ) { return 1; - else + } else { return (Process_isUserlandThread(this)); + } } diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index d3acf73d..b66dc0e8 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -123,7 +123,9 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui void ProcessList_delete(ProcessList* this) { const DragonFlyBSDProcessList* dfpl = (DragonFlyBSDProcessList*) this; - if (dfpl->kd) kvm_close(dfpl->kd); + if (dfpl->kd) { + kvm_close(dfpl->kd); + } if (dfpl->jails) { Hashtable_delete(dfpl->jails); @@ -199,7 +201,9 @@ static inline void DragonFlyBSDProcessList_scanCPUTime(ProcessList* pl) { // totals total_d = total_n - total_o; - if (total_d < 1 ) total_d = 1; + if (total_d < 1 ) { + total_d = 1; + } // save current state as old and calc percentages for (int s = 0; s < CPUSTATES; ++s) { @@ -331,8 +335,9 @@ retry: int jailid; char* str_hostname; nextpos = strchr(curpos, '\n'); - if (nextpos) + if (nextpos) { *nextpos++ = 0; + } jailid = atoi(strtok(curpos, " ")); str_hostname = strtok(NULL, " "); @@ -372,8 +377,9 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { DragonFlyBSDProcessList_scanJails(dfpl); // in pause mode only gather global data for meters (CPU/memory/...) - if (pauseProcessUpdate) + if (pauseProcessUpdate) { return; + } int count = 0; diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 5e9fe335..5f9f6373 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -177,7 +177,9 @@ double Platform_setCPUValues(Meter* this, int cpu) { } percent = CLAMP(percent, 0.0, 100.0); - if (isnan(percent)) percent = 0.0; + if (isnan(percent)) { + percent = 0.0; + } v[CPU_METER_FREQUENCY] = NAN; diff --git a/freebsd/Battery.c b/freebsd/Battery.c index 50691c8b..26b42da9 100644 --- a/freebsd/Battery.c +++ b/freebsd/Battery.c @@ -13,15 +13,17 @@ in the source distribution for its full text. void Battery_getData(double* level, ACPresence* isOnAC) { int life; size_t life_len = sizeof(life); - if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) + if (sysctlbyname("hw.acpi.battery.life", &life, &life_len, NULL, 0) == -1) { *level = NAN; - else + } else { *level = life; + } int acline; size_t acline_len = sizeof(acline); - if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) + if (sysctlbyname("hw.acpi.acline", &acline, &acline_len, NULL, 0) == -1) { *isOnAC = AC_ERROR; - else + } else { *isOnAC = acline == 0 ? AC_ABSENT : AC_PRESENT; + } } diff --git a/freebsd/FreeBSDProcess.c b/freebsd/FreeBSDProcess.c index a4516d04..baad5d13 100644 --- a/freebsd/FreeBSDProcess.c +++ b/freebsd/FreeBSDProcess.c @@ -134,10 +134,11 @@ static long FreeBSDProcess_compare(const void* v1, const void* v2) { bool Process_isThread(const Process* this) { const FreeBSDProcess* fp = (const FreeBSDProcess*) this; - if (fp->kernel == 1 ) + if (fp->kernel == 1 ) { return 1; - else + } else { return Process_isUserlandThread(this); + } } const ProcessClass FreeBSDProcess_class = { diff --git a/freebsd/FreeBSDProcessList.c b/freebsd/FreeBSDProcessList.c index 4594b992..7ce787f8 100644 --- a/freebsd/FreeBSDProcessList.c +++ b/freebsd/FreeBSDProcessList.c @@ -98,7 +98,9 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui if (smp) { int err = sysctlbyname("kern.smp.cpus", &cpus, &len, NULL, 0); - if (err) cpus = 1; + if (err) { + cpus = 1; + } } else { cpus = 1; } @@ -152,7 +154,9 @@ void ProcessList_delete(ProcessList* this) { Hashtable_delete(fpl->ttys); - if (fpl->kd) kvm_close(fpl->kd); + if (fpl->kd) { + kvm_close(fpl->kd); + } free(fpl->cp_time_o); free(fpl->cp_time_n); @@ -225,7 +229,9 @@ static inline void FreeBSDProcessList_scanCPUTime(ProcessList* pl) { // totals total_d = total_n - total_o; - if (total_d < 1 ) total_d = 1; + if (total_d < 1 ) { + total_d = 1; + } // save current state as old and calc percentages for (int s = 0; s < CPUSTATES; ++s) { @@ -434,13 +440,15 @@ IGNORE_WCASTQUAL_END jail_errmsg[0] = 0; jid = jail_get(jiov, 6, 0); if (jid < 0) { - if (!jail_errmsg[0]) + if (!jail_errmsg[0]) { xSnprintf(jail_errmsg, JAIL_ERRMSGLEN, "jail_get: %s", strerror(errno)); + } return NULL; } else if (jid == kproc->ki_jid) { jname = xStrdup(jnamebuf); - if (jname == NULL) + if (jname == NULL) { strerror_r(errno, jail_errmsg, JAIL_ERRMSGLEN); + } return jname; } else { return NULL; @@ -464,11 +472,13 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { FreeBSDProcessList_scanCPUTime(super); // in pause mode only gather global data for meters (CPU/memory/...) - if (pauseProcessUpdate) + if (pauseProcessUpdate) { return; + } - if (settings->flags & PROCESS_FLAG_FREEBSD_TTY) + if (settings->flags & PROCESS_FLAG_FREEBSD_TTY) { FreeBSDProcessList_scanTTYs(super); + } int count = 0; struct kinfo_proc* kprocs = kvm_getprocs(fpl->kd, KERN_PROC_PROC, 0, &count); @@ -485,10 +495,11 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { if (!preExisting) { fp->jid = kproc->ki_jid; proc->pid = kproc->ki_pid; - if ( ! ((kproc->ki_pid == 0) || (kproc->ki_pid == 1) ) && kproc->ki_flag & P_SYSTEM) - fp->kernel = 1; - else - fp->kernel = 0; + if ( ! ((kproc->ki_pid == 0) || (kproc->ki_pid == 1) ) && kproc->ki_flag & P_SYSTEM) { + fp->kernel = 1; + } else { + fp->kernel = 0; + } proc->ppid = kproc->ki_ppid; proc->tpgid = kproc->ki_tpgid; proc->tgid = kproc->ki_pid; @@ -565,8 +576,9 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { default: proc->state = '?'; } - if (settings->flags & PROCESS_FLAG_FREEBSD_TTY) + if (settings->flags & PROCESS_FLAG_FREEBSD_TTY) { fp->ttyPath = (kproc->ki_tdev == NODEV) ? nodevStr : Hashtable_get(fpl->ttys, kproc->ki_tdev); + } if (Process_isKernelThread(proc)) super->kernelThreads++; diff --git a/htop.c b/htop.c index 76754462..7fbc04c9 100644 --- a/htop.c +++ b/htop.c @@ -243,12 +243,13 @@ static void setCommFilter(State* state, char** commFilter) { int main(int argc, char** argv) { char* lc_ctype = getenv("LC_CTYPE"); - if (lc_ctype != NULL) + if (lc_ctype != NULL) { setlocale(LC_CTYPE, lc_ctype); - else if ((lc_ctype = getenv("LC_ALL"))) + } else if ((lc_ctype = getenv("LC_ALL"))) { setlocale(LC_CTYPE, lc_ctype); - else + } else { setlocale(LC_CTYPE, ""); + } CommandLineSettings flags = parseArguments(argc, argv); // may exit() @@ -271,14 +272,18 @@ int main(int argc, char** argv) { Header_populateFromSettings(header); - if (flags.delay != -1) + if (flags.delay != -1) { settings->delay = flags.delay; - if (!flags.useColors) + } + if (!flags.useColors) { settings->colorScheme = COLORSCHEME_MONOCHROME; - if (!flags.enableMouse) + } + if (!flags.enableMouse) { settings->enableMouse = false; - if (flags.treeView) + } + if (flags.treeView) { settings->treeView = true; + } CRT_init(settings->delay, settings->colorScheme, flags.allowUnicode); diff --git a/linux/Battery.c b/linux/Battery.c index 326f35fd..ba7d153a 100644 --- a/linux/Battery.c +++ b/linux/Battery.c @@ -52,9 +52,11 @@ static unsigned long int parseBatInfo(const char* fileName, const unsigned short struct dirent* dirEntry = readdir(batteryDir); if (!dirEntry) break; + char* entryName = dirEntry->d_name; if (!String_startsWith(entryName, "BAT")) continue; + batteries[nBatteries] = xStrdup(entryName); nBatteries++; } @@ -74,12 +76,14 @@ static unsigned long int parseBatInfo(const char* fileName, const unsigned short for (unsigned short int j = 0; j < lineNum; j++) { free(line); line = String_readLine(file); - if (!line) break; + if (!line) + break; } fclose(file); - if (!line) break; + if (!line) + break; char* foundNumStr = String_getToken(line, wordNum); const unsigned long int foundNum = atoi(foundNumStr); @@ -122,8 +126,11 @@ static ACPresence procAcpiCheck(void) { continue; } char* line = String_readLine(file); + fclose(file); - if (!line) continue; + + if (!line) + continue; char* isOnline = String_getToken(line, 2); free(line); @@ -139,8 +146,10 @@ static ACPresence procAcpiCheck(void) { } } - if (dir) + if (dir) { closedir(dir); + } + return isOn; } @@ -170,14 +179,21 @@ static inline ssize_t xread(int fd, void* buf, size_t count) { size_t alreadyRead = 0; for (;;) { ssize_t res = read(fd, buf, count); - if (res == -1 && errno == EINTR) continue; + if (res == -1) { + if (errno == EINTR) + continue; + return -1; + } + if (res > 0) { buf = ((char*)buf) + res; count -= res; alreadyRead += res; } - if (res == -1) return -1; - if (count == 0 || res == 0) return alreadyRead; + + if (count == 0 || res == 0) { + return alreadyRead; + } } } @@ -197,6 +213,7 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { struct dirent* dirEntry = readdir(dir); if (!dirEntry) break; + const char* entryName = dirEntry->d_name; char filePath[256]; @@ -257,14 +274,18 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { fullSize = atoi(value); totalFull += fullSize; full = true; - if (now) break; + if (now) { + break; + } continue; } value = (!now) ? match(energy, "NOW=") : NULL; if (value) { totalRemain += atoi(value); now = true; - if (full) break; + if (full) { + break; + } continue; } } @@ -288,7 +309,9 @@ static void Battery_getSysData(double* level, ACPresence* isOnAC) { char buffer[2] = ""; for (;;) { ssize_t res = read(fd3, buffer, 1); - if (res == -1 && errno == EINTR) continue; + if (res == -1 && errno == EINTR) { + continue; + } break; } close(fd3); diff --git a/linux/IOPriorityPanel.c b/linux/IOPriorityPanel.c index 9f85e792..cd4b2e60 100644 --- a/linux/IOPriorityPanel.c +++ b/linux/IOPriorityPanel.c @@ -21,7 +21,11 @@ Panel* IOPriorityPanel_new(IOPriority currPrio) { Panel_setHeader(this, "IO Priority:"); Panel_add(this, (Object*) ListItem_new("None (based on nice)", IOPriority_None)); - if (currPrio == IOPriority_None) Panel_setSelected(this, 0); + + if (currPrio == IOPriority_None) { + Panel_setSelected(this, 0); + } + static const struct { int klass; const char* name; } classes[] = { { .klass = IOPRIO_CLASS_RT, .name = "Realtime" }, { .klass = IOPRIO_CLASS_BE, .name = "Best-effort" }, @@ -33,11 +37,15 @@ Panel* IOPriorityPanel_new(IOPriority currPrio) { xSnprintf(name, sizeof(name) - 1, "%s %d %s", classes[c].name, i, i == 0 ? "(High)" : (i == 7 ? "(Low)" : "")); IOPriority ioprio = IOPriority_tuple(classes[c].klass, i); Panel_add(this, (Object*) ListItem_new(name, ioprio)); - if (currPrio == ioprio) Panel_setSelected(this, Panel_size(this) - 1); + if (currPrio == ioprio) { + Panel_setSelected(this, Panel_size(this) - 1); + } } } Panel_add(this, (Object*) ListItem_new("Idle", IOPriority_Idle)); - if (currPrio == IOPriority_Idle) Panel_setSelected(this, Panel_size(this) - 1); + if (currPrio == IOPriority_Idle) { + Panel_setSelected(this, Panel_size(this) - 1); + } return this; } diff --git a/linux/LinuxProcess.c b/linux/LinuxProcess.c index a5d7eccf..b1bd24d5 100644 --- a/linux/LinuxProcess.c +++ b/linux/LinuxProcess.c @@ -168,8 +168,9 @@ dynamically derived from the cpu nice level of the process: io_priority = (cpu_nice + 20) / 5. -- From ionice(1) man page */ static int LinuxProcess_effectiveIOPriority(const LinuxProcess* this) { - if (IOPriority_class(this->ioPriority) == IOPRIO_CLASS_NONE) + if (IOPriority_class(this->ioPriority) == IOPRIO_CLASS_NONE) { return IOPriority_tuple(IOPRIO_CLASS_BE, (this->super.nice + 20) / 5); + } return this->ioPriority; } @@ -290,8 +291,9 @@ void LinuxProcess_writeField(const Process* this, RichString* str, ProcessField case PERCENT_SWAP_DELAY: LinuxProcess_printDelay(lp->swapin_delay_percent, buffer, n); break; #endif case CTXT: - if (lp->ctxt_diff > 1000) + if (lp->ctxt_diff > 1000) { attr |= A_BOLD; + } xSnprintf(buffer, n, "%5lu ", lp->ctxt_diff); break; case SECATTR: snprintf(buffer, n, "%-30s ", lp->secattr ? lp->secattr : "?"); break; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index 6e7906d5..e91666d0 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -56,14 +56,21 @@ static ssize_t xread(int fd, void* buf, size_t count) { size_t alreadyRead = 0; for (;;) { ssize_t res = read(fd, buf, count); - if (res == -1 && errno == EINTR) continue; + if (res == -1) { + if (errno == EINTR) + continue; + return -1; + } + if (res > 0) { buf = ((char*)buf) + res; count -= res; alreadyRead += res; } - if (res == -1) return -1; - if (count == 0 || res == 0) return alreadyRead; + + if (count == 0 || res == 0) { + return alreadyRead; + } } } @@ -78,6 +85,7 @@ static void LinuxProcessList_initTtyDrivers(LinuxProcessList* this) { int fd = open(PROCTTYDRIVERSFILE, O_RDONLY); if (fd == -1) return; + char* buf = NULL; int bufSize = MAX_READ; int bufLen = 0; @@ -160,21 +168,24 @@ static void LinuxProcessList_initNetlinkSocket(LinuxProcessList* this) { static int LinuxProcessList_computeCPUcount(void) { FILE* file = fopen(PROCSTATFILE, "r"); - if (file == NULL) + if (file == NULL) { CRT_fatalError("Cannot open " PROCSTATFILE); + } int cpus = 0; char buffer[PROC_LINE_LENGTH + 1]; while (fgets(buffer, sizeof(buffer), file)) { - if (String_startsWith(buffer, "cpu")) + if (String_startsWith(buffer, "cpu")) { cpus++; + } } fclose(file); /* subtract raw cpu entry */ - if (cpus > 0) + if (cpus > 0) { cpus--; + } return cpus; } @@ -218,16 +229,18 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui // Read btime { FILE* statfile = fopen(PROCSTATFILE, "r"); - if (statfile == NULL) + if (statfile == NULL) { CRT_fatalError("Cannot open " PROCSTATFILE); + } while (true) { char buffer[PROC_LINE_LENGTH + 1]; if (fgets(buffer, sizeof(buffer), statfile) == NULL) { CRT_fatalError("No btime in " PROCSTATFILE); } else if (String_startsWith(buffer, "btime ")) { - if (sscanf(buffer, "btime %lld\n", &btime) != 1) + if (sscanf(buffer, "btime %lld\n", &btime) != 1) { CRT_fatalError("Failed to parse btime from " PROCSTATFILE); + } break; } } @@ -298,16 +311,19 @@ static bool LinuxProcessList_readStatFile(Process* process, const char* dirname, int size = xread(fd, buf, MAX_READ); close(fd); - if (size <= 0) return false; + if (size <= 0) + return false; buf[size] = '\0'; assert(process->pid == atoi(buf)); char* location = strchr(buf, ' '); - if (!location) return false; + if (!location) + return false; location += 2; char* end = strrchr(location, ')'); - if (!end) return false; + if (!end) + return false; int commsize = MINIMUM(end - location, commLenIn - 1); // deepcode ignore BufferOverflow: commsize is bounded by the allocated length passed in by commLen, saved into commLenIn @@ -359,8 +375,9 @@ static bool LinuxProcessList_readStatFile(Process* process, const char* dirname, location = strchr(location, ' ') + 1; } location += 1; - for (int i = 0; i < 15; i++) + for (int i = 0; i < 15; i++) { location = strchr(location, ' ') + 1; + } process->exit_signal = strtol(location, &location, 10); location += 1; assert(location != NULL); @@ -411,7 +428,9 @@ static void LinuxProcessList_readIoFile(LinuxProcess* process, const char* dirna char buffer[1024]; ssize_t buflen = xread(fd, buffer, 1023); close(fd); - if (buflen < 1) return; + if (buflen < 1) + return; + buffer[buflen] = '\0'; unsigned long long last_read = process->io_read_bytes; unsigned long long last_write = process->io_write_bytes; @@ -464,6 +483,7 @@ static bool LinuxProcessList_readStatmFile(LinuxProcess* process, const char* di FILE* statmfile = fopen(filename, "r"); if (!statmfile) return false; + int r = fscanf(statmfile, "%ld %ld %ld %ld %ld %ld %ld", &process->super.m_size, &process->super.m_resident, @@ -636,9 +656,13 @@ static void LinuxProcessList_readCGroupFile(LinuxProcess* process, const char* d while (!feof(file) && left > 0) { char buffer[PROC_LINE_LENGTH + 1]; char* ok = fgets(buffer, PROC_LINE_LENGTH, file); - if (!ok) break; + if (!ok) + break; + char* group = strchr(buffer, ':'); - if (!group) break; + if (!group) + break; + if (at != output) { *at = ';'; at++; @@ -662,6 +686,7 @@ static void LinuxProcessList_readVServerData(LinuxProcess* process, const char* FILE* file = fopen(filename, "r"); if (!file) return; + char buffer[PROC_LINE_LENGTH + 1]; process->vxid = 0; while (fgets(buffer, PROC_LINE_LENGTH, file)) { @@ -711,19 +736,22 @@ static void LinuxProcessList_readCtxtData(LinuxProcess* process, const char* dir FILE* file = fopen(filename, "r"); if (!file) return; + char buffer[PROC_LINE_LENGTH + 1]; unsigned long ctxt = 0; while (fgets(buffer, PROC_LINE_LENGTH, file)) { if (String_startsWith(buffer, "voluntary_ctxt_switches:")) { unsigned long vctxt; int ok = sscanf(buffer, "voluntary_ctxt_switches:\t%lu", &vctxt); - if (ok >= 1) + if (ok >= 1) { ctxt += vctxt; + } } else if (String_startsWith(buffer, "nonvoluntary_ctxt_switches:")) { unsigned long nvctxt; int ok = sscanf(buffer, "nonvoluntary_ctxt_switches:\t%lu", &nvctxt); - if (ok >= 1) + if (ok >= 1) { ctxt += nvctxt; + } } } fclose(file); @@ -749,10 +777,12 @@ static void LinuxProcessList_readSecattrData(LinuxProcess* process, const char* return; } char* newline = strchr(buffer, '\n'); - if (newline) + if (newline) { *newline = '\0'; - if (process->secattr && String_eq(process->secattr, buffer)) + } + if (process->secattr && String_eq(process->secattr, buffer)) { return; + } free(process->secattr); process->secattr = xStrdup(buffer); } @@ -905,17 +935,28 @@ static char* LinuxProcessList_updateTtyDevice(TtyDriver* ttyDrivers, unsigned in for (;;) { xAsprintf(&fullPath, "%s/%d", ttyDrivers[i].path, idx); int err = stat(fullPath, &sstat); - if (err == 0 && major(sstat.st_rdev) == maj && minor(sstat.st_rdev) == min) return fullPath; + if (err == 0 && major(sstat.st_rdev) == maj && minor(sstat.st_rdev) == min) { + return fullPath; + } free(fullPath); + xAsprintf(&fullPath, "%s%d", ttyDrivers[i].path, idx); err = stat(fullPath, &sstat); - if (err == 0 && major(sstat.st_rdev) == maj && minor(sstat.st_rdev) == min) return fullPath; + if (err == 0 && major(sstat.st_rdev) == maj && minor(sstat.st_rdev) == min) { + return fullPath; + } free(fullPath); - if (idx == min) break; + + if (idx == min) { + break; + } + idx = min; } int err = stat(ttyDrivers[i].path, &sstat); - if (err == 0 && tty_nr == sstat.st_rdev) return xStrdup(ttyDrivers[i].path); + if (err == 0 && tty_nr == sstat.st_rdev) { + return xStrdup(ttyDrivers[i].path); + } } char* out; xAsprintf(&out, "/dev/%u:%u", maj, min); @@ -933,7 +974,9 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* #endif dir = opendir(dirname); - if (!dir) return false; + if (!dir) + return false; + int cpus = pl->cpuCount; bool hideKernelThreads = settings->hideKernelThreads; bool hideUserlandThreads = settings->hideUserlandThreads; @@ -1001,15 +1044,21 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* unsigned int tty_nr = proc->tty_nr; if (! LinuxProcessList_readStatFile(proc, dirname, name, command, &commLen)) goto errorReadingProcess; + if (tty_nr != proc->tty_nr && this->ttyDrivers) { free(lp->ttyDevice); lp->ttyDevice = LinuxProcessList_updateTtyDevice(this->ttyDrivers, proc->tty_nr); } - if (settings->flags & PROCESS_FLAG_LINUX_IOPRIO) + + if (settings->flags & PROCESS_FLAG_LINUX_IOPRIO) { LinuxProcess_updateIOPriority(lp); + } + float percent_cpu = (lp->utime + lp->stime - lasttimes) / period * 100.0; proc->percent_cpu = CLAMP(percent_cpu, 0.0, cpus * 100.0); - if (isnan(proc->percent_cpu)) proc->percent_cpu = 0.0; + if (isnan(proc->percent_cpu)) + proc->percent_cpu = 0.0; + proc->percent_mem = (proc->m_resident * CRT_pageSizeKB) / (double)(pl->totalMem) * 100.0; if (!preExisting) { @@ -1051,18 +1100,22 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* #endif #ifdef HAVE_CGROUP - if (settings->flags & PROCESS_FLAG_LINUX_CGROUP) + if (settings->flags & PROCESS_FLAG_LINUX_CGROUP) { LinuxProcessList_readCGroupFile(lp, dirname, name); + } #endif - if (settings->flags & PROCESS_FLAG_LINUX_OOM) + if (settings->flags & PROCESS_FLAG_LINUX_OOM) { LinuxProcessList_readOomData(lp, dirname, name); + } - if (settings->flags & PROCESS_FLAG_LINUX_CTXT) + if (settings->flags & PROCESS_FLAG_LINUX_CTXT) { LinuxProcessList_readCtxtData(lp, dirname, name); + } - if (settings->flags & PROCESS_FLAG_LINUX_SECATTR) + if (settings->flags & PROCESS_FLAG_LINUX_SECATTR) { LinuxProcessList_readSecattrData(lp, dirname, name); + } if (proc->state == 'Z' && (proc->basenameOffset == 0)) { proc->basenameOffset = -1; @@ -1072,8 +1125,9 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* proc->basenameOffset = -1; setCommand(proc, command, commLen); } else if (settings->showThreadNames) { - if (! LinuxProcessList_readCmdlineFile(proc, dirname, name)) + if (! LinuxProcessList_readCmdlineFile(proc, dirname, name)) { goto errorReadingProcess; + } } if (Process_isKernelThread(proc)) { pl->kernelThreads++; @@ -1293,10 +1347,13 @@ static inline double LinuxProcessList_scanCPUTime(LinuxProcessList* this) { // 5, 7, 8 or 9 of these fields will be set. // The rest will remain at zero. char* ok = fgets(buffer, PROC_LINE_LENGTH, file); - if (!ok) buffer[0] = '\0'; - if (i == 0) + if (!ok) { + buffer[0] = '\0'; + } + + if (i == 0) { (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 { + } else { int cpuid; (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); @@ -1404,13 +1461,15 @@ static void scanCPUFreqencyFromCPUinfo(LinuxProcessList* this) { (sscanf(buffer, "cpu MHz : %lf", &frequency) == 1) || (sscanf(buffer, "cpu MHz: %lf", &frequency) == 1) ) { - if (cpuid < 0 || cpuid > (cpus - 1)) + if (cpuid < 0 || cpuid > (cpus - 1)) { continue; + } CPUData* cpuData = &(this->cpus[cpuid + 1]); /* do not override sysfs data */ - if (isnan(cpuData->frequency)) + if (isnan(cpuData->frequency)) { cpuData->frequency = frequency; + } numCPUsWithFrequency++; totalFrequency += frequency; } else if (buffer[0] == '\n') { @@ -1419,19 +1478,22 @@ static void scanCPUFreqencyFromCPUinfo(LinuxProcessList* this) { } fclose(file); - if (numCPUsWithFrequency > 0) + if (numCPUsWithFrequency > 0) { this->cpus[0].frequency = totalFrequency / numCPUsWithFrequency; + } } static void LinuxProcessList_scanCPUFrequency(LinuxProcessList* this) { int cpus = this->super.cpuCount; assert(cpus > 0); - for (int i = 0; i <= cpus; i++) + for (int i = 0; i <= cpus; i++) { this->cpus[i].frequency = NAN; + } - if (scanCPUFreqencyFromSysCPUFreq(this) == 0) + if (scanCPUFreqencyFromSysCPUFreq(this) == 0) { return; + } scanCPUFreqencyFromCPUinfo(this); } @@ -1447,12 +1509,14 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { double period = LinuxProcessList_scanCPUTime(this); - if (settings->showCPUFrequency) + if (settings->showCPUFrequency) { LinuxProcessList_scanCPUFrequency(this); + } // in pause mode only gather global data for meters (CPU/memory/...) - if (pauseProcessUpdate) + if (pauseProcessUpdate) { return; + } struct timeval tv; gettimeofday(&tv, NULL); diff --git a/linux/Platform.c b/linux/Platform.c index 3da3f029..66200acc 100644 --- a/linux/Platform.c +++ b/linux/Platform.c @@ -98,15 +98,18 @@ static Htop_Reaction Platform_actionSetIOPriority(State* st) { Panel* panel = st->panel; LinuxProcess* p = (LinuxProcess*) Panel_getSelected(panel); - if (!p) return HTOP_OK; + if (!p) + return HTOP_OK; + IOPriority ioprio1 = p->ioPriority; Panel* ioprioPanel = IOPriorityPanel_new(ioprio1); void* set = Action_pickFromVector(st, ioprioPanel, 21, true); if (set) { IOPriority ioprio2 = IOPriorityPanel_getIOPriority(ioprioPanel); - bool ok = MainPanel_foreachProcess((MainPanel*)panel, LinuxProcess_setIOPriority, (Arg){ .i = ioprio2 }, NULL); - if (!ok) + bool ok = MainPanel_foreachProcess((MainPanel*)panel, LinuxProcess_setIOPriority, (Arg) { .i = ioprio2 }, NULL); + if (!ok) { beep(); + } } Panel_delete((Object*)ioprioPanel); return HTOP_REFRESH | HTOP_REDRAW_BAR | HTOP_UPDATE_PANELHDR; @@ -162,7 +165,9 @@ int Platform_getUptime() { if (fd) { int n = fscanf(fd, "%64lf", &uptime); fclose(fd); - if (n <= 0) return 0; + if (n <= 0) { + return 0; + } } return floor(uptime); } @@ -185,7 +190,9 @@ void Platform_getLoadAverage(double* one, double* five, double* fifteen) { int Platform_getMaxPid() { FILE* file = fopen(PROCDIR "/sys/kernel/pid_max", "r"); - if (!file) return -1; + if (!file) + return -1; + int maxPid = 4194303; int match = fscanf(file, "%32d", &maxPid); (void) match; @@ -221,7 +228,9 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = v[0] + v[1] + v[2] + v[3]; } percent = CLAMP(percent, 0.0, 100.0); - if (isnan(percent)) percent = 0.0; + if (isnan(percent)) { + percent = 0.0; + } v[CPU_METER_FREQUENCY] = cpuData->frequency; diff --git a/linux/SELinuxMeter.c b/linux/SELinuxMeter.c index 275eefef..ee1d8470 100644 --- a/linux/SELinuxMeter.c +++ b/linux/SELinuxMeter.c @@ -32,16 +32,19 @@ static bool enforcing = false; static bool hasSELinuxMount(void) { struct statfs sfbuf; int r = statfs("/sys/fs/selinux", &sfbuf); - if (r != 0) + if (r != 0) { return false; + } - if (sfbuf.f_type != SELINUX_MAGIC) + if (sfbuf.f_type != SELINUX_MAGIC) { return false; + } struct statvfs vfsbuf; r = statvfs("/sys/fs/selinux", &vfsbuf); - if (r != 0 || (vfsbuf.f_flag & ST_RDONLY)) + if (r != 0 || (vfsbuf.f_flag & ST_RDONLY)) { return false; + } return true; } @@ -51,22 +54,26 @@ static bool isSelinuxEnabled(void) { } static bool isSelinuxEnforcing(void) { - if (!enabled) + if (!enabled) { return false; + } int fd = open("/sys/fs/selinux/enforce", O_RDONLY); - if (fd < 0) + if (fd < 0) { return false; + } char buf[20] = {0}; int r = read(fd, buf, sizeof(buf) - 1); close(fd); - if (r < 0) + if (r < 0) { return false; + } int enforce = 0; - if (sscanf(buf, "%d", &enforce) != 1) + if (sscanf(buf, "%d", &enforce) != 1) { return false; + } return !!enforce; } diff --git a/openbsd/OpenBSDProcessList.c b/openbsd/OpenBSDProcessList.c index bfac535d..aec13477 100644 --- a/openbsd/OpenBSDProcessList.c +++ b/openbsd/OpenBSDProcessList.c @@ -347,8 +347,9 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { OpenBSDProcessList_scanCPUTime(opl); // in pause mode only gather global data for meters (CPU/memory/...) - if (pauseProcessUpdate) + if (pauseProcessUpdate) { return; + } OpenBSDProcessList_scanProcs(opl); } diff --git a/openbsd/Platform.c b/openbsd/Platform.c index 21a33d1e..055ffa99 100644 --- a/openbsd/Platform.c +++ b/openbsd/Platform.c @@ -184,7 +184,9 @@ double Platform_setCPUValues(Meter* this, int cpu) { } totalPercent = CLAMP(totalPercent, 0.0, 100.0); - if (isnan(totalPercent)) totalPercent = 0.0; + if (isnan(totalPercent)) { + totalPercent = 0.0; + } return totalPercent; } @@ -250,8 +252,9 @@ char* Platform_getProcessEnv(pid_t pid) { struct kinfo_proc* kproc; size_t capacity = 4096, size = 0; - if ((kt = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf)) == NULL) + if ((kt = kvm_openfiles(NULL, NULL, NULL, KVM_NO_FILES, errbuf)) == NULL) { return NULL; + } if ((kproc = kvm_getprocs(kt, KERN_PROC_PID, pid, sizeof(struct kinfo_proc), &count)) == NULL) { diff --git a/solaris/Platform.c b/solaris/Platform.c index 69777726..6159c357 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -156,13 +156,19 @@ int Platform_getMaxPid() { kvar_t* ksvar = NULL; int vproc = 32778; // Reasonable Solaris default kc = kstat_open(); - if (kc != NULL) { kshandle = kstat_lookup(kc,"unix",0,"var"); } - if (kshandle != NULL) { kstat_read(kc,kshandle,NULL); } + if (kc != NULL) { + kshandle = kstat_lookup(kc, "unix", 0, "var"); + } + if (kshandle != NULL) { + kstat_read(kc, kshandle, NULL); + } ksvar = kshandle->ks_data; if (ksvar->v_proc > 0 ) { vproc = ksvar->v_proc; } - if (kc != NULL) { kstat_close(kc); } + if (kc != NULL) { + kstat_close(kc); + } return vproc; } @@ -195,7 +201,9 @@ double Platform_setCPUValues(Meter* this, int cpu) { } percent = CLAMP(percent, 0.0, 100.0); - if (isnan(percent)) percent = 0.0; + if (isnan(percent)) { + percent = 0.0; + } v[CPU_METER_FREQUENCY] = NAN; @@ -233,10 +241,12 @@ static int Platform_buildenv(void* accum, struct ps_prochandle* Phandle, uintptr (void) Phandle; (void) addr; size_t thissz = strlen(str); - if ((thissz + 2) > (accump->capacity - accump->size)) + if ((thissz + 2) > (accump->capacity - accump->size)) { accump->env = xRealloc(accump->env, accump->capacity *= 2); - if ((thissz + 2) > (accump->capacity - accump->size)) + } + if ((thissz + 2) > (accump->capacity - accump->size)) { return 1; + } strlcpy( accump->env + accump->size, str, (accump->capacity - accump->size)); strncpy( accump->env + accump->size + thissz + 1, "\n", 1); accump->size = accump->size + thissz + 1; @@ -249,8 +259,9 @@ char* Platform_getProcessEnv(pid_t pid) { int graberr; struct ps_prochandle* Phandle; - if ((Phandle = Pgrab(realpid, PGRAB_RDONLY, &graberr)) == NULL) + if ((Phandle = Pgrab(realpid, PGRAB_RDONLY, &graberr)) == NULL) { return "Unable to read process environment."; + } envBuilder.capacity = 4096; envBuilder.size = 0; diff --git a/solaris/SolarisProcessList.c b/solaris/SolarisProcessList.c index 31507506..49aeb24c 100644 --- a/solaris/SolarisProcessList.c +++ b/solaris/SolarisProcessList.c @@ -169,10 +169,11 @@ static inline void SolarisProcessList_scanMemoryInfo(ProcessList* pl) { pages = kstat_data_lookup(meminfo, "pagestotal"); pl->totalMem = totalmem_pgs->value.ui64 * CRT_pageSizeKB; - if (pl->totalMem > freemem_pgs->value.ui64 * CRT_pageSizeKB) + if (pl->totalMem > freemem_pgs->value.ui64 * CRT_pageSizeKB) { pl->usedMem = pl->totalMem - freemem_pgs->value.ui64 * CRT_pageSizeKB; - else - pl->usedMem = 0; // This can happen in non-global zone (in theory) + } else { + pl->usedMem = 0; // This can happen in non-global zone (in theory) + } // Not sure how to implement this on Solaris - suggestions welcome! pl->cachedMem = 0; // Not really "buffers" but the best Solaris analogue that I can find to @@ -268,7 +269,9 @@ void ProcessList_delete(ProcessList* pl) { SolarisProcessList* spl = (SolarisProcessList*) pl; ProcessList_done(pl); free(spl->cpus); - if (spl->kd) kstat_close(spl->kd); + if (spl->kd) { + kstat_close(spl->kd); + } free(spl); } @@ -287,7 +290,10 @@ int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo, void* SolarisProcessList* spl = (SolarisProcessList*) listptr; id_t lwpid_real = _lwpsinfo->pr_lwpid; - if (lwpid_real > 1023) return 0; + if (lwpid_real > 1023) { + return 0; + } + pid_t lwpid = (_psinfo->pr_pid * 1024) + lwpid_real; bool onMasterLWP = (_lwpsinfo->pr_lwpid == _psinfo->pr_lwp.pr_lwpid); if (onMasterLWP) { @@ -347,9 +353,13 @@ int SolarisProcessList_walkproc(psinfo_t* _psinfo, lwpsinfo_t* _lwpsinfo, void* if (sproc->kernel && !pl->settings->hideKernelThreads) { pl->kernelThreads += proc->nlwp; pl->totalTasks += proc->nlwp + 1; - if (proc->state == 'O') pl->runningTasks++; + if (proc->state == 'O') { + pl->runningTasks++; + } } else if (!sproc->kernel) { - if (proc->state == 'O') pl->runningTasks++; + if (proc->state == 'O') { + pl->runningTasks++; + } if (pl->settings->hideUserlandThreads) { pl->totalTasks++; } else { @@ -403,8 +413,9 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { SolarisProcessList_scanZfsArcstats(super); // in pause mode only gather global data for meters (CPU/memory/...) - if (pauseProcessUpdate) + if (pauseProcessUpdate) { return; + } super->kernelThreads = 1; proc_walk(&SolarisProcessList_walkproc, super, PR_WALK_LWP); diff --git a/unsupported/UnsupportedProcessList.c b/unsupported/UnsupportedProcessList.c index 24668b69..6c0e0229 100644 --- a/unsupported/UnsupportedProcessList.c +++ b/unsupported/UnsupportedProcessList.c @@ -27,8 +27,9 @@ void ProcessList_delete(ProcessList* this) { void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { // in pause mode only gather global data for meters (CPU/memory/...) - if (pauseProcessUpdate) + if (pauseProcessUpdate) { return; + } bool preExisting = true; Process* proc; From 0d64ca92627a42f78dc980ec53081eeadd49b262 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sun, 1 Nov 2020 01:49:54 +0100 Subject: [PATCH 13/17] Wrap inline structure definitions --- Action.c | 10 ++++++++-- linux/IOPriorityPanel.c | 7 ++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Action.c b/Action.c index 8a6e2cbe..45128fad 100644 --- a/Action.c +++ b/Action.c @@ -425,7 +425,10 @@ static Htop_Reaction actionTogglePauseProcessUpdate(State* st) { return HTOP_REFRESH | HTOP_REDRAW_BAR; } -static const struct { const char* key; const char* info; } helpLeft[] = { +static const struct { + const char* key; + const char* info; +} helpLeft[] = { { .key = " Arrows: ", .info = "scroll process list" }, { .key = " Digits: ", .info = "incremental PID search" }, { .key = " F3 /: ", .info = "incremental name search" }, @@ -444,7 +447,10 @@ static const struct { const char* key; const char* info; } helpLeft[] = { { .key = NULL, .info = NULL } }; -static const struct { const char* key; const char* info; } helpRight[] = { +static const struct { + const char* key; + const char* info; +} helpRight[] = { { .key = " Space: ", .info = "tag process" }, { .key = " c: ", .info = "tag process and its children" }, { .key = " U: ", .info = "untag all processes" }, diff --git a/linux/IOPriorityPanel.c b/linux/IOPriorityPanel.c index cd4b2e60..bd84241e 100644 --- a/linux/IOPriorityPanel.c +++ b/linux/IOPriorityPanel.c @@ -21,12 +21,13 @@ Panel* IOPriorityPanel_new(IOPriority currPrio) { Panel_setHeader(this, "IO Priority:"); Panel_add(this, (Object*) ListItem_new("None (based on nice)", IOPriority_None)); - if (currPrio == IOPriority_None) { Panel_setSelected(this, 0); } - - static const struct { int klass; const char* name; } classes[] = { + static const struct { + int klass; + const char* name; + } classes[] = { { .klass = IOPRIO_CLASS_RT, .name = "Realtime" }, { .klass = IOPRIO_CLASS_BE, .name = "Best-effort" }, { .klass = 0, .name = NULL } From 1c060a9d6bde6109b5c2d003a9c275b419dd2d62 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 2 Nov 2020 21:30:47 +0100 Subject: [PATCH 14/17] Avoid RichString_beginAllocated being ammendable --- RichString.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RichString.h b/RichString.h index 5bcda602..fdf6ba35 100644 --- a/RichString.h +++ b/RichString.h @@ -16,7 +16,7 @@ in the source distribution for its full text. #define RichString_sizeVal(this) ((this).chlen) #define RichString_begin(this) RichString (this); RichString_beginAllocated(this) -#define RichString_beginAllocated(this) memset(&(this), 0, sizeof(RichString)); (this).chptr = (this).chstr +#define RichString_beginAllocated(this) do { memset(&(this), 0, sizeof(RichString)); (this).chptr = (this).chstr; } while(0) #define RichString_end(this) RichString_prune(&(this)) #ifdef HAVE_LIBNCURSESW From cb8bb12974af25fc845acc008c529eb86835fe6f Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 2 Nov 2020 21:32:20 +0100 Subject: [PATCH 15/17] Shorten initializer --- TraceScreen.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/TraceScreen.c b/TraceScreen.c index b1277488..1280b1e4 100644 --- a/TraceScreen.c +++ b/TraceScreen.c @@ -143,9 +143,7 @@ void TraceScreen_updateTrace(InfoScreen* super) { // FD_SET(STDIN_FILENO, &fds); FD_SET(fd_strace, &fds); - struct timeval tv; - tv.tv_sec = 0; - tv.tv_usec = 500; + struct timeval tv = { .tv_sec = 0, .tv_usec = 500 }; int ready = select(fd_strace + 1, &fds, NULL, NULL, &tv); size_t nread = 0; From 0e922d4085f0285cf353323fd5a96edae604d5da Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 2 Nov 2020 21:36:20 +0100 Subject: [PATCH 16/17] Integrate NAN check into assignment The check for NAN is kept to avoid relying on implementation details of the CLAMP macro/function --- dragonflybsd/Platform.c | 5 +---- linux/LinuxProcessList.c | 5 +---- solaris/Platform.c | 5 +---- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 5f9f6373..604994c4 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -176,10 +176,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = v[0] + v[1] + v[2]; } - percent = CLAMP(percent, 0.0, 100.0); - if (isnan(percent)) { - percent = 0.0; - } + percent = isnan(percent) ? 0.0 : CLAMP(percent, 0.0, 100.0); v[CPU_METER_FREQUENCY] = NAN; diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index e91666d0..d3416de5 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -1055,10 +1055,7 @@ static bool LinuxProcessList_recurseProcTree(LinuxProcessList* this, const char* } float percent_cpu = (lp->utime + lp->stime - lasttimes) / period * 100.0; - proc->percent_cpu = CLAMP(percent_cpu, 0.0, cpus * 100.0); - if (isnan(proc->percent_cpu)) - proc->percent_cpu = 0.0; - + proc->percent_cpu = isnan(percent_cpu) ? 0.0 : CLAMP(percent_cpu, 0.0, cpus * 100.0); proc->percent_mem = (proc->m_resident * CRT_pageSizeKB) / (double)(pl->totalMem) * 100.0; if (!preExisting) { diff --git a/solaris/Platform.c b/solaris/Platform.c index 6159c357..e7a70c2c 100644 --- a/solaris/Platform.c +++ b/solaris/Platform.c @@ -200,10 +200,7 @@ double Platform_setCPUValues(Meter* this, int cpu) { percent = v[0] + v[1] + v[2]; } - percent = CLAMP(percent, 0.0, 100.0); - if (isnan(percent)) { - percent = 0.0; - } + percent = isnan(percent) ? 0.0 : CLAMP(percent, 0.0, 100.0); v[CPU_METER_FREQUENCY] = NAN; From e7b95feee4f375738cb339a58337fdab83f6abbf Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 2 Nov 2020 21:37:25 +0100 Subject: [PATCH 17/17] Remove unnecessary braces --- linux/LinuxProcessList.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/LinuxProcessList.c b/linux/LinuxProcessList.c index d3416de5..4227dd38 100644 --- a/linux/LinuxProcessList.c +++ b/linux/LinuxProcessList.c @@ -808,7 +808,7 @@ static int handleNetlinkMsg(struct nl_msg* nlmsg, void* linuxProcess) { memcpy(&stats, nla_data(nla_next(nla_data(nlattr), &rem)), sizeof(stats)); assert(lp->super.pid == (pid_t)stats.ac_pid); - timeDelta = (stats.ac_etime * 1000 - lp->delay_read_time); + 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);