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
2020-10-05 07:51:32 +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-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>
# 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
2011-12-26 21:35:57 +00:00
2006-03-04 18:16:49 +00:00
void Settings_delete ( Settings * this ) {
2015-01-22 01:27:31 +00:00
free ( this - > filename ) ;
free ( this - > fields ) ;
2020-09-28 19:14:50 +00:00
for ( unsigned int i = 0 ; i < ARRAYSIZE ( this - > columns ) ; i + + ) {
2015-01-22 01:27:31 +00:00
String_freeArray ( this - > columns [ i ] . names ) ;
free ( this - > columns [ i ] . modes ) ;
}
2006-03-04 18:16:49 +00:00
free ( this ) ;
}
2021-01-05 22:42:55 +00:00
static void Settings_readMeters ( Settings * this , const char * line , int column ) {
2006-03-04 18:16:49 +00:00
char * trim = String_trim ( line ) ;
2020-10-03 19:20:43 +00:00
char * * ids = String_split ( trim , ' ' , NULL ) ;
2006-03-04 18:16:49 +00:00
free ( trim ) ;
2015-01-22 01:27:31 +00:00
this - > columns [ column ] . names = ids ;
2006-03-04 18:16:49 +00:00
}
2021-01-05 22:42:55 +00:00
static void Settings_readMeterModes ( Settings * this , const char * line , int column ) {
2006-03-04 18:16:49 +00:00
char * trim = String_trim ( line ) ;
2020-10-03 19:20:43 +00:00
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 ;
2011-08-29 20:45:29 +00:00
for ( int i = 0 ; ids [ i ] ; i + + ) {
2015-01-22 01:27:31 +00:00
len + + ;
}
this - > columns [ column ] . len = len ;
2021-01-25 16:31:43 +00:00
int * modes = len ? xCalloc ( len , sizeof ( int ) ) : NULL ;
2015-01-22 01:27:31 +00:00
for ( int i = 0 ; i < len ; i + + ) {
modes [ i ] = atoi ( ids [ i ] ) ;
2006-03-04 18:16:49 +00:00
}
String_freeArray ( ids ) ;
2015-01-22 01:27:31 +00:00
this - > columns [ column ] . modes = modes ;
2006-03-04 18:16:49 +00:00
}
2021-02-17 16:38:35 +00:00
static void Settings_defaultMeters ( Settings * this , unsigned int initialCpuCount ) {
2015-01-22 01:27:31 +00:00
int sizes [ ] = { 3 , 3 } ;
2021-02-02 09:32:11 +00:00
if ( initialCpuCount > 4 & & initialCpuCount < = 128 ) {
2015-01-22 01:27:31 +00:00
sizes [ 1 ] + + ;
}
for ( int i = 0 ; i < 2 ; i + + ) {
2016-02-02 14:53:02 +00:00
this - > columns [ i ] . names = xCalloc ( sizes [ i ] + 1 , sizeof ( char * ) ) ;
this - > columns [ i ] . modes = xCalloc ( sizes [ i ] , sizeof ( int ) ) ;
2015-03-17 02:01:21 +00:00
this - > columns [ i ] . len = sizes [ i ] ;
2015-01-22 01:27:31 +00:00
}
int r = 0 ;
2021-02-02 09:32:11 +00:00
if ( initialCpuCount > 128 ) {
// Just show the average, ricers need to config for impressive screenshots
this - > columns [ 0 ] . names [ 0 ] = xStrdup ( " CPU " ) ;
this - > columns [ 0 ] . modes [ 0 ] = BAR_METERMODE ;
} else if ( initialCpuCount > 32 ) {
this - > columns [ 0 ] . names [ 0 ] = xStrdup ( " LeftCPUs8 " ) ;
this - > columns [ 0 ] . modes [ 0 ] = BAR_METERMODE ;
this - > columns [ 1 ] . names [ r ] = xStrdup ( " RightCPUs8 " ) ;
this - > columns [ 1 ] . modes [ r + + ] = BAR_METERMODE ;
} else if ( initialCpuCount > 16 ) {
this - > columns [ 0 ] . names [ 0 ] = xStrdup ( " LeftCPUs4 " ) ;
this - > columns [ 0 ] . modes [ 0 ] = BAR_METERMODE ;
this - > columns [ 1 ] . names [ r ] = xStrdup ( " RightCPUs4 " ) ;
this - > columns [ 1 ] . modes [ r + + ] = BAR_METERMODE ;
} else if ( initialCpuCount > 8 ) {
2016-02-02 14:53:02 +00:00
this - > columns [ 0 ] . names [ 0 ] = xStrdup ( " LeftCPUs2 " ) ;
2016-02-02 15:15:07 +00:00
this - > columns [ 0 ] . modes [ 0 ] = BAR_METERMODE ;
this - > columns [ 1 ] . names [ r ] = xStrdup ( " RightCPUs2 " ) ;
this - > columns [ 1 ] . modes [ r + + ] = BAR_METERMODE ;
2020-09-23 09:52:57 +00:00
} else if ( initialCpuCount > 4 ) {
2016-02-02 14:53:02 +00:00
this - > columns [ 0 ] . names [ 0 ] = xStrdup ( " LeftCPUs " ) ;
2016-02-02 15:15:07 +00:00
this - > columns [ 0 ] . modes [ 0 ] = BAR_METERMODE ;
this - > columns [ 1 ] . names [ r ] = xStrdup ( " RightCPUs " ) ;
this - > columns [ 1 ] . modes [ r + + ] = BAR_METERMODE ;
2014-11-27 20:38:52 +00:00
} else {
2016-02-02 14:53:02 +00:00
this - > columns [ 0 ] . names [ 0 ] = xStrdup ( " AllCPUs " ) ;
2016-02-02 15:15:07 +00:00
this - > columns [ 0 ] . modes [ 0 ] = BAR_METERMODE ;
2015-01-22 01:27:31 +00:00
}
2016-02-02 14:53:02 +00:00
this - > columns [ 0 ] . names [ 1 ] = xStrdup ( " Memory " ) ;
2016-02-02 15:15:07 +00:00
this - > columns [ 0 ] . modes [ 1 ] = BAR_METERMODE ;
2016-02-02 14:53:02 +00:00
this - > columns [ 0 ] . names [ 2 ] = xStrdup ( " Swap " ) ;
2016-02-02 15:15:07 +00:00
this - > columns [ 0 ] . modes [ 2 ] = BAR_METERMODE ;
this - > columns [ 1 ] . names [ r ] = xStrdup ( " Tasks " ) ;
this - > columns [ 1 ] . modes [ r + + ] = TEXT_METERMODE ;
this - > columns [ 1 ] . names [ r ] = xStrdup ( " LoadAverage " ) ;
this - > columns [ 1 ] . modes [ r + + ] = TEXT_METERMODE ;
this - > columns [ 1 ] . names [ r ] = xStrdup ( " Uptime " ) ;
this - > columns [ 1 ] . modes [ r + + ] = TEXT_METERMODE ;
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
static void Settings_readFields ( Settings * settings , const char * line ) {
2015-01-22 01:27:31 +00:00
char * trim = String_trim ( line ) ;
2020-10-03 19:20:43 +00:00
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
settings - > flags = 0 ;
unsigned int i , j ;
for ( j = 0 , i = 0 ; ids [ i ] ; i + + ) {
if ( j > = UINT_MAX / sizeof ( ProcessField ) )
continue ;
if ( j > = LAST_PROCESSFIELD ) {
settings - > fields = xRealloc ( settings - > fields , j * sizeof ( ProcessField ) ) ;
memset ( & settings - > fields [ j ] , 0 , sizeof ( ProcessField ) ) ;
}
// Dynamically-defined columns are always stored by-name.
char * end , dynamic [ 32 ] = { 0 } ;
if ( sscanf ( ids [ i ] , " Dynamic(%30s) " , dynamic ) ) {
if ( ( end = strrchr ( dynamic , ' ) ' ) ) = = NULL )
continue ;
* end = ' \0 ' ;
unsigned int key ;
if ( ! DynamicColumn_search ( settings - > dynamicColumns , dynamic , & key ) )
continue ;
settings - > fields [ j + + ] = key ;
continue ;
}
2015-01-22 01:27:31 +00:00
// This "+1" is for compatibility with the older enum format.
int id = atoi ( ids [ i ] ) + 1 ;
2020-12-15 18:44:48 +00:00
if ( id > 0 & & id < LAST_PROCESSFIELD & & Process_fields [ id ] . name ) {
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
settings - > flags | = Process_fields [ id ] . flags ;
settings - > fields [ j + + ] = id ;
2015-01-22 01:27:31 +00:00
}
2014-11-27 20:38:52 +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
settings - > fields [ j ] = NULL_PROCESSFIELD ;
2015-01-22 01:27:31 +00:00
String_freeArray ( ids ) ;
2014-11-27 20:38:52 +00:00
}
2021-02-17 16:38:35 +00:00
static bool Settings_read ( Settings * this , const char * fileName , unsigned int initialCpuCount ) {
2021-02-16 18:44:59 +00:00
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
2018-02-18 23:35:23 +00:00
bool didReadMeters = false ;
bool didReadFields = false ;
2016-06-19 21:55:35 +00:00
for ( ; ; ) {
char * line = String_readLine ( fd ) ;
if ( ! line ) {
break ;
}
2020-10-03 19:20:43 +00:00
size_t nOptions ;
2016-06-19 21:55:35 +00:00
char * * option = String_split ( line , ' = ' , & nOptions ) ;
free ( line ) ;
2011-08-29 20:45:29 +00:00
if ( nOptions < 2 ) {
String_freeArray ( option ) ;
continue ;
}
2021-07-16 15:04:23 +00:00
if ( String_eq ( option [ 0 ] , " config_reader_min_version " ) ) {
this - > config_version = atoi ( option [ 1 ] ) ;
if ( this - > config_version > CONFIG_READER_MIN_VERSION ) {
// the version of the config file on disk is newer than what we can read
fprintf ( stderr , " WARNING: The config file %s requires support for a newer format (v%d) than what this version of htop can read (v%d). \n " , fileName , this - > config_version , CONFIG_READER_MIN_VERSION ) ;
fprintf ( stderr , " It will be overwritten when this version of htop exits. \n " ) ;
return false ;
}
} else if ( String_eq ( option [ 0 ] , " fields " ) ) {
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
Settings_readFields ( this , option [ 1 ] ) ;
2018-02-18 23:35:23 +00:00
didReadFields = true ;
2006-03-04 18:16:49 +00:00
} else if ( String_eq ( option [ 0 ] , " sort_key " ) ) {
// This "+1" is for compatibility with the older enum format.
2015-01-22 01:27:31 +00:00
this - > sortKey = atoi ( option [ 1 ] ) + 1 ;
2020-12-18 14:03:31 +00:00
} else if ( String_eq ( option [ 0 ] , " tree_sort_key " ) ) {
// This "+1" is for compatibility with the older enum format.
this - > treeSortKey = atoi ( option [ 1 ] ) + 1 ;
2006-03-04 18:16:49 +00:00
} else if ( String_eq ( option [ 0 ] , " sort_direction " ) ) {
2015-01-22 01:27:31 +00:00
this - > direction = atoi ( option [ 1 ] ) ;
2020-12-18 14:03:31 +00:00
} else if ( String_eq ( option [ 0 ] , " tree_sort_direction " ) ) {
this - > treeDirection = atoi ( option [ 1 ] ) ;
2006-03-04 18:16:49 +00:00
} else if ( String_eq ( option [ 0 ] , " tree_view " ) ) {
2015-01-22 01:27:31 +00:00
this - > treeView = atoi ( option [ 1 ] ) ;
2020-12-17 22:08:56 +00:00
} else if ( String_eq ( option [ 0 ] , " tree_view_always_by_pid " ) ) {
this - > treeViewAlwaysByPID = atoi ( option [ 1 ] ) ;
2021-02-12 17:48:09 +00:00
} else if ( String_eq ( option [ 0 ] , " all_branches_collapsed " ) ) {
this - > allBranchesCollapsed = atoi ( option [ 1 ] ) ;
2006-03-04 18:16:49 +00:00
} else if ( String_eq ( option [ 0 ] , " hide_kernel_threads " ) ) {
2015-01-22 01:27:31 +00:00
this - > hideKernelThreads = atoi ( option [ 1 ] ) ;
2006-03-04 18:16:49 +00:00
} else if ( String_eq ( option [ 0 ] , " hide_userland_threads " ) ) {
2015-01-22 01:27:31 +00:00
this - > hideUserlandThreads = atoi ( option [ 1 ] ) ;
2006-03-04 18:16:49 +00:00
} else if ( String_eq ( option [ 0 ] , " shadow_other_users " ) ) {
2015-01-22 01:27:31 +00:00
this - > shadowOtherUsers = atoi ( option [ 1 ] ) ;
2010-02-25 01:37:31 +00:00
} else if ( String_eq ( option [ 0 ] , " show_thread_names " ) ) {
2015-01-22 01:27:31 +00:00
this - > showThreadNames = atoi ( option [ 1 ] ) ;
2015-07-29 19:14:29 +00:00
} else if ( String_eq ( option [ 0 ] , " show_program_path " ) ) {
this - > showProgramPath = atoi ( option [ 1 ] ) ;
2006-03-04 18:16:49 +00:00
} else if ( String_eq ( option [ 0 ] , " highlight_base_name " ) ) {
2015-01-22 01:27:31 +00:00
this - > highlightBaseName = atoi ( option [ 1 ] ) ;
2020-12-19 15:46:00 +00:00
} else if ( String_eq ( option [ 0 ] , " highlight_deleted_exe " ) ) {
this - > highlightDeletedExe = atoi ( option [ 1 ] ) ;
2006-03-04 18:16:49 +00:00
} else if ( String_eq ( option [ 0 ] , " highlight_megabytes " ) ) {
2015-01-22 01:27:31 +00:00
this - > highlightMegabytes = atoi ( option [ 1 ] ) ;
2008-03-08 23:39:48 +00:00
} else if ( String_eq ( option [ 0 ] , " highlight_threads " ) ) {
2015-01-22 01:27:31 +00:00
this - > highlightThreads = atoi ( option [ 1 ] ) ;
2020-10-31 01:56:16 +00:00
} else if ( String_eq ( option [ 0 ] , " highlight_changes " ) ) {
this - > highlightChanges = atoi ( option [ 1 ] ) ;
} 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 ) ;
2020-10-17 10:54:45 +00:00
} else if ( String_eq ( option [ 0 ] , " find_comm_in_cmdline " ) ) {
this - > findCommInCmdline = atoi ( option [ 1 ] ) ;
} else if ( String_eq ( option [ 0 ] , " strip_exe_from_cmdline " ) ) {
this - > stripExeFromCmdline = atoi ( option [ 1 ] ) ;
} else if ( String_eq ( option [ 0 ] , " show_merged_command " ) ) {
this - > showMergedCommand = atoi ( option [ 1 ] ) ;
2006-03-04 18:16:49 +00:00
} else if ( String_eq ( option [ 0 ] , " header_margin " ) ) {
2015-01-22 01:27:31 +00:00
this - > headerMargin = atoi ( option [ 1 ] ) ;
2006-10-04 14:21:27 +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 ] ) ;
2007-11-09 00:40:59 +00:00
} else if ( String_eq ( option [ 0 ] , " detailed_cpu_time " ) ) {
2015-01-22 01:27:31 +00:00
this - > detailedCPUTime = atoi ( option [ 1 ] ) ;
2019-12-19 22:30:45 +00:00
} else if ( String_eq ( option [ 0 ] , " cpu_count_from_one " ) ) {
this - > countCPUsFromOne = atoi ( option [ 1 ] ) ;
2011-03-22 20:37:08 +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 ] ) ;
2019-08-10 18:20:21 +00:00
} else if ( String_eq ( option [ 0 ] , " show_cpu_usage " ) ) {
this - > showCPUUsage = atoi ( option [ 1 ] ) ;
2019-08-10 04:34:48 +00:00
} else if ( String_eq ( option [ 0 ] , " show_cpu_frequency " ) ) {
this - > showCPUFrequency = atoi ( option [ 1 ] ) ;
2020-12-22 19:02:01 +00:00
# ifdef BUILD_WITH_CPU_TEMP
2020-09-10 17:56:33 +00:00
} else if ( String_eq ( option [ 0 ] , " show_cpu_temperature " ) ) {
this - > showCPUTemperature = atoi ( option [ 1 ] ) ;
} else if ( String_eq ( option [ 0 ] , " degree_fahrenheit " ) ) {
this - > degreeFahrenheit = atoi ( option [ 1 ] ) ;
# endif
2012-10-20 00:43:25 +00:00
} else if ( String_eq ( option [ 0 ] , " update_process_names " ) ) {
2015-01-22 01:27:31 +00:00
this - > updateProcessNames = atoi ( option [ 1 ] ) ;
2013-12-18 02:58:34 +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 ] ) ;
2006-03-04 18:16:49 +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 ) ;
2006-03-04 18:16:49 +00:00
} else if ( String_eq ( option [ 0 ] , " color_scheme " ) ) {
this - > colorScheme = atoi ( option [ 1 ] ) ;
2020-11-01 00:09:51 +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
}
2021-07-14 19:07:43 +00:00
# ifdef HAVE_GETMOUSE
2020-10-31 21:14:27 +00:00
} else if ( String_eq ( option [ 0 ] , " enable_mouse " ) ) {
2019-07-12 19:41:09 +00:00
this - > enableMouse = atoi ( option [ 1 ] ) ;
2021-07-14 19:07:43 +00:00
# endif
2006-03-04 18:16:49 +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 ;
2006-03-04 18:16:49 +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 ;
2006-03-04 18:16:49 +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 ;
2006-03-04 18:16:49 +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 ;
2020-12-28 22:26:14 +00:00
} else if ( String_eq ( option [ 0 ] , " hide_function_bar " ) ) {
this - > hideFunctionBar = atoi ( option [ 1 ] ) ;
2020-08-26 00:15:00 +00:00
# ifdef HAVE_LIBHWLOC
} else if ( String_eq ( option [ 0 ] , " topology_affinity " ) ) {
this - > topologyAffinity = ! ! atoi ( option [ 1 ] ) ;
# endif
2006-03-04 18:16:49 +00:00
}
String_freeArray ( option ) ;
}
fclose ( fd ) ;
2018-02-18 23:35:23 +00:00
if ( ! didReadMeters ) {
2020-09-23 09:52:57 +00:00
Settings_defaultMeters ( this , initialCpuCount ) ;
2006-03-04 18:16:49 +00:00
}
2018-02-18 23:35:23 +00:00
return didReadFields ;
2006-03-04 18:16:49 +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
static void writeFields ( FILE * fd , const ProcessField * fields , Hashtable * columns , const char * name ) {
2015-01-22 01:27:31 +00:00
fprintf ( fd , " %s= " , name ) ;
2017-07-24 23:36:27 +00:00
const char * sep = " " ;
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
for ( unsigned int i = 0 ; fields [ i ] ; i + + ) {
if ( fields [ i ] > = LAST_PROCESSFIELD ) {
const DynamicColumn * column = DynamicColumn_lookup ( columns , fields [ i ] ) ;
fprintf ( fd , " %sDynamic(%s) " , sep , column - > name ) ;
} else {
// This "-1" is for compatibility with the older enum format.
fprintf ( fd , " %s%d " , sep , ( int ) fields [ i ] - 1 ) ;
}
2017-07-24 23:36:27 +00:00
sep = " " ;
2015-01-22 01:27:31 +00:00
}
fprintf ( fd , " \n " ) ;
}
2021-03-12 15:48:41 +00:00
static void writeMeters ( const Settings * this , FILE * fd , int column ) {
2017-07-24 23:36:27 +00:00
const char * sep = " " ;
2015-01-22 01:27:31 +00:00
for ( int i = 0 ; i < this - > columns [ column ] . len ; i + + ) {
2017-07-24 23:36:27 +00:00
fprintf ( fd , " %s%s " , sep , this - > columns [ column ] . names [ i ] ) ;
sep = " " ;
2015-01-22 01:27:31 +00:00
}
fprintf ( fd , " \n " ) ;
}
2021-03-12 15:48:41 +00:00
static void writeMeterModes ( const Settings * this , FILE * fd , int column ) {
2017-07-24 23:36:27 +00:00
const char * sep = " " ;
2015-01-22 01:27:31 +00:00
for ( int i = 0 ; i < this - > columns [ column ] . len ; i + + ) {
2017-07-24 23:36:27 +00:00
fprintf ( fd , " %s%d " , sep , this - > columns [ column ] . modes [ i ] ) ;
sep = " " ;
2015-01-22 01:27:31 +00:00
}
fprintf ( fd , " \n " ) ;
}
2021-05-16 17:55:31 +00:00
int Settings_write ( const Settings * this , bool onCrash ) {
FILE * fd ;
if ( onCrash ) {
fd = stderr ;
} else {
fd = fopen ( this - > filename , " w " ) ;
if ( fd = = NULL )
return - errno ;
}
2021-02-16 18:44:59 +00:00
2021-05-16 17:55:31 +00:00
if ( ! onCrash ) {
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-07-16 15:04:23 +00:00
fprintf ( fd , " htop_version=%s \n " , VERSION ) ;
fprintf ( fd , " config_reader_min_version=%d \n " , CONFIG_READER_MIN_VERSION ) ;
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
writeFields ( fd , this - > fields , this - > dynamicColumns , " fields " ) ;
2006-03-04 18:16:49 +00:00
// This "-1" is for compatibility with the older enum format.
2020-10-31 22:28:02 +00:00
fprintf ( fd , " sort_key=%d \n " , ( int ) this - > sortKey - 1 ) ;
2015-01-22 01:27:31 +00:00
fprintf ( fd , " sort_direction=%d \n " , ( int ) this - > direction ) ;
2020-12-18 14:03:31 +00:00
fprintf ( fd , " tree_sort_key=%d \n " , ( int ) this - > treeSortKey - 1 ) ;
fprintf ( fd , " tree_sort_direction=%d \n " , ( int ) this - > treeDirection ) ;
2015-01-22 01:27:31 +00:00
fprintf ( fd , " hide_kernel_threads=%d \n " , ( int ) this - > hideKernelThreads ) ;
fprintf ( fd , " hide_userland_threads=%d \n " , ( int ) this - > hideUserlandThreads ) ;
fprintf ( fd , " shadow_other_users=%d \n " , ( int ) this - > shadowOtherUsers ) ;
fprintf ( fd , " show_thread_names=%d \n " , ( int ) this - > showThreadNames ) ;
2015-07-29 19:14:29 +00:00
fprintf ( fd , " show_program_path=%d \n " , ( int ) this - > showProgramPath ) ;
2015-01-22 01:27:31 +00:00
fprintf ( fd , " highlight_base_name=%d \n " , ( int ) this - > highlightBaseName ) ;
2020-12-19 15:46:00 +00:00
fprintf ( fd , " highlight_deleted_exe=%d \n " , ( int ) this - > highlightDeletedExe ) ;
2015-01-22 01:27:31 +00:00
fprintf ( fd , " highlight_megabytes=%d \n " , ( int ) this - > highlightMegabytes ) ;
fprintf ( fd , " highlight_threads=%d \n " , ( int ) this - > highlightThreads ) ;
2020-10-31 01:56:16 +00:00
fprintf ( fd , " highlight_changes=%d \n " , ( int ) this - > highlightChanges ) ;
fprintf ( fd , " highlight_changes_delay_secs=%d \n " , ( int ) this - > highlightDelaySecs ) ;
2020-10-17 10:54:45 +00:00
fprintf ( fd , " find_comm_in_cmdline=%d \n " , ( int ) this - > findCommInCmdline ) ;
fprintf ( fd , " strip_exe_from_cmdline=%d \n " , ( int ) this - > stripExeFromCmdline ) ;
fprintf ( fd , " show_merged_command=%d \n " , ( int ) this - > showMergedCommand ) ;
2015-01-22 01:27:31 +00:00
fprintf ( fd , " tree_view=%d \n " , ( int ) this - > treeView ) ;
2020-12-17 22:08:56 +00:00
fprintf ( fd , " tree_view_always_by_pid=%d \n " , ( int ) this - > treeViewAlwaysByPID ) ;
2021-02-12 17:48:09 +00:00
fprintf ( fd , " all_branches_collapsed=%d \n " , ( int ) this - > allBranchesCollapsed ) ;
2015-01-22 01:27:31 +00:00
fprintf ( fd , " header_margin=%d \n " , ( int ) this - > headerMargin ) ;
fprintf ( fd , " detailed_cpu_time=%d \n " , ( int ) this - > detailedCPUTime ) ;
2019-12-19 22:30:45 +00:00
fprintf ( fd , " cpu_count_from_one=%d \n " , ( int ) this - > countCPUsFromOne ) ;
2019-08-10 18:20:21 +00:00
fprintf ( fd , " show_cpu_usage=%d \n " , ( int ) this - > showCPUUsage ) ;
2019-08-10 04:34:48 +00:00
fprintf ( fd , " show_cpu_frequency=%d \n " , ( int ) this - > showCPUFrequency ) ;
2020-12-22 19:02:01 +00:00
# ifdef BUILD_WITH_CPU_TEMP
2020-09-10 17:56:33 +00:00
fprintf ( fd , " show_cpu_temperature=%d \n " , ( int ) this - > showCPUTemperature ) ;
fprintf ( fd , " degree_fahrenheit=%d \n " , ( int ) this - > degreeFahrenheit ) ;
# endif
2015-01-22 01:27:31 +00:00
fprintf ( fd , " update_process_names=%d \n " , ( int ) this - > updateProcessNames ) ;
fprintf ( fd , " account_guest_in_cpu_meter=%d \n " , ( int ) this - > accountGuestInCPUMeter ) ;
2006-03-04 18:16:49 +00:00
fprintf ( fd , " color_scheme=%d \n " , ( int ) this - > colorScheme ) ;
2021-07-14 19:07:43 +00:00
# ifdef HAVE_GETMOUSE
2019-07-12 19:41:09 +00:00
fprintf ( fd , " enable_mouse=%d \n " , ( int ) this - > enableMouse ) ;
2021-07-14 19:07:43 +00:00
# endif
2006-03-04 18:16:49 +00:00
fprintf ( fd , " delay=%d \n " , ( int ) this - > delay ) ;
2015-01-22 01:27:31 +00:00
fprintf ( fd , " left_meters= " ) ; writeMeters ( this , fd , 0 ) ;
fprintf ( fd , " left_meter_modes= " ) ; writeMeterModes ( this , fd , 0 ) ;
fprintf ( fd , " right_meters= " ) ; writeMeters ( this , fd , 1 ) ;
fprintf ( fd , " right_meter_modes= " ) ; writeMeterModes ( this , fd , 1 ) ;
2020-12-28 22:26:14 +00:00
fprintf ( fd , " hide_function_bar=%d \n " , ( int ) this - > hideFunctionBar ) ;
2020-08-26 00:15:00 +00:00
# ifdef HAVE_LIBHWLOC
fprintf ( fd , " topology_affinity=%d \n " , ( int ) this - > topologyAffinity ) ;
# endif
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
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
Settings * Settings_new ( unsigned int initialCpuCount , Hashtable * dynamicColumns ) {
2016-02-02 14:53:02 +00:00
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 ;
2015-01-22 01:27:31 +00:00
this - > sortKey = PERCENT_CPU ;
2020-12-18 14:03:31 +00:00
this - > treeSortKey = PID ;
2021-01-21 13:27:23 +00:00
this - > direction = - 1 ;
2020-12-18 14:03:31 +00:00
this - > treeDirection = 1 ;
2015-01-22 01:27:31 +00:00
this - > shadowOtherUsers = false ;
this - > showThreadNames = false ;
this - > hideKernelThreads = false ;
this - > hideUserlandThreads = false ;
this - > treeView = false ;
2021-02-12 17:48:09 +00:00
this - > allBranchesCollapsed = false ;
2015-01-22 01:27:31 +00:00
this - > highlightBaseName = false ;
2020-12-19 15:46:00 +00:00
this - > highlightDeletedExe = true ;
2015-01-22 01:27:31 +00:00
this - > highlightMegabytes = false ;
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 ;
2020-12-22 19:02:01 +00:00
# ifdef BUILD_WITH_CPU_TEMP
2020-09-10 17:56:33 +00:00
this - > showCPUTemperature = false ;
this - > degreeFahrenheit = false ;
# 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 ;
2020-08-26 00:15:00 +00:00
# ifdef HAVE_LIBHWLOC
this - > topologyAffinity = false ;
# endif
2020-12-15 18:44:48 +00:00
this - > fields = xCalloc ( LAST_PROCESSFIELD + 1 , sizeof ( ProcessField ) ) ;
2015-01-22 01:27:31 +00:00
// TODO: turn 'fields' into a Vector,
// (and ProcessFields into proper objects).
this - > flags = 0 ;
2020-12-19 17:10:03 +00:00
const ProcessField * defaults = Platform_defaultFields ;
2015-01-22 01:27:31 +00:00
for ( int i = 0 ; defaults [ i ] ; i + + ) {
this - > fields [ i ] = defaults [ i ] ;
this - > flags | = Process_fields [ defaults [ i ] ] . flags ;
}
2011-12-25 20:22:41 +00:00
char * legacyDotfile = NULL ;
2021-01-05 22:42:55 +00:00
const char * rcfile = getenv ( " HTOPRC " ) ;
2011-12-25 20:22:41 +00:00
if ( rcfile ) {
2016-02-02 14:53:02 +00:00
this - > filename = xStrdup ( rcfile ) ;
2011-12-25 20:22:41 +00:00
} else {
const char * home = getenv ( " HOME " ) ;
2020-11-01 00:09:51 +00:00
if ( ! home )
home = " " ;
2011-12-25 20:22:41 +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 " ) ;
} 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 " ) ;
2014-04-22 23:35:57 +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 ) ;
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 ;
if ( legacyDotfile ) {
2020-09-23 09:52:57 +00:00
ok = Settings_read ( this , legacyDotfile , initialCpuCount ) ;
2018-02-18 23:42:17 +00:00
if ( ok ) {
2011-12-25 20:22:41 +00:00
// Transition to new location and delete old configuration file
2021-05-16 17:55:31 +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 ) ;
}
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
}
if ( ! ok ) {
2008-03-09 08:58:38 +00:00
this - > changed = true ;
2021-01-29 15:44:23 +00:00
ok = Settings_read ( this , SYSCONFDIR " /htoprc " , initialCpuCount ) ;
2008-03-09 08:58:38 +00:00
}
2018-02-18 23:42:17 +00:00
if ( ! ok ) {
2020-09-23 09:52:57 +00:00
Settings_defaultMeters ( this , initialCpuCount ) ;
2018-02-18 23:42:17 +00:00
this - > hideKernelThreads = true ;
this - > highlightMegabytes = true ;
this - > highlightThreads = true ;
2020-10-17 10:54:45 +00:00
this - > findCommInCmdline = true ;
this - > stripExeFromCmdline = true ;
this - > showMergedCommand = false ;
2018-02-18 23:42:17 +00:00
this - > headerMargin = true ;
}
2008-03-09 08:58:38 +00:00
return this ;
}
2015-01-22 01:27:31 +00:00
void Settings_invertSortOrder ( Settings * this ) {
2020-12-18 14:03:31 +00:00
int * attr = ( this - > treeView ) ? & ( this - > treeDirection ) : & ( this - > direction ) ;
* attr = ( * attr = = 1 ) ? - 1 : 1 ;
}
void Settings_setSortKey ( Settings * this , ProcessField sortKey ) {
if ( this - > treeViewAlwaysByPID | | ! this - > treeView ) {
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 ;
} else {
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 ;
void Settings_enableReadonly ( void ) {
readonly = true ;
}
bool Settings_isReadonly ( void ) {
return readonly ;
}