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) --- freebsd/FreeBSDProcessList.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'freebsd') 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); -- 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 --- freebsd/FreeBSDProcessList.c | 42 +++++++++++++++++++++--------------------- freebsd/Platform.c | 6 +++--- 2 files changed, 24 insertions(+), 24 deletions(-) (limited to 'freebsd') 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; -- 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 --- freebsd/FreeBSDProcess.c | 2 +- freebsd/FreeBSDProcessList.c | 16 ++++++++-------- freebsd/FreeBSDProcessList.h | 8 ++++---- freebsd/Platform.c | 18 +++++++++--------- freebsd/Platform.h | 8 ++++---- 5 files changed, 26 insertions(+), 26 deletions(-) (limited to 'freebsd') 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 -- 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 --- freebsd/Battery.c | 10 ++++++---- freebsd/FreeBSDProcess.c | 5 +++-- freebsd/FreeBSDProcessList.c | 36 ++++++++++++++++++++++++------------ 3 files changed, 33 insertions(+), 18 deletions(-) (limited to 'freebsd') 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++; -- cgit v1.2.3