2006-03-04 18:16:49 +00:00
|
|
|
/*
|
|
|
|
htop - Settings.c
|
2011-05-26 16:35:07 +00:00
|
|
|
(C) 2004-2011 Hisham H. Muhammad
|
2021-09-22 09:33:00 +00:00
|
|
|
Released under the GNU GPLv2+, see the COPYING file
|
2006-03-04 18:16:49 +00:00
|
|
|
in the source distribution for its full text.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "Settings.h"
|
|
|
|
|
2021-08-24 15:40:22 +00:00
|
|
|
#include <ctype.h>
|
2021-03-12 15:56:06 +00:00
|
|
|
#include <errno.h>
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
#include <limits.h>
|
2020-09-19 11:55:23 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2021-08-24 15:27:43 +00:00
|
|
|
#include <string.h>
|
2020-09-19 11:55:23 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2015-04-09 18:19:31 +00:00
|
|
|
#include "CRT.h"
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
#include "DynamicColumn.h"
|
2020-09-19 11:55:23 +00:00
|
|
|
#include "Macros.h"
|
|
|
|
#include "Meter.h"
|
2020-10-14 18:21:09 +00:00
|
|
|
#include "Platform.h"
|
|
|
|
#include "XUtils.h"
|
2006-03-04 18:16:49 +00:00
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
#define FORCE_TEMP_METER
|
|
|
|
#define FORCE_FREQ_METER
|
2011-12-26 21:35:57 +00:00
|
|
|
|
2021-08-31 05:38:52 +00:00
|
|
|
/*
|
|
|
|
|
|
|
|
static char** readQuotedList(char* line) {
|
|
|
|
int n = 0;
|
|
|
|
char** list = xCalloc(sizeof(char*), 1);
|
|
|
|
int start = 0;
|
|
|
|
for (;;) {
|
|
|
|
while (line[start] && line[start] == ' ') {
|
|
|
|
start++;
|
|
|
|
}
|
|
|
|
if (line[start] != '"') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
start++;
|
|
|
|
int close = start;
|
|
|
|
while (line[close] && line[close] != '"') {
|
|
|
|
close++;
|
|
|
|
}
|
|
|
|
int len = close - start;
|
|
|
|
char* item = xMalloc(len + 1);
|
|
|
|
strncpy(item, line + start, len);
|
|
|
|
item[len] = '\0';
|
|
|
|
list[n] = item;
|
|
|
|
n++;
|
|
|
|
list = xRealloc(list, sizeof(char*) * (n + 1));
|
|
|
|
start = close + 1;
|
|
|
|
}
|
|
|
|
list[n] = NULL;
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void writeQuotedList(FILE* fd, char** list) {
|
|
|
|
const char* sep = "";
|
|
|
|
for (int i = 0; list[i]; i++) {
|
|
|
|
fprintf(fd, "%s\"%s\"", sep, list[i]);
|
|
|
|
sep = " ";
|
|
|
|
}
|
|
|
|
fprintf(fd, "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
void Settings_delete(Settings *this)
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
free(this->filename);
|
2022-06-07 19:16:47 +00:00
|
|
|
for (unsigned int i = 0; i < HeaderLayout_getColumns(this->hLayout); i++)
|
|
|
|
{
|
2021-10-05 22:00:13 +00:00
|
|
|
String_freeArray(this->hColumns[i].names);
|
2020-12-25 15:42:35 +00:00
|
|
|
free(this->hColumns[i].modes);
|
2015-01-22 01:27:31 +00:00
|
|
|
}
|
2020-12-25 15:42:35 +00:00
|
|
|
free(this->hColumns);
|
2022-06-07 19:16:47 +00:00
|
|
|
if (this->screens)
|
|
|
|
{
|
|
|
|
for (unsigned int i = 0; this->screens[i]; i++)
|
|
|
|
{
|
2021-12-08 13:20:54 +00:00
|
|
|
ScreenSettings_delete(this->screens[i]);
|
2021-08-31 05:38:52 +00:00
|
|
|
}
|
|
|
|
free(this->screens);
|
|
|
|
}
|
2006-03-04 18:16:49 +00:00
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
static void Settings_readMeters(Settings *this, const char *line, unsigned int column)
|
|
|
|
{
|
|
|
|
char *trim = String_trim(line);
|
|
|
|
char **ids = String_split(trim, ' ', NULL);
|
2006-03-04 18:16:49 +00:00
|
|
|
free(trim);
|
2020-12-25 15:42:35 +00:00
|
|
|
column = MINIMUM(column, HeaderLayout_getColumns(this->hLayout) - 1);
|
|
|
|
this->hColumns[column].names = ids;
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
static void Settings_readMeterModes(Settings *this, const char *line, unsigned int column)
|
|
|
|
{
|
|
|
|
char *trim = String_trim(line);
|
|
|
|
char **ids = String_split(trim, ' ', NULL);
|
2006-03-04 18:16:49 +00:00
|
|
|
free(trim);
|
2015-01-22 01:27:31 +00:00
|
|
|
int len = 0;
|
2022-06-07 19:16:47 +00:00
|
|
|
for (int i = 0; ids[i]; i++)
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
len++;
|
|
|
|
}
|
2020-12-25 15:42:35 +00:00
|
|
|
column = MINIMUM(column, HeaderLayout_getColumns(this->hLayout) - 1);
|
|
|
|
this->hColumns[column].len = len;
|
2022-06-07 19:16:47 +00:00
|
|
|
int *modes = len ? xCalloc(len, sizeof(int)) : NULL;
|
|
|
|
for (int i = 0; i < len; i++)
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
modes[i] = atoi(ids[i]);
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
String_freeArray(ids);
|
2020-12-25 15:42:35 +00:00
|
|
|
this->hColumns[column].modes = modes;
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
static bool Settings_validateMeters(Settings *this)
|
|
|
|
{
|
2021-10-05 22:00:55 +00:00
|
|
|
const size_t colCount = HeaderLayout_getColumns(this->hLayout);
|
|
|
|
|
2022-04-02 10:30:30 +00:00
|
|
|
bool anyMeter = false;
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
for (size_t column = 0; column < colCount; column++)
|
|
|
|
{
|
|
|
|
char **names = this->hColumns[column].names;
|
|
|
|
const int *modes = this->hColumns[column].modes;
|
2021-10-05 22:00:55 +00:00
|
|
|
const size_t len = this->hColumns[column].len;
|
|
|
|
|
2022-04-02 10:30:30 +00:00
|
|
|
if (!len)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!names || !modes)
|
2021-10-05 22:00:55 +00:00
|
|
|
return false;
|
|
|
|
|
2022-04-02 10:30:30 +00:00
|
|
|
anyMeter |= !!len;
|
|
|
|
|
2021-10-05 22:00:55 +00:00
|
|
|
// Check for each mode there is an entry with a non-NULL name
|
|
|
|
for (size_t meterIdx = 0; meterIdx < len; meterIdx++)
|
|
|
|
if (!names[meterIdx])
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (names[len])
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-04-02 10:30:30 +00:00
|
|
|
return anyMeter;
|
2021-10-05 22:00:55 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
static void Settings_defaultMeters(Settings *this, unsigned int initialCpuCount)
|
|
|
|
{
|
|
|
|
int sizes[] = {3, 5};
|
2021-10-05 22:00:13 +00:00
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
if (initialCpuCount > 4 && initialCpuCount <= 128)
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
sizes[1]++;
|
|
|
|
}
|
2021-10-05 22:00:13 +00:00
|
|
|
|
|
|
|
// Release any previously allocated memory
|
2022-06-07 19:16:47 +00:00
|
|
|
for (size_t i = 0; i < HeaderLayout_getColumns(this->hLayout); i++)
|
|
|
|
{
|
2021-10-05 22:00:13 +00:00
|
|
|
String_freeArray(this->hColumns[i].names);
|
|
|
|
free(this->hColumns[i].modes);
|
|
|
|
}
|
|
|
|
free(this->hColumns);
|
|
|
|
|
|
|
|
this->hLayout = HF_TWO_50_50;
|
|
|
|
this->hColumns = xCalloc(HeaderLayout_getColumns(this->hLayout), sizeof(MeterColumnSetting));
|
2022-06-07 19:16:47 +00:00
|
|
|
for (size_t i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
this->hColumns[i].names = xCalloc(sizes[i] + 1, sizeof(char *));
|
2020-12-25 15:42:35 +00:00
|
|
|
this->hColumns[i].modes = xCalloc(sizes[i], sizeof(int));
|
|
|
|
this->hColumns[i].len = sizes[i];
|
2015-01-22 01:27:31 +00:00
|
|
|
}
|
2021-10-05 22:00:13 +00:00
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
int r = 0;
|
2021-02-02 09:32:11 +00:00
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
if (initialCpuCount > 128)
|
|
|
|
{
|
2021-02-02 09:32:11 +00:00
|
|
|
// Just show the average, ricers need to config for impressive screenshots
|
2020-12-25 15:42:35 +00:00
|
|
|
this->hColumns[0].names[0] = xStrdup("CPU");
|
|
|
|
this->hColumns[0].modes[0] = BAR_METERMODE;
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (initialCpuCount > 32)
|
|
|
|
{
|
2020-12-25 15:42:35 +00:00
|
|
|
this->hColumns[0].names[0] = xStrdup("LeftCPUs8");
|
|
|
|
this->hColumns[0].modes[0] = BAR_METERMODE;
|
|
|
|
this->hColumns[1].names[r] = xStrdup("RightCPUs8");
|
|
|
|
this->hColumns[1].modes[r++] = BAR_METERMODE;
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (initialCpuCount > 16)
|
|
|
|
{
|
2020-12-25 15:42:35 +00:00
|
|
|
this->hColumns[0].names[0] = xStrdup("LeftCPUs4");
|
|
|
|
this->hColumns[0].modes[0] = BAR_METERMODE;
|
|
|
|
this->hColumns[1].names[r] = xStrdup("RightCPUs4");
|
|
|
|
this->hColumns[1].modes[r++] = BAR_METERMODE;
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (initialCpuCount > 8)
|
|
|
|
{
|
2020-12-25 15:42:35 +00:00
|
|
|
this->hColumns[0].names[0] = xStrdup("LeftCPUs2");
|
|
|
|
this->hColumns[0].modes[0] = BAR_METERMODE;
|
|
|
|
this->hColumns[1].names[r] = xStrdup("RightCPUs2");
|
|
|
|
this->hColumns[1].modes[r++] = BAR_METERMODE;
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (initialCpuCount > 4)
|
|
|
|
{
|
2020-12-25 15:42:35 +00:00
|
|
|
this->hColumns[0].names[0] = xStrdup("LeftCPUs");
|
|
|
|
this->hColumns[0].modes[0] = BAR_METERMODE;
|
|
|
|
this->hColumns[1].names[r] = xStrdup("RightCPUs");
|
|
|
|
this->hColumns[1].modes[r++] = BAR_METERMODE;
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-25 15:42:35 +00:00
|
|
|
this->hColumns[0].names[0] = xStrdup("AllCPUs");
|
|
|
|
this->hColumns[0].modes[0] = BAR_METERMODE;
|
2015-01-22 01:27:31 +00:00
|
|
|
}
|
2020-12-25 15:42:35 +00:00
|
|
|
this->hColumns[0].names[1] = xStrdup("Memory");
|
|
|
|
this->hColumns[0].modes[1] = BAR_METERMODE;
|
|
|
|
this->hColumns[0].names[2] = xStrdup("Swap");
|
|
|
|
this->hColumns[0].modes[2] = BAR_METERMODE;
|
|
|
|
this->hColumns[1].names[r] = xStrdup("Tasks");
|
|
|
|
this->hColumns[1].modes[r++] = TEXT_METERMODE;
|
|
|
|
this->hColumns[1].names[r] = xStrdup("LoadAverage");
|
|
|
|
this->hColumns[1].modes[r++] = TEXT_METERMODE;
|
|
|
|
this->hColumns[1].names[r] = xStrdup("Uptime");
|
|
|
|
this->hColumns[1].modes[r++] = TEXT_METERMODE;
|
2022-06-07 19:16:47 +00:00
|
|
|
this->hColumns[1].names[r] = xStrdup("Temp");
|
|
|
|
this->hColumns[1].modes[r++] = TEXT_METERMODE;
|
|
|
|
this->hColumns[1].names[r] = xStrdup("Freq");
|
|
|
|
this->hColumns[1].modes[r++] = TEXT_METERMODE;
|
2015-01-22 01:27:31 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
static const char *toFieldName(Hashtable *columns, int id)
|
|
|
|
{
|
2021-08-31 05:38:52 +00:00
|
|
|
if (id < 0)
|
|
|
|
return NULL;
|
2022-06-07 19:16:47 +00:00
|
|
|
if (id >= LAST_PROCESSFIELD)
|
|
|
|
{
|
|
|
|
const DynamicColumn *column = DynamicColumn_lookup(columns, id);
|
2021-08-31 05:38:52 +00:00
|
|
|
return column->name;
|
|
|
|
}
|
|
|
|
return Process_fields[id].name;
|
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
static int toFieldIndex(Hashtable *columns, const char *str)
|
|
|
|
{
|
|
|
|
if (isdigit(str[0]))
|
|
|
|
{
|
2021-08-31 05:38:52 +00:00
|
|
|
// This "+1" is for compatibility with the older enum format.
|
|
|
|
int id = atoi(str) + 1;
|
2022-06-07 19:16:47 +00:00
|
|
|
if (toFieldName(columns, id))
|
|
|
|
{
|
2021-08-31 05:38:52 +00:00
|
|
|
return id;
|
|
|
|
}
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-31 05:38:52 +00:00
|
|
|
// Dynamically-defined columns are always stored by-name.
|
|
|
|
char dynamic[32] = {0};
|
2022-06-07 19:16:47 +00:00
|
|
|
if (sscanf(str, "Dynamic(%30s)", dynamic))
|
|
|
|
{
|
|
|
|
char *end;
|
|
|
|
if ((end = strrchr(dynamic, ')')) != NULL)
|
|
|
|
{
|
2021-10-26 11:07:24 +00:00
|
|
|
bool success;
|
2021-08-31 05:38:52 +00:00
|
|
|
unsigned int key;
|
|
|
|
*end = '\0';
|
|
|
|
success = DynamicColumn_search(columns, dynamic, &key) != NULL;
|
|
|
|
*end = ')';
|
2021-10-26 11:07:24 +00:00
|
|
|
if (success)
|
2021-08-31 05:38:52 +00:00
|
|
|
return key;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Fallback to iterative scan of table of fields by-name.
|
2022-06-07 19:16:47 +00:00
|
|
|
for (int p = 1; p < LAST_PROCESSFIELD; p++)
|
|
|
|
{
|
|
|
|
const char *pName = toFieldName(columns, p);
|
2021-08-31 05:38:52 +00:00
|
|
|
if (pName && strcmp(pName, str) == 0)
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
static void ScreenSettings_readFields(ScreenSettings *ss, Hashtable *columns, const char *line)
|
|
|
|
{
|
|
|
|
char *trim = String_trim(line);
|
|
|
|
char **ids = String_split(trim, ' ', NULL);
|
2015-01-22 01:27:31 +00:00
|
|
|
free(trim);
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
|
2021-12-16 14:49:17 +00:00
|
|
|
/* reset default fields */
|
|
|
|
memset(ss->fields, '\0', LAST_PROCESSFIELD * sizeof(ProcessField));
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
for (size_t j = 0, i = 0; ids[i]; i++)
|
|
|
|
{
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
if (j >= UINT_MAX / sizeof(ProcessField))
|
|
|
|
continue;
|
2022-06-07 19:16:47 +00:00
|
|
|
if (j >= LAST_PROCESSFIELD)
|
|
|
|
{
|
2021-10-26 11:07:24 +00:00
|
|
|
ss->fields = xRealloc(ss->fields, (j + 1) * sizeof(ProcessField));
|
2021-08-31 05:38:52 +00:00
|
|
|
memset(&ss->fields[j], 0, sizeof(ProcessField));
|
2015-01-22 01:27:31 +00:00
|
|
|
}
|
2021-08-31 05:38:52 +00:00
|
|
|
int id = toFieldIndex(columns, ids[i]);
|
|
|
|
if (id >= 0)
|
|
|
|
ss->fields[j] = id;
|
|
|
|
if (id > 0 && id < LAST_PROCESSFIELD)
|
|
|
|
ss->flags |= Process_fields[id].flags;
|
|
|
|
j++;
|
2014-11-27 20:38:52 +00:00
|
|
|
}
|
2015-01-22 01:27:31 +00:00
|
|
|
String_freeArray(ids);
|
2014-11-27 20:38:52 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
ScreenSettings *Settings_newScreen(Settings *this, const ScreenDefaults *defaults)
|
|
|
|
{
|
2021-12-16 15:09:32 +00:00
|
|
|
int sortKey = defaults->sortKey ? toFieldIndex(this->dynamicColumns, defaults->sortKey) : PID;
|
2022-05-01 06:21:13 +00:00
|
|
|
int sortDesc = (sortKey >= 0 && sortKey < LAST_PROCESSFIELD) ? Process_fields[sortKey].defaultSortDesc : 1;
|
2022-04-30 03:50:25 +00:00
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
ScreenSettings *ss = xMalloc(sizeof(ScreenSettings));
|
|
|
|
*ss = (ScreenSettings){
|
|
|
|
.name = xStrdup(defaults->name),
|
|
|
|
.fields = xCalloc(LAST_PROCESSFIELD, sizeof(ProcessField)),
|
|
|
|
.flags = 0,
|
|
|
|
.direction = sortDesc ? -1 : 1,
|
|
|
|
.treeDirection = 1,
|
|
|
|
.sortKey = sortKey,
|
|
|
|
.treeSortKey = PID,
|
|
|
|
.treeView = false,
|
|
|
|
.treeViewAlwaysByPID = false,
|
|
|
|
.allBranchesCollapsed = false,
|
2021-12-08 12:02:58 +00:00
|
|
|
};
|
|
|
|
|
2021-12-16 15:09:32 +00:00
|
|
|
ScreenSettings_readFields(ss, this->dynamicColumns, defaults->columns);
|
2021-08-31 05:38:52 +00:00
|
|
|
this->screens[this->nScreens] = ss;
|
|
|
|
this->nScreens++;
|
2022-06-07 19:16:47 +00:00
|
|
|
this->screens = xRealloc(this->screens, sizeof(ScreenSettings *) * (this->nScreens + 1));
|
2021-08-31 05:38:52 +00:00
|
|
|
this->screens[this->nScreens] = NULL;
|
|
|
|
return ss;
|
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
void ScreenSettings_delete(ScreenSettings *this)
|
|
|
|
{
|
2021-12-08 13:20:54 +00:00
|
|
|
free(this->name);
|
|
|
|
free(this->fields);
|
|
|
|
free(this);
|
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
static ScreenSettings *Settings_defaultScreens(Settings *this)
|
|
|
|
{
|
2021-09-24 07:52:20 +00:00
|
|
|
if (this->nScreens)
|
|
|
|
return this->screens[0];
|
2022-06-07 19:16:47 +00:00
|
|
|
for (unsigned int i = 0; i < Platform_numberOfDefaultScreens; i++)
|
|
|
|
{
|
|
|
|
const ScreenDefaults *defaults = &Platform_defaultScreens[i];
|
2021-12-16 15:09:32 +00:00
|
|
|
Settings_newScreen(this, defaults);
|
2021-08-31 05:38:52 +00:00
|
|
|
}
|
2021-09-24 07:52:20 +00:00
|
|
|
return this->screens[0];
|
2021-08-31 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
static bool Settings_read(Settings *this, const char *fileName, unsigned int initialCpuCount)
|
|
|
|
{
|
|
|
|
FILE *fd = fopen(fileName, "r");
|
2011-12-25 20:22:41 +00:00
|
|
|
if (!fd)
|
2006-03-04 18:16:49 +00:00
|
|
|
return false;
|
2020-11-01 00:09:51 +00:00
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
ScreenSettings *screen = NULL;
|
2018-02-18 23:35:23 +00:00
|
|
|
bool didReadMeters = false;
|
2021-08-02 15:33:34 +00:00
|
|
|
bool didReadAny = false;
|
2022-06-07 19:16:47 +00:00
|
|
|
for (;;)
|
|
|
|
{
|
|
|
|
char *line = String_readLine(fd);
|
|
|
|
if (!line)
|
|
|
|
{
|
2016-06-19 21:55:35 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-08-02 15:33:34 +00:00
|
|
|
didReadAny = true;
|
2020-10-03 19:20:43 +00:00
|
|
|
size_t nOptions;
|
2022-06-07 19:16:47 +00:00
|
|
|
char **option = String_split(line, '=', &nOptions);
|
|
|
|
free(line);
|
|
|
|
if (nOptions < 2)
|
|
|
|
{
|
2011-08-29 20:45:29 +00:00
|
|
|
String_freeArray(option);
|
|
|
|
continue;
|
|
|
|
}
|
2022-06-07 19:16:47 +00:00
|
|
|
if (String_eq(option[0], "config_reader_min_version"))
|
|
|
|
{
|
2021-07-16 15:04:23 +00:00
|
|
|
this->config_version = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
if (this->config_version > CONFIG_READER_MIN_VERSION)
|
|
|
|
{
|
2021-08-23 06:58:14 +00:00
|
|
|
// the version of the config file on disk is newer than what we can read
|
2021-09-27 05:13:01 +00:00
|
|
|
fprintf(stderr, "WARNING: %s specifies configuration format\n", fileName);
|
|
|
|
fprintf(stderr, " version v%d, but this %s binary only supports up to version v%d.\n", this->config_version, PACKAGE, CONFIG_READER_MIN_VERSION);
|
|
|
|
fprintf(stderr, " The configuration file will be downgraded to v%d when %s exits.\n", CONFIG_READER_MIN_VERSION, PACKAGE);
|
2021-08-31 05:55:27 +00:00
|
|
|
String_freeArray(option);
|
|
|
|
fclose(fd);
|
2021-08-23 06:58:14 +00:00
|
|
|
return false;
|
2021-07-16 15:04:23 +00:00
|
|
|
}
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "fields") && this->config_version <= 2)
|
|
|
|
{
|
2021-08-31 05:38:52 +00:00
|
|
|
// old (no screen) naming also supported for backwards compatibility
|
2021-09-24 07:52:20 +00:00
|
|
|
screen = Settings_defaultScreens(this);
|
|
|
|
ScreenSettings_readFields(screen, this->dynamicColumns, option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "sort_key") && this->config_version <= 2)
|
|
|
|
{
|
2021-08-31 05:38:52 +00:00
|
|
|
// old (no screen) naming also supported for backwards compatibility
|
2006-03-04 18:16:49 +00:00
|
|
|
// This "+1" is for compatibility with the older enum format.
|
2021-09-24 07:52:20 +00:00
|
|
|
screen = Settings_defaultScreens(this);
|
|
|
|
screen->sortKey = atoi(option[1]) + 1;
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "tree_sort_key") && this->config_version <= 2)
|
|
|
|
{
|
2021-08-31 05:38:52 +00:00
|
|
|
// old (no screen) naming also supported for backwards compatibility
|
2020-12-18 14:03:31 +00:00
|
|
|
// This "+1" is for compatibility with the older enum format.
|
2021-09-24 07:52:20 +00:00
|
|
|
screen = Settings_defaultScreens(this);
|
|
|
|
screen->treeSortKey = atoi(option[1]) + 1;
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "sort_direction") && this->config_version <= 2)
|
|
|
|
{
|
2021-08-31 05:38:52 +00:00
|
|
|
// old (no screen) naming also supported for backwards compatibility
|
2021-09-24 07:52:20 +00:00
|
|
|
screen = Settings_defaultScreens(this);
|
|
|
|
screen->direction = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "tree_sort_direction") && this->config_version <= 2)
|
|
|
|
{
|
2021-08-31 05:38:52 +00:00
|
|
|
// old (no screen) naming also supported for backwards compatibility
|
2021-09-24 07:52:20 +00:00
|
|
|
screen = Settings_defaultScreens(this);
|
|
|
|
screen->treeDirection = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "tree_view") && this->config_version <= 2)
|
|
|
|
{
|
2021-08-31 05:38:52 +00:00
|
|
|
// old (no screen) naming also supported for backwards compatibility
|
2021-09-24 07:52:20 +00:00
|
|
|
screen = Settings_defaultScreens(this);
|
|
|
|
screen->treeView = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "tree_view_always_by_pid") && this->config_version <= 2)
|
|
|
|
{
|
2021-08-31 05:38:52 +00:00
|
|
|
// old (no screen) naming also supported for backwards compatibility
|
2021-09-24 07:52:20 +00:00
|
|
|
screen = Settings_defaultScreens(this);
|
|
|
|
screen->treeViewAlwaysByPID = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "all_branches_collapsed") && this->config_version <= 2)
|
|
|
|
{
|
2021-08-31 05:38:52 +00:00
|
|
|
// old (no screen) naming also supported for backwards compatibility
|
2021-09-24 07:52:20 +00:00
|
|
|
screen = Settings_defaultScreens(this);
|
|
|
|
screen->allBranchesCollapsed = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "hide_kernel_threads"))
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
this->hideKernelThreads = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "hide_userland_threads"))
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
this->hideUserlandThreads = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "shadow_other_users"))
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
this->shadowOtherUsers = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "show_thread_names"))
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
this->showThreadNames = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "show_program_path"))
|
|
|
|
{
|
2015-07-29 19:14:29 +00:00
|
|
|
this->showProgramPath = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "highlight_base_name"))
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
this->highlightBaseName = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "highlight_deleted_exe"))
|
|
|
|
{
|
2020-12-19 15:46:00 +00:00
|
|
|
this->highlightDeletedExe = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "highlight_megabytes"))
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
this->highlightMegabytes = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "highlight_threads"))
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
this->highlightThreads = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "highlight_changes"))
|
|
|
|
{
|
2020-10-31 01:56:16 +00:00
|
|
|
this->highlightChanges = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "highlight_changes_delay_secs"))
|
|
|
|
{
|
2021-07-14 17:18:27 +00:00
|
|
|
this->highlightDelaySecs = CLAMP(atoi(option[1]), 1, 24 * 60 * 60);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "find_comm_in_cmdline"))
|
|
|
|
{
|
2020-10-17 10:54:45 +00:00
|
|
|
this->findCommInCmdline = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "strip_exe_from_cmdline"))
|
|
|
|
{
|
2020-10-17 10:54:45 +00:00
|
|
|
this->stripExeFromCmdline = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "show_merged_command"))
|
|
|
|
{
|
2020-10-17 10:54:45 +00:00
|
|
|
this->showMergedCommand = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "header_margin"))
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
this->headerMargin = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "screen_tabs"))
|
|
|
|
{
|
2021-08-31 05:38:52 +00:00
|
|
|
this->screenTabs = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "expand_system_time"))
|
|
|
|
{
|
2007-11-09 00:40:59 +00:00
|
|
|
// Compatibility option.
|
2015-01-22 01:27:31 +00:00
|
|
|
this->detailedCPUTime = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "detailed_cpu_time"))
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
this->detailedCPUTime = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "cpu_count_from_one"))
|
|
|
|
{
|
2019-12-19 22:30:45 +00:00
|
|
|
this->countCPUsFromOne = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "cpu_count_from_zero"))
|
|
|
|
{
|
2019-12-19 22:30:45 +00:00
|
|
|
// old (inverted) naming also supported for backwards compatibility
|
|
|
|
this->countCPUsFromOne = !atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "show_cpu_usage"))
|
|
|
|
{
|
2019-08-10 18:20:21 +00:00
|
|
|
this->showCPUUsage = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "show_cpu_frequency"))
|
|
|
|
{
|
2019-08-10 04:34:48 +00:00
|
|
|
this->showCPUFrequency = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
#ifdef BUILD_WITH_CPU_TEMP
|
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "show_cpu_temperature"))
|
|
|
|
{
|
2020-09-10 17:56:33 +00:00
|
|
|
this->showCPUTemperature = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "degree_fahrenheit"))
|
|
|
|
{
|
2020-09-10 17:56:33 +00:00
|
|
|
this->degreeFahrenheit = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "update_process_names"))
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
this->updateProcessNames = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "account_guest_in_cpu_meter"))
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
this->accountGuestInCPUMeter = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "delay"))
|
|
|
|
{
|
2020-11-21 20:40:08 +00:00
|
|
|
this->delay = CLAMP(atoi(option[1]), 1, 255);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "color_scheme"))
|
|
|
|
{
|
2006-03-04 18:16:49 +00:00
|
|
|
this->colorScheme = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
if (this->colorScheme < 0 || this->colorScheme >= LAST_COLORSCHEME)
|
|
|
|
{
|
2020-10-31 21:14:27 +00:00
|
|
|
this->colorScheme = 0;
|
2020-11-01 00:09:51 +00:00
|
|
|
}
|
2022-06-07 19:16:47 +00:00
|
|
|
#ifdef HAVE_GETMOUSE
|
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "enable_mouse"))
|
|
|
|
{
|
2019-07-12 19:41:09 +00:00
|
|
|
this->enableMouse = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "header_layout"))
|
|
|
|
{
|
|
|
|
this->hLayout = isdigit((unsigned char)option[1][0]) ? ((HeaderLayout)atoi(option[1])) : HeaderLayout_fromName(option[1]);
|
2020-12-25 15:42:35 +00:00
|
|
|
if (this->hLayout < 0 || this->hLayout >= LAST_HEADER_LAYOUT)
|
|
|
|
this->hLayout = HF_TWO_50_50;
|
|
|
|
free(this->hColumns);
|
|
|
|
this->hColumns = xCalloc(HeaderLayout_getColumns(this->hLayout), sizeof(MeterColumnSetting));
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "left_meters"))
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
Settings_readMeters(this, option[1], 0);
|
2018-02-18 23:35:23 +00:00
|
|
|
didReadMeters = true;
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "right_meters"))
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
Settings_readMeters(this, option[1], 1);
|
2018-02-18 23:35:23 +00:00
|
|
|
didReadMeters = true;
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "left_meter_modes"))
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
Settings_readMeterModes(this, option[1], 0);
|
2018-02-18 23:35:23 +00:00
|
|
|
didReadMeters = true;
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "right_meter_modes"))
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
Settings_readMeterModes(this, option[1], 1);
|
2018-02-18 23:35:23 +00:00
|
|
|
didReadMeters = true;
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_startsWith(option[0], "column_meters_"))
|
|
|
|
{
|
2020-12-25 15:42:35 +00:00
|
|
|
Settings_readMeters(this, option[1], atoi(option[0] + strlen("column_meters_")));
|
|
|
|
didReadMeters = true;
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_startsWith(option[0], "column_meter_modes_"))
|
|
|
|
{
|
2020-12-25 15:42:35 +00:00
|
|
|
Settings_readMeterModes(this, option[1], atoi(option[0] + strlen("column_meter_modes_")));
|
|
|
|
didReadMeters = true;
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "hide_function_bar"))
|
|
|
|
{
|
2020-12-28 22:26:14 +00:00
|
|
|
this->hideFunctionBar = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
#ifdef HAVE_LIBHWLOC
|
|
|
|
}
|
|
|
|
else if (String_eq(option[0], "topology_affinity"))
|
|
|
|
{
|
2020-08-26 00:15:00 +00:00
|
|
|
this->topologyAffinity = !!atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else if (strncmp(option[0], "screen:", 7) == 0)
|
|
|
|
{
|
|
|
|
screen = Settings_newScreen(this, &(const ScreenDefaults){.name = option[0] + 7, .columns = option[1]});
|
|
|
|
}
|
|
|
|
else if (String_eq(option[0], ".sort_key"))
|
|
|
|
{
|
2021-09-24 07:52:20 +00:00
|
|
|
if (screen)
|
|
|
|
screen->sortKey = toFieldIndex(this->dynamicColumns, option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], ".tree_sort_key"))
|
|
|
|
{
|
2021-09-24 07:52:20 +00:00
|
|
|
if (screen)
|
|
|
|
screen->treeSortKey = toFieldIndex(this->dynamicColumns, option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], ".sort_direction"))
|
|
|
|
{
|
2021-09-24 07:52:20 +00:00
|
|
|
if (screen)
|
|
|
|
screen->direction = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], ".tree_sort_direction"))
|
|
|
|
{
|
2021-09-24 07:52:20 +00:00
|
|
|
if (screen)
|
|
|
|
screen->treeDirection = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], ".tree_view"))
|
|
|
|
{
|
2021-09-24 07:52:20 +00:00
|
|
|
if (screen)
|
|
|
|
screen->treeView = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], ".tree_view_always_by_pid"))
|
|
|
|
{
|
2021-09-24 07:52:20 +00:00
|
|
|
if (screen)
|
|
|
|
screen->treeViewAlwaysByPID = atoi(option[1]);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (String_eq(option[0], ".all_branches_collapsed"))
|
|
|
|
{
|
2021-09-24 07:52:20 +00:00
|
|
|
if (screen)
|
|
|
|
screen->allBranchesCollapsed = atoi(option[1]);
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
String_freeArray(option);
|
|
|
|
}
|
|
|
|
fclose(fd);
|
2022-06-07 19:16:47 +00:00
|
|
|
|
2022-06-10 17:12:16 +00:00
|
|
|
if (!didReadMeters || !Settings_validateMeters(this))
|
|
|
|
Settings_defaultMeters(this, initialCpuCount);
|
|
|
|
if (!this->nScreens)
|
|
|
|
Settings_defaultScreens(this);
|
2022-06-07 19:16:47 +00:00
|
|
|
|
2022-06-10 17:12:16 +00:00
|
|
|
return didReadAny;
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
static void writeFields(FILE *fd, const ProcessField *fields, Hashtable *columns, bool byName, char separator)
|
|
|
|
{
|
|
|
|
const char *sep = "";
|
|
|
|
for (unsigned int i = 0; fields[i]; i++)
|
|
|
|
{
|
|
|
|
if (fields[i] < LAST_PROCESSFIELD && byName)
|
|
|
|
{
|
|
|
|
const char *pName = toFieldName(columns, fields[i]);
|
2021-09-24 07:52:20 +00:00
|
|
|
fprintf(fd, "%s%s", sep, pName);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (fields[i] >= LAST_PROCESSFIELD && byName)
|
|
|
|
{
|
|
|
|
const char *pName = toFieldName(columns, fields[i]);
|
2021-10-18 06:55:54 +00:00
|
|
|
fprintf(fd, " Dynamic(%s)", pName);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
// This "-1" is for compatibility with the older enum format.
|
2022-06-07 19:16:47 +00:00
|
|
|
fprintf(fd, "%s%d", sep, (int)fields[i] - 1);
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
}
|
2017-07-24 23:36:27 +00:00
|
|
|
sep = " ";
|
2015-01-22 01:27:31 +00:00
|
|
|
}
|
2021-08-08 17:47:17 +00:00
|
|
|
fputc(separator, fd);
|
2015-01-22 01:27:31 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
static void writeList(FILE *fd, char **list, int len, char separator)
|
|
|
|
{
|
|
|
|
const char *sep = "";
|
|
|
|
for (int i = 0; i < len; i++)
|
|
|
|
{
|
2021-08-31 05:38:52 +00:00
|
|
|
fprintf(fd, "%s%s", sep, list[i]);
|
2017-07-24 23:36:27 +00:00
|
|
|
sep = " ";
|
2015-01-22 01:27:31 +00:00
|
|
|
}
|
2021-08-08 17:47:17 +00:00
|
|
|
fputc(separator, fd);
|
2015-01-22 01:27:31 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
static void writeMeters(const Settings *this, FILE *fd, char separator, unsigned int column)
|
|
|
|
{
|
2021-08-31 05:38:52 +00:00
|
|
|
writeList(fd, this->hColumns[column].names, this->hColumns[column].len, separator);
|
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
static void writeMeterModes(const Settings *this, FILE *fd, char separator, unsigned int column)
|
|
|
|
{
|
|
|
|
const char *sep = "";
|
|
|
|
for (size_t i = 0; i < this->hColumns[column].len; i++)
|
|
|
|
{
|
2020-12-25 15:42:35 +00:00
|
|
|
fprintf(fd, "%s%d", sep, this->hColumns[column].modes[i]);
|
2017-07-24 23:36:27 +00:00
|
|
|
sep = " ";
|
2015-01-22 01:27:31 +00:00
|
|
|
}
|
2021-08-08 17:47:17 +00:00
|
|
|
fputc(separator, fd);
|
2015-01-22 01:27:31 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
int Settings_write(const Settings *this, bool onCrash)
|
|
|
|
{
|
|
|
|
FILE *fd;
|
2021-08-08 17:47:17 +00:00
|
|
|
char separator;
|
2022-06-07 19:16:47 +00:00
|
|
|
if (onCrash)
|
|
|
|
{
|
2021-05-16 17:55:31 +00:00
|
|
|
fd = stderr;
|
2021-08-08 17:47:17 +00:00
|
|
|
separator = ';';
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-05-16 17:55:31 +00:00
|
|
|
fd = fopen(this->filename, "w");
|
|
|
|
if (fd == NULL)
|
|
|
|
return -errno;
|
2021-08-08 17:47:17 +00:00
|
|
|
separator = '\n';
|
2021-05-16 17:55:31 +00:00
|
|
|
}
|
2021-02-16 18:44:59 +00:00
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
#define printSettingInteger(setting_, value_) \
|
|
|
|
fprintf(fd, setting_ "=%d%c", (int)(value_), separator)
|
|
|
|
#define printSettingString(setting_, value_) \
|
|
|
|
fprintf(fd, setting_ "=%s%c", value_, separator)
|
2021-08-08 17:47:17 +00:00
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
if (!onCrash)
|
|
|
|
{
|
2021-05-16 17:55:31 +00:00
|
|
|
fprintf(fd, "# Beware! This file is rewritten by htop when settings are changed in the interface.\n");
|
|
|
|
fprintf(fd, "# The parser is also very primitive, and not human-friendly.\n");
|
|
|
|
}
|
2021-08-08 17:47:17 +00:00
|
|
|
printSettingString("htop_version", VERSION);
|
|
|
|
printSettingInteger("config_reader_min_version", CONFIG_READER_MIN_VERSION);
|
2022-06-07 19:16:47 +00:00
|
|
|
fprintf(fd, "fields=");
|
|
|
|
writeFields(fd, this->screens[0]->fields, this->dynamicColumns, false, separator);
|
2021-08-08 17:47:17 +00:00
|
|
|
printSettingInteger("hide_kernel_threads", this->hideKernelThreads);
|
|
|
|
printSettingInteger("hide_userland_threads", this->hideUserlandThreads);
|
|
|
|
printSettingInteger("shadow_other_users", this->shadowOtherUsers);
|
|
|
|
printSettingInteger("show_thread_names", this->showThreadNames);
|
|
|
|
printSettingInteger("show_program_path", this->showProgramPath);
|
|
|
|
printSettingInteger("highlight_base_name", this->highlightBaseName);
|
|
|
|
printSettingInteger("highlight_deleted_exe", this->highlightDeletedExe);
|
|
|
|
printSettingInteger("highlight_megabytes", this->highlightMegabytes);
|
|
|
|
printSettingInteger("highlight_threads", this->highlightThreads);
|
|
|
|
printSettingInteger("highlight_changes", this->highlightChanges);
|
|
|
|
printSettingInteger("highlight_changes_delay_secs", this->highlightDelaySecs);
|
|
|
|
printSettingInteger("find_comm_in_cmdline", this->findCommInCmdline);
|
|
|
|
printSettingInteger("strip_exe_from_cmdline", this->stripExeFromCmdline);
|
|
|
|
printSettingInteger("show_merged_command", this->showMergedCommand);
|
|
|
|
printSettingInteger("header_margin", this->headerMargin);
|
2021-08-31 05:38:52 +00:00
|
|
|
printSettingInteger("screen_tabs", this->screenTabs);
|
2021-08-08 17:47:17 +00:00
|
|
|
printSettingInteger("detailed_cpu_time", this->detailedCPUTime);
|
|
|
|
printSettingInteger("cpu_count_from_one", this->countCPUsFromOne);
|
|
|
|
printSettingInteger("show_cpu_usage", this->showCPUUsage);
|
|
|
|
printSettingInteger("show_cpu_frequency", this->showCPUFrequency);
|
2022-06-07 19:16:47 +00:00
|
|
|
#ifdef BUILD_WITH_CPU_TEMP
|
2021-08-08 17:47:17 +00:00
|
|
|
printSettingInteger("show_cpu_temperature", this->showCPUTemperature);
|
|
|
|
printSettingInteger("degree_fahrenheit", this->degreeFahrenheit);
|
2022-06-07 19:16:47 +00:00
|
|
|
#endif
|
2021-08-08 17:47:17 +00:00
|
|
|
printSettingInteger("update_process_names", this->updateProcessNames);
|
|
|
|
printSettingInteger("account_guest_in_cpu_meter", this->accountGuestInCPUMeter);
|
|
|
|
printSettingInteger("color_scheme", this->colorScheme);
|
2022-06-07 19:16:47 +00:00
|
|
|
#ifdef HAVE_GETMOUSE
|
2021-08-08 17:47:17 +00:00
|
|
|
printSettingInteger("enable_mouse", this->enableMouse);
|
2022-06-07 19:16:47 +00:00
|
|
|
#endif
|
|
|
|
printSettingInteger("delay", (int)this->delay);
|
|
|
|
printSettingInteger("hide_function_bar", (int)this->hideFunctionBar);
|
|
|
|
#ifdef HAVE_LIBHWLOC
|
2021-08-08 17:47:17 +00:00
|
|
|
printSettingInteger("topology_affinity", this->topologyAffinity);
|
2022-06-07 19:16:47 +00:00
|
|
|
#endif
|
2021-08-08 17:47:17 +00:00
|
|
|
|
|
|
|
printSettingString("header_layout", HeaderLayout_getName(this->hLayout));
|
2022-06-07 19:16:47 +00:00
|
|
|
for (unsigned int i = 0; i < HeaderLayout_getColumns(this->hLayout); i++)
|
|
|
|
{
|
2020-12-25 15:42:35 +00:00
|
|
|
fprintf(fd, "column_meters_%u=", i);
|
2021-08-08 17:47:17 +00:00
|
|
|
writeMeters(this, fd, separator, i);
|
2020-12-25 15:42:35 +00:00
|
|
|
fprintf(fd, "column_meter_modes_%u=", i);
|
2021-08-08 17:47:17 +00:00
|
|
|
writeMeterModes(this, fd, separator, i);
|
2020-12-25 15:42:35 +00:00
|
|
|
}
|
2021-08-08 17:47:17 +00:00
|
|
|
|
2021-08-31 05:38:52 +00:00
|
|
|
// Legacy compatibility with older versions of htop
|
|
|
|
printSettingInteger("tree_view", this->screens[0]->treeView);
|
|
|
|
// This "-1" is for compatibility with the older enum format.
|
|
|
|
printSettingInteger("sort_key", this->screens[0]->sortKey - 1);
|
|
|
|
printSettingInteger("tree_sort_key", this->screens[0]->treeSortKey - 1);
|
|
|
|
printSettingInteger("sort_direction", this->screens[0]->direction);
|
|
|
|
printSettingInteger("tree_sort_direction", this->screens[0]->treeDirection);
|
|
|
|
printSettingInteger("tree_view_always_by_pid", this->screens[0]->treeViewAlwaysByPID);
|
|
|
|
printSettingInteger("all_branches_collapsed", this->screens[0]->allBranchesCollapsed);
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
for (unsigned int i = 0; i < this->nScreens; i++)
|
|
|
|
{
|
|
|
|
ScreenSettings *ss = this->screens[i];
|
2022-04-30 03:55:56 +00:00
|
|
|
fprintf(fd, "screen:%s=", ss->name);
|
|
|
|
writeFields(fd, ss->fields, this->dynamicColumns, true, separator);
|
|
|
|
printSettingString(".sort_key", toFieldName(this->dynamicColumns, ss->sortKey));
|
|
|
|
printSettingString(".tree_sort_key", toFieldName(this->dynamicColumns, ss->treeSortKey));
|
|
|
|
printSettingInteger(".tree_view", ss->treeView);
|
|
|
|
printSettingInteger(".tree_view_always_by_pid", ss->treeViewAlwaysByPID);
|
|
|
|
printSettingInteger(".sort_direction", ss->direction);
|
|
|
|
printSettingInteger(".tree_sort_direction", ss->treeDirection);
|
|
|
|
printSettingInteger(".all_branches_collapsed", ss->allBranchesCollapsed);
|
2021-08-31 05:38:52 +00:00
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
#undef printSettingString
|
|
|
|
#undef printSettingInteger
|
2021-03-12 15:56:06 +00:00
|
|
|
|
2021-05-16 17:55:31 +00:00
|
|
|
if (onCrash)
|
|
|
|
return 0;
|
|
|
|
|
2021-03-13 17:15:20 +00:00
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
if (ferror(fd) != 0)
|
|
|
|
r = (errno != 0) ? -errno : -EBADF;
|
|
|
|
|
|
|
|
if (fclose(fd) != 0)
|
|
|
|
r = r ? r : -errno;
|
|
|
|
|
|
|
|
return r;
|
2006-03-04 18:16:49 +00:00
|
|
|
}
|
2008-03-09 08:58:38 +00:00
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
Settings *Settings_new(unsigned int initialCpuCount, Hashtable *dynamicColumns)
|
|
|
|
{
|
|
|
|
Settings *this = xCalloc(1, sizeof(Settings));
|
2015-01-22 01:27:31 +00:00
|
|
|
|
PCP: support for 'dynamic columns' added at runtime
Implements support for arbitrary Performance Co-Pilot
metrics with per-process instance domains to form new
htop columns. The column-to-metric mappings are setup
using configuration files which will be documented via
man pages as part of a follow-up commit.
We provide an initial set of column configurations so
as to provide new capabilities to pcp-htop: including
configs for containers, open fd counts, scheduler run
queue time, tcp/udp bytes/calls sent/recv, delay acct,
virtual machine guests, detailed virtual memory, swap.
Note there is a change to the configuration file path
resolution algorithm introduced for 'dynamic meters'.
First, look in any custom PCP_HTOP_DIR location. Then
iterate, in priority order, users home directory, then
local sysadmins files in /etc/pcp/htop, then readonly
configuration files below /usr/share/pcp/htop. This
final location becomes the preferred place for our own
shipped meter and column files.
The Settings file (htoprc) writing code is updated to
not using the numeric identifier for dynamic columns.
The same strategy used for dynamic meters is used here
where we write Dynamic(name) so the name can be setup
once more at start. Regular (static) columns writing
to htoprc - i.e. numerically indexed - is unchanged.
2021-07-11 01:11:29 +00:00
|
|
|
this->dynamicColumns = dynamicColumns;
|
2020-12-25 15:42:35 +00:00
|
|
|
this->hLayout = HF_TWO_50_50;
|
|
|
|
this->hColumns = xCalloc(HeaderLayout_getColumns(this->hLayout), sizeof(MeterColumnSetting));
|
2021-08-31 05:38:52 +00:00
|
|
|
|
2015-01-22 01:27:31 +00:00
|
|
|
this->shadowOtherUsers = false;
|
|
|
|
this->showThreadNames = false;
|
2021-08-02 15:33:34 +00:00
|
|
|
this->hideKernelThreads = true;
|
2015-01-22 01:27:31 +00:00
|
|
|
this->hideUserlandThreads = false;
|
|
|
|
this->highlightBaseName = false;
|
2020-12-19 15:46:00 +00:00
|
|
|
this->highlightDeletedExe = true;
|
2021-08-02 15:33:34 +00:00
|
|
|
this->highlightMegabytes = true;
|
2015-01-22 01:27:31 +00:00
|
|
|
this->detailedCPUTime = false;
|
2019-12-19 22:30:45 +00:00
|
|
|
this->countCPUsFromOne = false;
|
2019-08-10 18:20:21 +00:00
|
|
|
this->showCPUUsage = true;
|
2019-08-10 04:34:48 +00:00
|
|
|
this->showCPUFrequency = false;
|
2022-06-07 19:16:47 +00:00
|
|
|
#ifdef BUILD_WITH_CPU_TEMP
|
2020-09-10 17:56:33 +00:00
|
|
|
this->showCPUTemperature = false;
|
|
|
|
this->degreeFahrenheit = false;
|
2022-06-07 19:16:47 +00:00
|
|
|
#endif
|
2015-01-22 01:27:31 +00:00
|
|
|
this->updateProcessNames = false;
|
2015-08-12 20:24:41 +00:00
|
|
|
this->showProgramPath = true;
|
2016-01-31 11:07:48 +00:00
|
|
|
this->highlightThreads = true;
|
2020-11-01 00:36:53 +00:00
|
|
|
this->highlightChanges = false;
|
2020-10-31 01:56:16 +00:00
|
|
|
this->highlightDelaySecs = DEFAULT_HIGHLIGHT_SECS;
|
2020-10-17 10:54:45 +00:00
|
|
|
this->findCommInCmdline = true;
|
|
|
|
this->stripExeFromCmdline = true;
|
|
|
|
this->showMergedCommand = false;
|
2020-12-28 22:26:14 +00:00
|
|
|
this->hideFunctionBar = 0;
|
2021-08-02 15:33:34 +00:00
|
|
|
this->headerMargin = true;
|
2022-06-07 19:16:47 +00:00
|
|
|
#ifdef HAVE_LIBHWLOC
|
2020-08-26 00:15:00 +00:00
|
|
|
this->topologyAffinity = false;
|
2022-06-07 19:16:47 +00:00
|
|
|
#endif
|
2021-08-31 05:38:52 +00:00
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
this->screens = xCalloc(Platform_numberOfDefaultScreens * sizeof(ScreenSettings *), 1);
|
2021-08-31 05:38:52 +00:00
|
|
|
this->nScreens = 0;
|
2015-01-22 01:27:31 +00:00
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
char *legacyDotfile = NULL;
|
|
|
|
const char *rcfile = getenv("HTOPRC");
|
|
|
|
if (rcfile)
|
|
|
|
{
|
2016-02-02 14:53:02 +00:00
|
|
|
this->filename = xStrdup(rcfile);
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *home = getenv("HOME");
|
2020-11-01 00:09:51 +00:00
|
|
|
if (!home)
|
|
|
|
home = "";
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
const char *xdgConfigHome = getenv("XDG_CONFIG_HOME");
|
|
|
|
char *configDir = NULL;
|
|
|
|
char *htopDir = NULL;
|
|
|
|
if (xdgConfigHome)
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
this->filename = String_cat(xdgConfigHome, "/htop/htoprc");
|
2016-02-02 14:53:02 +00:00
|
|
|
configDir = xStrdup(xdgConfigHome);
|
2011-12-25 20:22:41 +00:00
|
|
|
htopDir = String_cat(xdgConfigHome, "/htop");
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-01-22 01:27:31 +00:00
|
|
|
this->filename = String_cat(home, "/.config/htop/htoprc");
|
2011-12-25 20:22:41 +00:00
|
|
|
configDir = String_cat(home, "/.config");
|
|
|
|
htopDir = String_cat(home, "/.config/htop");
|
|
|
|
}
|
|
|
|
legacyDotfile = String_cat(home, "/.htoprc");
|
2022-06-07 19:16:47 +00:00
|
|
|
(void)mkdir(configDir, 0700);
|
|
|
|
(void)mkdir(htopDir, 0700);
|
2011-12-25 20:22:41 +00:00
|
|
|
free(htopDir);
|
|
|
|
free(configDir);
|
2012-03-05 11:12:58 +00:00
|
|
|
struct stat st;
|
2018-02-18 23:42:17 +00:00
|
|
|
int err = lstat(legacyDotfile, &st);
|
2022-06-07 19:16:47 +00:00
|
|
|
if (err || S_ISLNK(st.st_mode))
|
|
|
|
{
|
2011-12-25 20:22:41 +00:00
|
|
|
free(legacyDotfile);
|
|
|
|
legacyDotfile = NULL;
|
|
|
|
}
|
|
|
|
}
|
2008-03-09 08:58:38 +00:00
|
|
|
this->colorScheme = 0;
|
2021-07-14 19:07:43 +00:00
|
|
|
#ifdef HAVE_GETMOUSE
|
2019-07-12 19:41:09 +00:00
|
|
|
this->enableMouse = true;
|
2021-07-14 19:07:43 +00:00
|
|
|
#endif
|
2008-03-09 08:58:38 +00:00
|
|
|
this->changed = false;
|
|
|
|
this->delay = DEFAULT_DELAY;
|
2018-02-18 23:42:17 +00:00
|
|
|
bool ok = false;
|
2022-06-07 19:16:47 +00:00
|
|
|
if (legacyDotfile)
|
|
|
|
{
|
2020-09-23 09:52:57 +00:00
|
|
|
ok = Settings_read(this, legacyDotfile, initialCpuCount);
|
2022-06-07 19:16:47 +00:00
|
|
|
if (ok)
|
|
|
|
{
|
2011-12-25 20:22:41 +00:00
|
|
|
// Transition to new location and delete old configuration file
|
2022-06-07 19:16:47 +00:00
|
|
|
if (Settings_write(this, false) == 0)
|
|
|
|
{
|
2011-12-25 20:22:41 +00:00
|
|
|
unlink(legacyDotfile);
|
2020-11-01 00:09:51 +00:00
|
|
|
}
|
2011-12-25 20:22:41 +00:00
|
|
|
}
|
2018-02-18 23:42:17 +00:00
|
|
|
free(legacyDotfile);
|
|
|
|
}
|
2022-06-07 19:16:47 +00:00
|
|
|
if (!ok)
|
|
|
|
{
|
2020-09-23 09:52:57 +00:00
|
|
|
ok = Settings_read(this, this->filename, initialCpuCount);
|
2018-02-18 23:42:17 +00:00
|
|
|
}
|
2022-06-07 19:16:47 +00:00
|
|
|
if (!ok)
|
|
|
|
{
|
2021-10-26 10:21:40 +00:00
|
|
|
this->screenTabs = true;
|
2008-03-09 08:58:38 +00:00
|
|
|
this->changed = true;
|
2021-09-09 07:04:41 +00:00
|
|
|
ok = Settings_read(this, SYSCONFDIR "/htoprc", initialCpuCount);
|
2018-02-18 23:42:17 +00:00
|
|
|
}
|
2022-06-07 19:16:47 +00:00
|
|
|
if (!ok)
|
|
|
|
{
|
2021-08-28 15:57:51 +00:00
|
|
|
Settings_defaultMeters(this, initialCpuCount);
|
2021-08-31 05:38:52 +00:00
|
|
|
Settings_defaultScreens(this);
|
2021-08-28 15:57:51 +00:00
|
|
|
}
|
2021-08-31 05:38:52 +00:00
|
|
|
|
|
|
|
this->ssIndex = 0;
|
|
|
|
this->ss = this->screens[this->ssIndex];
|
|
|
|
|
2022-05-29 21:03:56 +00:00
|
|
|
this->lastUpdate = 1;
|
|
|
|
|
2008-03-09 08:58:38 +00:00
|
|
|
return this;
|
|
|
|
}
|
2015-01-22 01:27:31 +00:00
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
void ScreenSettings_invertSortOrder(ScreenSettings *this)
|
|
|
|
{
|
|
|
|
int *attr = (this->treeView) ? &(this->treeDirection) : &(this->direction);
|
2020-12-18 14:03:31 +00:00
|
|
|
*attr = (*attr == 1) ? -1 : 1;
|
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
void ScreenSettings_setSortKey(ScreenSettings *this, ProcessField sortKey)
|
|
|
|
{
|
|
|
|
if (this->treeViewAlwaysByPID || !this->treeView)
|
|
|
|
{
|
2020-12-18 14:03:31 +00:00
|
|
|
this->sortKey = sortKey;
|
2021-01-21 13:27:23 +00:00
|
|
|
this->direction = (Process_fields[sortKey].defaultSortDesc) ? -1 : 1;
|
2020-12-18 14:03:31 +00:00
|
|
|
this->treeView = false;
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-18 14:03:31 +00:00
|
|
|
this->treeSortKey = sortKey;
|
2021-01-21 13:27:23 +00:00
|
|
|
this->treeDirection = (Process_fields[sortKey].defaultSortDesc) ? -1 : 1;
|
2020-11-01 00:09:51 +00:00
|
|
|
}
|
2015-01-22 01:27:31 +00:00
|
|
|
}
|
2021-01-21 19:27:37 +00:00
|
|
|
|
|
|
|
static bool readonly = false;
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
void Settings_enableReadonly(void)
|
|
|
|
{
|
2021-01-21 19:27:37 +00:00
|
|
|
readonly = true;
|
|
|
|
}
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
bool Settings_isReadonly(void)
|
|
|
|
{
|
2021-01-21 19:27:37 +00:00
|
|
|
return readonly;
|
|
|
|
}
|
2020-12-25 15:42:35 +00:00
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
void Settings_setHeaderLayout(Settings *this, HeaderLayout hLayout)
|
|
|
|
{
|
2020-12-25 15:42:35 +00:00
|
|
|
unsigned int oldColumns = HeaderLayout_getColumns(this->hLayout);
|
|
|
|
unsigned int newColumns = HeaderLayout_getColumns(hLayout);
|
|
|
|
|
2022-06-07 19:16:47 +00:00
|
|
|
if (newColumns > oldColumns)
|
|
|
|
{
|
2020-12-25 15:42:35 +00:00
|
|
|
this->hColumns = xReallocArray(this->hColumns, newColumns, sizeof(MeterColumnSetting));
|
|
|
|
memset(this->hColumns + oldColumns, 0, (newColumns - oldColumns) * sizeof(MeterColumnSetting));
|
2022-06-07 19:16:47 +00:00
|
|
|
}
|
|
|
|
else if (newColumns < oldColumns)
|
|
|
|
{
|
|
|
|
for (unsigned int i = newColumns; i < oldColumns; i++)
|
|
|
|
{
|
|
|
|
if (this->hColumns[i].names)
|
|
|
|
{
|
2021-09-04 12:15:47 +00:00
|
|
|
for (size_t j = 0; j < this->hColumns[i].len; j++)
|
2020-12-25 15:42:35 +00:00
|
|
|
free(this->hColumns[i].names[j]);
|
|
|
|
free(this->hColumns[i].names);
|
|
|
|
}
|
|
|
|
free(this->hColumns[i].modes);
|
|
|
|
}
|
|
|
|
this->hColumns = xReallocArray(this->hColumns, newColumns, sizeof(MeterColumnSetting));
|
|
|
|
}
|
|
|
|
|
|
|
|
this->hLayout = hLayout;
|
|
|
|
this->changed = true;
|
|
|
|
}
|