diff options
author | Daniel Lange <DLange@git.local> | 2020-11-15 14:32:41 +0100 |
---|---|---|
committer | Daniel Lange <DLange@git.local> | 2020-11-15 14:33:09 +0100 |
commit | bb908f3dc4ac5847592e9698dec150658067e84e (patch) | |
tree | fb0d7b03602de14f4ba6efbdd9f8a9f3cf7cc067 /freebsd | |
parent | da2dcf9505299eae607e29cc85691b8163c1a36e (diff) | |
parent | e7b95feee4f375738cb339a58337fdab83f6abbf (diff) |
Resolve merge conflicts, merge #298 "Macro cleanup" from @BenBE
Diffstat (limited to 'freebsd')
-rw-r--r-- | freebsd/Battery.c | 10 | ||||
-rw-r--r-- | freebsd/FreeBSDProcess.c | 7 | ||||
-rw-r--r-- | freebsd/FreeBSDProcessList.c | 98 | ||||
-rw-r--r-- | freebsd/FreeBSDProcessList.h | 8 | ||||
-rw-r--r-- | freebsd/Platform.c | 24 | ||||
-rw-r--r-- | freebsd/Platform.h | 8 |
6 files changed, 85 insertions, 70 deletions
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 fee2c2c8..baad5d13 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] = ' '; @@ -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 df06546c..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; } @@ -124,10 +126,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)); } @@ -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); @@ -175,8 +179,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]; @@ -187,12 +191,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 +206,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,19 +222,21 @@ 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 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) { - 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]); @@ -415,18 +421,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; @@ -434,20 +440,22 @@ 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; } } else { - jnamebuf[0]='-'; - jnamebuf[1]='\0'; + jnamebuf[0] = '-'; + jnamebuf[1] = '\0'; jname = xStrdup(jnamebuf); } return jname; @@ -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; @@ -502,7 +513,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 +523,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); @@ -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/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 a49cfd25..9fd2f4d0 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; @@ -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; @@ -294,10 +294,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 2cdd068d..72e964aa 100644 --- a/freebsd/Platform.h +++ b/freebsd/Platform.h @@ -54,9 +54,9 @@ FileLocks_ProcessData* Platform_getProcessLocks(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 |