From 374edb9ed5e9d5fa24cfe358258d82f69d9d430d Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 20:52:20 +0100 Subject: Spacing after keywords (if) --- dragonflybsd/DragonFlyBSDProcessList.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dragonflybsd') 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); } -- cgit v1.2.3 From b23f8235e28472c410dcb00893e0e3d403892673 Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 22:14:27 +0100 Subject: Whitespace and indentation issues --- dragonflybsd/DragonFlyBSDProcessList.c | 47 +++++++++++++++++----------------- dragonflybsd/Platform.c | 6 ++--- 2 files changed, 27 insertions(+), 26 deletions(-) (limited to 'dragonflybsd') 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; -- cgit v1.2.3 From 61e14d4bb25268593019e6df3eb02264b4ac8e0e Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sat, 31 Oct 2020 23:28:02 +0100 Subject: Spacing around operators --- dragonflybsd/DragonFlyBSDProcess.c | 2 +- dragonflybsd/DragonFlyBSDProcessList.c | 16 ++++++++-------- dragonflybsd/DragonFlyBSDProcessList.h | 10 +++++----- dragonflybsd/Platform.c | 12 ++++++------ dragonflybsd/Platform.h | 8 ++++---- 5 files changed, 24 insertions(+), 24 deletions(-) (limited to 'dragonflybsd') 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 -- cgit v1.2.3 From 45869513bfebba80cc2ab42e4218f68b34b1e6ac Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Sun, 1 Nov 2020 01:09:51 +0100 Subject: Embracing branches --- dragonflybsd/Battery.c | 10 ++++++---- dragonflybsd/DragonFlyBSDProcess.c | 5 +++-- dragonflybsd/DragonFlyBSDProcessList.c | 14 ++++++++++---- dragonflybsd/Platform.c | 4 +++- 4 files changed, 22 insertions(+), 11 deletions(-) (limited to 'dragonflybsd') 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; -- cgit v1.2.3 From 0e922d4085f0285cf353323fd5a96edae604d5da Mon Sep 17 00:00:00 2001 From: Benny Baumann Date: Mon, 2 Nov 2020 21:36:20 +0100 Subject: 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 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'dragonflybsd') 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; -- cgit v1.2.3