From c55320e9e2a8916e911bcd39ab37b79e3a7d03b2 Mon Sep 17 00:00:00 2001 From: Daniel Lange Date: Mon, 11 Jan 2021 20:43:27 +0100 Subject: New upstream version 3.0.5 --- dragonflybsd/DragonFlyBSDProcess.c | 88 ++++++++++++---------------------- dragonflybsd/DragonFlyBSDProcess.h | 15 +----- dragonflybsd/DragonFlyBSDProcessList.c | 37 ++++++-------- dragonflybsd/DragonFlyBSDProcessList.h | 8 ---- dragonflybsd/Platform.c | 4 +- dragonflybsd/Platform.h | 5 +- dragonflybsd/ProcessField.h | 17 +++++++ 7 files changed, 65 insertions(+), 109 deletions(-) create mode 100644 dragonflybsd/ProcessField.h (limited to 'dragonflybsd') diff --git a/dragonflybsd/DragonFlyBSDProcess.c b/dragonflybsd/DragonFlyBSDProcess.c index 9311f03..15b1a69 100644 --- a/dragonflybsd/DragonFlyBSDProcess.c +++ b/dragonflybsd/DragonFlyBSDProcess.c @@ -18,26 +18,16 @@ in the source distribution for its full text. #include -const ProcessClass DragonFlyBSDProcess_class = { - .super = { - .extends = Class(Process), - .display = Process_display, - .delete = Process_delete, - .compare = DragonFlyBSDProcess_compare - }, - .writeField = DragonFlyBSDProcess_writeField, -}; - -ProcessFieldData Process_fields[] = { +const ProcessFieldData Process_fields[LAST_PROCESSFIELD] = { [0] = { .name = "", .title = NULL, .description = NULL, .flags = 0, }, - [PID] = { .name = "PID", .title = " PID ", .description = "Process/thread ID", .flags = 0, }, + [PID] = { .name = "PID", .title = "PID", .description = "Process/thread ID", .flags = 0, .pidColumn = true, }, [COMM] = { .name = "Command", .title = "Command ", .description = "Command line", .flags = 0, }, [STATE] = { .name = "STATE", .title = "S ", .description = "Process state (S sleeping (<20s), I Idle, Q Queued for Run, R running, D disk, Z zombie, T traced, W paging, B Blocked, A AskedPage, C Core, J Jailed)", .flags = 0, }, - [PPID] = { .name = "PPID", .title = " PPID ", .description = "Parent process ID", .flags = 0, }, - [PGRP] = { .name = "PGRP", .title = " PGRP ", .description = "Process group ID", .flags = 0, }, - [SESSION] = { .name = "SESSION", .title = " SID ", .description = "Process's session ID", .flags = 0, }, + [PPID] = { .name = "PPID", .title = "PPID", .description = "Parent process ID", .flags = 0, .pidColumn = true, }, + [PGRP] = { .name = "PGRP", .title = "PGRP", .description = "Process group ID", .flags = 0, .pidColumn = true, }, + [SESSION] = { .name = "SESSION", .title = "SID", .description = "Process's session ID", .flags = 0, .pidColumn = true, }, [TTY_NR] = { .name = "TTY_NR", .title = " TTY ", .description = "Controlling terminal", .flags = 0, }, - [TPGID] = { .name = "TPGID", .title = " TPGID ", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, }, + [TPGID] = { .name = "TPGID", .title = "TPGID", .description = "Process ID of the fg process group of the controlling terminal", .flags = 0, .pidColumn = true, }, [MINFLT] = { .name = "MINFLT", .title = " MINFLT ", .description = "Number of minor faults which have not required loading a memory page from disk", .flags = 0, }, [MAJFLT] = { .name = "MAJFLT", .title = " MAJFLT ", .description = "Number of major faults which have required loading a memory page from disk", .flags = 0, }, [PRIORITY] = { .name = "PRIORITY", .title = "PRI ", .description = "Kernel's internal priority for the process", .flags = 0, }, @@ -53,21 +43,9 @@ ProcessFieldData Process_fields[] = { [USER] = { .name = "USER", .title = "USER ", .description = "Username of the process owner (or user ID if name cannot be determined)", .flags = 0, }, [TIME] = { .name = "TIME", .title = " TIME+ ", .description = "Total time the process has spent in user and system time", .flags = 0, }, [NLWP] = { .name = "NLWP", .title = "NLWP ", .description = "Number of threads in the process", .flags = 0, }, - [TGID] = { .name = "TGID", .title = " TGID ", .description = "Thread group ID (i.e. process ID)", .flags = 0, }, - [JID] = { .name = "JID", .title = " JID ", .description = "Jail prison ID", .flags = 0, }, + [TGID] = { .name = "TGID", .title = "TGID", .description = "Thread group ID (i.e. process ID)", .flags = 0, .pidColumn = true, }, + [JID] = { .name = "JID", .title = "JID", .description = "Jail prison ID", .flags = 0, .pidColumn = true, }, [JAIL] = { .name = "JAIL", .title = "JAIL ", .description = "Jail prison name", .flags = 0, }, - [LAST_PROCESSFIELD] = { .name = "*** report bug! ***", .title = NULL, .description = NULL, .flags = 0, }, -}; - -ProcessPidColumn Process_pidColumns[] = { - { .id = JID, .label = "JID" }, - { .id = PID, .label = "PID" }, - { .id = PPID, .label = "PPID" }, - { .id = TPGID, .label = "TPGID" }, - { .id = TGID, .label = "TGID" }, - { .id = PGRP, .label = "PGRP" }, - { .id = SESSION, .label = "SID" }, - { .id = 0, .label = NULL }, }; Process* DragonFlyBSDProcess_new(const Settings* settings) { @@ -84,50 +62,35 @@ void Process_delete(Object* cast) { free(this); } -void DragonFlyBSDProcess_writeField(const Process* this, RichString* str, ProcessField field) { +static void DragonFlyBSDProcess_writeField(const Process* this, RichString* str, ProcessField field) { const DragonFlyBSDProcess* fp = (const DragonFlyBSDProcess*) this; char buffer[256]; buffer[255] = '\0'; int attr = CRT_colors[DEFAULT_COLOR]; - int n = sizeof(buffer) - 1; - switch ((int) field) { + size_t n = sizeof(buffer) - 1; + switch (field) { // 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: { - xSnprintf(buffer, n, "%-11s ", fp->jname); - if (buffer[11] != '\0') { - buffer[11] = ' '; - buffer[12] = '\0'; - } - break; - } + case PID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, (fp->kernel ? -1 : this->pid)); break; + case JID: xSnprintf(buffer, n, "%*d ", Process_pidDigits, fp->jid); break; + case JAIL: Process_printLeftAlignedField(str, attr, fp->jname, 11); return; default: Process_writeField(this, str, field); return; } - RichString_append(str, attr, buffer); + RichString_appendWide(str, attr, buffer); } -long DragonFlyBSDProcess_compare(const void* v1, const void* v2) { - const DragonFlyBSDProcess *p1, *p2; - const Settings *settings = ((const Process*)v1)->settings; +static int DragonFlyBSDProcess_compareByKey(const Process* v1, const Process* v2, ProcessField key) { + const DragonFlyBSDProcess* p1 = (const DragonFlyBSDProcess*)v1; + const DragonFlyBSDProcess* p2 = (const DragonFlyBSDProcess*)v2; - if (settings->direction == 1) { - p1 = (const DragonFlyBSDProcess*)v1; - p2 = (const DragonFlyBSDProcess*)v2; - } else { - p2 = (const DragonFlyBSDProcess*)v1; - p1 = (const DragonFlyBSDProcess*)v2; - } - - switch ((int) settings->sortKey) { + switch (key) { // add Platform-specific fields here case JID: return SPACESHIP_NUMBER(p1->jid, p2->jid); case JAIL: return SPACESHIP_NULLSTR(p1->jname, p2->jname); default: - return Process_compare(v1, v2); + return Process_compareByKey_Base(v1, v2, key); } } @@ -140,3 +103,14 @@ bool Process_isThread(const Process* this) { return (Process_isUserlandThread(this)); } } + +const ProcessClass DragonFlyBSDProcess_class = { + .super = { + .extends = Class(Process), + .display = Process_display, + .delete = Process_delete, + .compare = Process_compare + }, + .writeField = DragonFlyBSDProcess_writeField, + .compareByKey = DragonFlyBSDProcess_compareByKey +}; diff --git a/dragonflybsd/DragonFlyBSDProcess.h b/dragonflybsd/DragonFlyBSDProcess.h index 1befd94..dc40a99 100644 --- a/dragonflybsd/DragonFlyBSDProcess.h +++ b/dragonflybsd/DragonFlyBSDProcess.h @@ -8,13 +8,6 @@ Released under the GNU GPLv2, see the COPYING file in the source distribution for its full text. */ -typedef enum DragonFlyBSDProcessFields { - // Add platform-specific fields here, with ids >= 100 - JID = 100, - JAIL = 101, - LAST_PROCESSFIELD = 102, -} DragonFlyBSDProcessField; - typedef struct DragonFlyBSDProcess_ { Process super; int kernel; @@ -29,18 +22,12 @@ typedef struct DragonFlyBSDProcess_ { extern const ProcessClass DragonFlyBSDProcess_class; -extern ProcessFieldData Process_fields[]; - -extern ProcessPidColumn Process_pidColumns[]; +extern const ProcessFieldData Process_fields[LAST_PROCESSFIELD]; Process* DragonFlyBSDProcess_new(const Settings* settings); void Process_delete(Object* cast); -void DragonFlyBSDProcess_writeField(const Process* this, RichString* str, ProcessField field); - -long DragonFlyBSDProcess_compare(const void* v1, const void* v2); - bool Process_isThread(const Process* this); #endif diff --git a/dragonflybsd/DragonFlyBSDProcessList.c b/dragonflybsd/DragonFlyBSDProcessList.c index 940ec03..edf2c86 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.c +++ b/dragonflybsd/DragonFlyBSDProcessList.c @@ -15,7 +15,6 @@ in the source distribution for its full text. #include #include #include -#include #include #include #include @@ -55,12 +54,9 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui len = 2; sysctlnametomib("hw.physmem", MIB_hw_physmem, &len); len = sizeof(pageSize); - if (sysctlbyname("vm.stats.vm.v_page_size", &pageSize, &len, NULL, 0) == -1) { - pageSize = CRT_pageSize; - pageSizeKb = CRT_pageSizeKB; - } else { - pageSizeKb = pageSize / ONE_K; - } + if (sysctlbyname("vm.stats.vm.v_page_size", &pageSize, &len, NULL, 0) == -1) + CRT_fatalError("Cannot get pagesize by sysctl"); + pageSizeKb = pageSize / ONE_K; // usable page count vm.stats.vm.v_page_count // actually usable memory : vm.stats.vm.v_page_count * vm.stats.vm.v_page_size @@ -115,7 +111,7 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui dfpl->kd = kvm_openfiles(NULL, "/dev/null", NULL, 0, errbuf); if (dfpl->kd == NULL) { - errx(1, "kvm_open: %s", errbuf); + CRT_fatalError("kvm_openfiles() failed"); } return pl; @@ -265,7 +261,7 @@ static inline void DragonFlyBSDProcessList_scanMemoryInfo(ProcessList* pl) { pl->usedSwap *= pageSizeKb; } -char* DragonFlyBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd) { +static char* DragonFlyBSDProcessList_readProcessName(kvm_t* kd, const struct kinfo_proc* kproc, int* basenameEnd) { char** argv = kvm_getargv(kd, kproc, 0); if (!argv) { return xStrdup(kproc->kp_comm); @@ -297,25 +293,20 @@ static inline void DragonFlyBSDProcessList_scanJails(DragonFlyBSDProcessList* df char* nextpos; if (sysctlbyname("jail.list", NULL, &len, NULL, 0) == -1) { - fprintf(stderr, "initial sysctlbyname / jail.list failed\n"); - exit(3); + CRT_fatalError("initial sysctlbyname / jail.list failed"); } retry: if (len == 0) return; jls = xMalloc(len); - if (jls == NULL) { - fprintf(stderr, "xMalloc failed\n"); - exit(4); - } + if (sysctlbyname("jail.list", jls, &len, NULL, 0) == -1) { if (errno == ENOMEM) { free(jls); goto retry; } - fprintf(stderr, "sysctlbyname / jail.list failed\n"); - exit(5); + CRT_fatalError("sysctlbyname / jail.list failed"); } if (dfpl->jails) { @@ -346,7 +337,7 @@ retry: free(jls); } -char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int jailid) { +static char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int jailid) { char* hostname; char* jname; @@ -376,10 +367,10 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { int count = 0; // TODO Kernel Threads seem to be skipped, need to figure out the correct flag - struct kinfo_proc* kprocs = kvm_getprocs(dfpl->kd, KERN_PROC_ALL | (!hideUserlandThreads ? KERN_PROC_FLAG_LWP : 0), 0, &count); + const struct kinfo_proc* kprocs = kvm_getprocs(dfpl->kd, KERN_PROC_ALL | (!hideUserlandThreads ? KERN_PROC_FLAG_LWP : 0), 0, &count); for (int i = 0; i < count; i++) { - struct kinfo_proc* kproc = &kprocs[i]; + const struct kinfo_proc* kproc = &kprocs[i]; bool preExisting = false; bool ATTR_UNUSED isIdleProcess = false; @@ -433,13 +424,13 @@ void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate) { } } - proc->m_virt = kproc->kp_vm_map_size / pageSize; - proc->m_resident = kproc->kp_vm_rssize; + proc->m_virt = kproc->kp_vm_map_size / ONE_K; + proc->m_resident = kproc->kp_vm_rssize * pageSizeKb; proc->nlwp = kproc->kp_nthreads; // number of lwp thread proc->time = (kproc->kp_swtime + 5000) / 10000; proc->percent_cpu = 100.0 * ((double)kproc->kp_lwp.kl_pctcpu / (double)kernelFScale); - proc->percent_mem = 100.0 * (proc->m_resident * pageSizeKb) / (double)(super->totalMem); + proc->percent_mem = 100.0 * proc->m_resident / (double)(super->totalMem); if (proc->percent_cpu > 0.1) { // system idle process should own all CPU time left regardless of CPU count diff --git a/dragonflybsd/DragonFlyBSDProcessList.h b/dragonflybsd/DragonFlyBSDProcessList.h index 682971e..80fb9f3 100644 --- a/dragonflybsd/DragonFlyBSDProcessList.h +++ b/dragonflybsd/DragonFlyBSDProcessList.h @@ -11,16 +11,12 @@ in the source distribution for its full text. #include #include #include -#include -#include #include #include #include #include "Hashtable.h" #include "DragonFlyBSDProcess.h" -#define JAIL_ERRMSGLEN 1024 -extern char jail_errmsg[JAIL_ERRMSGLEN]; typedef struct CPUData_ { double userPercent; @@ -55,10 +51,6 @@ ProcessList* ProcessList_new(UsersTable* usersTable, Hashtable* pidMatchList, ui void ProcessList_delete(ProcessList* this); -char* DragonFlyBSDProcessList_readProcessName(kvm_t* kd, struct kinfo_proc* kproc, int* basenameEnd); - -char* DragonFlyBSDProcessList_readJailName(DragonFlyBSDProcessList* dfpl, int jailid); - void ProcessList_goThroughEntries(ProcessList* super, bool pauseProcessUpdate); #endif diff --git a/dragonflybsd/Platform.c b/dragonflybsd/Platform.c index 40a7348..8ce216c 100644 --- a/dragonflybsd/Platform.c +++ b/dragonflybsd/Platform.c @@ -31,9 +31,7 @@ in the source distribution for its full text. #include -ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_VIRT, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; - -int Platform_numberOfFields = LAST_PROCESSFIELD; +const ProcessField Platform_defaultFields[] = { PID, USER, PRIORITY, NICE, M_VIRT, M_RESIDENT, STATE, PERCENT_CPU, PERCENT_MEM, TIME, COMM, 0 }; const SignalItem Platform_signals[] = { { .name = " 0 Cancel", .number = 0 }, diff --git a/dragonflybsd/Platform.h b/dragonflybsd/Platform.h index 5456539..3c5d9cb 100644 --- a/dragonflybsd/Platform.h +++ b/dragonflybsd/Platform.h @@ -17,11 +17,8 @@ in the source distribution for its full text. #include "ProcessLocksScreen.h" #include "SignalsPanel.h" -extern ProcessFieldData Process_fields[]; -extern ProcessField Platform_defaultFields[]; - -extern int Platform_numberOfFields; +extern const ProcessField Platform_defaultFields[]; extern const SignalItem Platform_signals[]; diff --git a/dragonflybsd/ProcessField.h b/dragonflybsd/ProcessField.h new file mode 100644 index 0000000..a32e3d3 --- /dev/null +++ b/dragonflybsd/ProcessField.h @@ -0,0 +1,17 @@ +#ifndef HEADER_DragonFlyBSDProcessField +#define HEADER_DragonFlyBSDProcessField +/* +htop - dragonflybsd/ProcessField.h +(C) 2020 htop dev team +Released under the GNU GPLv2, see the COPYING file +in the source distribution for its full text. +*/ + + +#define PLATFORM_PROCESS_FIELDS \ + JID = 100, \ + JAIL = 101, \ + // End of list + + +#endif /* HEADER_DragonFlyBSDProcessField */ -- cgit v1.2.3