summaryrefslogtreecommitdiffstats
path: root/Settings.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix GCC build warning in NetBSD 10mainExplorer092 days1-1/+1
| | | | | | | | | | | | | The warning message is "array subscript has type 'char' [-Wchar-subscripts]" Fix this by casting to 'unsigned char' before passing any character to a `<ctype.h>` function. Also add an assertion to RichString_writeFromAscii() to ensure the characters in the string are all in ASCII range. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Use struct member to determine size of allocationsBenny Baumann8 days1-2/+2
|
* Define MeterModeId to unsigned int and use it throughoutExplorer098 days1-5/+5
| | | | | | | | | All uses of meter drawing "mode" numbers now have the type `MeterModeId`, including the uses in structures and arrays. `MeterModeId` is defined as `unsigned int`, as (currently) it doesn't save any code size by defining it to any smaller type. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Use 'fp' name for local 'FILE*' variables.Explorer0911 days1-37/+37
| | | | | | | | | | | It is inappropriate to use the 'fd' name for 'FILE*' variables. POSIX file descriptiors are of type 'int' and are distinguished from ISO C stream pointers (type 'FILE*'). Rename these variables to 'fp', which is a preferred naming in POSIX. (Note that ISO C preferred the 'stream' name for the variables.) No code changes.
* Merge branch 'signal_safe' of cgzones/htopDaniel Lange12 days1-29/+53
|\
| * Avoid fprintf in Settings_writeChristian Göttsche2024-04-131-29/+53
| | | | | | | | | | | | | | | | Settings_write() is called on a crash inside of a signal handler. Using fprintf(3) is not safe to call ins signal handlers due to file buffering and memory allocations. Format messages in signal handlers via snprintf(3) and output them via write(2) on crash.
* | Avoid writing configuration to non-regular filesExplorer0912 days1-16/+50
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Check whether the configuration file (after symlink resolution) is writable and is a regular file on htop startup, and only then, write the configuration on exit. Also permit reading when the legacy configuration file ("~/.htoprc") is a symlink. Write the new configuration only when both the legacy file and the new location are writable. Thanks to Christian Göttsche (@cgzones) for providing the initial version of the patch. Fixes: #1426 Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* | Memory leak when a legacy config file existsBenny Baumann12 days1-2/+5
|/ | | | | | | Fixes regression caused by 15b4bc45b2b0ccf2 Fixes: #1449 Co-authored-by: Kang-Che Sung <explorer09@gmail.com>
* Read htoprc in modern location first before old oneExplorer092024-04-051-5/+2
| | | | | | | | | | Read htop configuration file in the modern location first ("~/.config/htop/htoprc") before trying the legacy location ("~/.htoprc"). This would prevent a case where configuration files exist in both locations and the new configuration gets replaced by the old one. Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
* Avoid multiplication in calloc argumentChristian Göttsche2024-04-051-1/+1
|
* Check for absolute paths in environment variablesChristian Göttsche2024-04-051-3/+3
| | | | | | Only use the environment variables HOME and XDG_CONFIG_HOME, or the home directory from getpwuid(3) if they are absolute paths. Avoid different behavior depending on the current working directory.
* Print message if config file was resolvedSefa Eyeoglu2024-03-121-7/+7
| | | | Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
* Resolve configuration pathSefa Eyeoglu2024-03-111-0/+6
| | | | | | | | Some configuration systems might link a htop configuration file and we don't really want to replace the symlink but rather its source. This will also allow us to fail in case the source is read only. Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
* Update Settings.cKen McDonell2024-02-051-1/+1
| | | Co-authored-by: BenBE <BenBE@geshi.org>
* Minor bug fixes for Coverity issuesKen McDonell2024-02-051-0/+3
| | | | | | | | | | | | | | | | | Over in the PCP project, Coverity has spotted a couple of minor issues in the htop code. This commit addresses them: Settings.c need to take control of the umask before calling mkstemp() pcp/Platform.c Although Platform_getMaxPid() returns a pid_t (which strictly speaking is signed), the value is used to call Row_setPidColumnWidth() and a negative value here is not good ... using INT_MAX instead of UNIT_MAX on the (unlikely) error path makes no practical difference but may keep Coverity quiet
* Explicitly check sscanf(3) and fscanf(3) return valuesChristian Göttsche2024-01-251-1/+1
| | | | | | | | | Compare the return value of sscanf(3) and fscanf(3) explicitly against the expected number of parsed items and avoid implicit boolean conversion. Such an implicit conversion would treat EOF (-1) the same as at least one item parsed successfully. Reported by CodeQL.
* Settings: preserve empty headerChristian Göttsche2023-12-311-5/+15
| | | | | | | | | | | | | If the user removes all meters from the header on exit htop will write no values for the settings column_meters_X and column_meter_modes_X. The parser skips all configuration settings with no value, so on the next start no header meter related key is processed and htop will add a set of default meters to the header. Write instead an invalid value of `!`, so the keys are parsed and htop will not add the default meters back. Closes: #1248
* Update includes based on IWYUBenny Baumann2023-12-261-0/+2
|
* Fix code styleBenny Baumann2023-12-261-2/+2
|
* Add includes for config.h as per the discussion in PR #1337Daniel Lange2023-12-261-0/+2
| | | | | | Many thanks to @Explorer09 Kang-Che Sung (宋岡哲). Also add a #error stanza to XUtils.h in case somebody forgets the beautiful mess GNU forces on us.
* Write configuration to temporary file firstChristian Göttsche2023-11-111-1/+11
| | | | | | | | | | | | | | | Currently when the runtime configuration is saved to file the true configuration file is first truncated and then written to with each available option. If for any reason htop dies (e.g. program crash, or system shutdown) while still performing the output the configuration file might end up empty or corrupted. Write to a temporary file and rename at the end on success. As a side effect new configuration files are now created with a mode of 0600.
* Ensure possible NULL pointer values dealt with defensivelyNathan Scott2023-09-041-2/+3
| | | | | | Coverity scanning shows a couple of locations where a NULL pointer dereference could happen; updated code to ensure it cannot.
* Support dynamic screens with 'top-most' entities beyond processesSohaib Mohamed2023-08-301-26/+81
| | | | | | | | | | | | | | | | | | | | | | This implements our concept of 'dynamic screens' in htop, with a first use-case of pcp-htop displaying things like top-filesystem and top-cgroups under new screen tabs. However the idea is more general than use in pcp-htop and we've paved the way here for us to collectively build mroe general tabular screens in core htop, as well. From the pcp-htop side of things, dynamic screens are configured using text-based configuration files that define the mapping for PCP metrics to columns (and metric instances to rows). Metrics are defined either directly (via metric names) or indirectly via PCP derived metric specifications. Value scaling and the units displayed is automatic based on PCP metric units and data types. This commit represents a collaborative effort of several months, primarily between myself, Nathan and BenBE. Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com> Signed-off-by: Nathan Scott <nathans@redhat.com>
* Introduce Row and Table classes for screens beyond top-processesNathan Scott2023-08-301-7/+7
| | | | | | | | | This commit refactors the Process and ProcessList structures such they each have a new parent - Row and Table, respectively. These new classes handle screen updates relating to anything that could be represented in tabular format, e.g. cgroups, filesystems, etc, without us having to reimplement the display logic repeatedly for each new entity.
* Refactor and consolidate dynamic meters/columns pointersNathan Scott2023-04-061-1/+2
| | | | | | | | This removes the duplication of dynamic meter/column hashtable pointers that has come in between the Settings and ProcessList structures - only one copy of these is needed. With the future planned dynamic screens feature adding another pointer, let us first clean this up before any further duplication happens.
* Add option to shadow path prefixesChristian Göttsche2023-02-031-0/+4
| | | | | | | | | Shadow path prefixes which are used by distributions, like /usr/bin/ /usr/sbin/ /bin/ /sbin/ /usr/libexec/
* Handle invalid process columns from configurationChristian Göttsche2023-01-101-6/+9
| | | | | | | Skip over invalid process columns, such that later columns are displayed fine. Replace invalid sort key identifiers with the default sort column PID.
* Reformat code baseBenny Baumann2022-10-241-1/+1
| | | | | | | | | | | | | | This includes: - Wrap function implementations - Pointer alignment for function signatures - Pointer alignment for variable declarations - Whitespace after keywords - Whitespace after comma - Whitespace around initializers - Whitespace around operators - Code indentation - Line break for single line statements - Misleading alignment
* TUI-setup for 'hide running in container' optionvaldaarhun2022-08-291-0/+4
|
* Add fallback for HOME environment variableChristian Göttsche2022-08-221-3/+5
| | | | | If the environment variable HOME is not set, try to get the home directory from the systems password database.
* Refactor code for rendering command line cacheBenny Baumann2022-05-311-0/+2
| | | | Fixes #1008
* Update Settings_newScreen with single-line sortKey checking.Nathan Scott2022-05-011-5/+1
| | | Co-authored-by: BenBE <BenBE@geshi.org>
* Remove redundant null checks on Settings_write (covscan)Nathan Scott2022-04-301-13/+11
| | | | | | | | Coverity scan reports that there is dead code in Settings_write checking for nulls that have already been dereferenced on every code path leading to the check. This is likely a hangover from times when the screens pointer was only conditionally allocated - they're not needed anymore.
* Add array bounds checking for the Process_fields array (covscan)Nathan Scott2022-04-301-1/+7
| | | | | | | Coverity scan reports there may be a code path that would cause an overrun in the (relatively new) ScreenSettings code where it evaluates default sort direction. Add bounds check and default to descending instead of a potentially invalid array access.
* Fix header layout and meters reset if a header column is emptyDaniel Lange2022-04-021-2/+9
| | | | | Closes #880 Patch from BenBE and cgzones
* Set correct default sorting directionChristian Göttsche2021-12-171-8/+8
| | | | | Respect the field option defaultSortDesc for the default screen sort direction, e.g. for CPU%.
* Do not combine default and configuration process fieldsChristian Göttsche2021-12-171-2/+4
| | | | | | | | When reading a configuration file with the syntax previous to the screens update Settings_defaultScreens() will add the default fields and later ScreenSettings_readFields() will add the ones from the configuration file. This will duplicate some fields and corrupt the columns due to the boundless Command field.
* Mark ScreenDefaults constChristian Göttsche2021-12-171-1/+1
|
* Add ScreenSettings_delete helperChristian Göttsche2021-12-081-3/+7
|
* Settings: initialize default sort key for new screenpanelChristian Göttsche2021-12-081-10/+14
| | | | | | Use C99 struct initialization, which also makes using calloc redundant. htop: Process.c:1179: int Process_compareByKey_Base(const Process *, const Process *, ProcessField): Assertion `0 && "Process_compareByKey_Base: default key reached"' failed.
* Fix memory leak on shutdown in new screen settings code.Nathan Scott2021-12-071-1/+2
| | | | | Also tidy up the calloc call parameters in the initial allocation of this pointer, thanks to @BenBE for noticing.
* Fix misc styleguide issues and add missing header filesSohaib Mohamed2021-12-071-4/+4
| | | | Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
* Enable tabs for a fresh install of htop OnlySohaib Mohamed2021-12-071-1/+1
| | | | | | | | If the new htop is configured with htoprc having no tabs (eg on upgrade) then the interface will not automatically introduce/enable them. However, for a fresh install of htop, enabling them automatically Signed-off-by: Sohaib Mohamed <sohaib.amhmd@gmail.com>
* Fixup tabs with dynamic Columns - add missing `Dynamic()`Sohaib Mohamed2021-12-071-1/+4
|
* Improvements to the tab code after initial feedbackNathan Scott2021-12-071-37/+48
|
* Introduce screen tabsHisham Muhammad2021-12-071-71/+222
| | | | This is a forward port (by nathans) of Hisham's original code.
* Validate meter configuration before proceedingBenny Baumann2021-10-061-1/+24
|
* Properly release memory on partially read configurationBenny Baumann2021-10-061-6/+14
|
* Settings: use size_t for meter count in headerChristian Göttsche2021-10-011-4/+4
| | | | | | Header.c:150:26: error: implicit conversion loses integer precision: 'int' to 'uint8_t' (aka 'unsigned char') [-Werror,-Wimplicit-int-conversion] colSettings->len = len; ~ ^~~
* Improve configuration file version diagnostic formatting slightlyNathan Scott2021-09-271-2/+3
|

© 2014-2024 Faster IT GmbH | imprint | privacy policy