When parsing an essential pid entry file like 'status' fails, we treat
the process as a short-lived one and skip adding it into the process
table.
This should be done before the process is added, as the goto label used
for error handling can free the process structure, thus causing an
use-after-free scenario.
Fixes: 22d25db46 ("Linux: detect container process by different PID namespace")
Closes: #1455
Since \n is used internally by htop to split command lines, replace \n
with \r in command lines to not display them as space.
Merging the command string will not work, but newlines in commands
should be rather the exception.
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>
Assume the CGROUP, CCGROUP, CONTAINER and SECATTR field value may
contain non-ASCII characters and use RichString_appendWide() to convert
the strings.
Patch suggested by Christian Göttsche (@cgzones)
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
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>
All client codes that access this global `Meter_modes` array have been
replaced in previous commits, thus it's no longer necessary to keep
this internal information (draw functions, default heights, etc.)
public. It was also a bad idea when the client codes need to avoid
accessing `Meter_modes[0]` (which is reserved and contains null
information) by themselves.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Let the respective `MeterClass.updateMode` functions initialize the
meter mode instead. The `updateMode` function is always called after the
`MeterClass.init` function by `Meter_new()`.
This not only simplifies the init functions of meter subclasses, but
avoids the use of the global `Meter_modes` array when it's unnecessary.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
The use of CUSTOM_METERMODE value in meter default mode was a bad
design. There are no meter that really has a "custom" mode to work with
and currently that value serves as a useless placeholder that hides the
real default mode for a meter.
Replace CUSTOM_METERMODE in `defaultMode` of all meters with the real
intended default modes. Currently only CPU meters and MemorySwapMeter
used this, and their real defaults are BAR_METERMODE.
In Meter_setMode(), remove the special treatment of `defaultMode ==
CUSTOM_METERMODE`, Meter_setMode() still calls the `updateMode` function
for custom treatment when it's present for a meter class.
As CUSTOM_METERMODE is obsolete from `defaultMode`, the init functions
of CPU meters and MemorySwapMeter need to be adjusted to avoid
incomplete initialization (Meter.draw function bring NULL).
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
Deprecate the use of 'st' and other names. The 'sb' name is often seen
in example codes in Linux man pages. (The 'statbuf' name is sometimes
also used but I choose 'sb' name because it's shorter.)
No code changes.
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.
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>
Recently FreeBSD updated its Autoconf package to 2.72 and removed the
old Autoconf-2.71 package. This caused build error in our CI jobs.
Remove the Autoconf version number from FreeBSD and DragonFlyBSD jobs.
Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
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.
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).
While both pointers are identical, GCC-14 with -fanalyzer complains about these return statements to leak memory.
The leak is only reported with LTO though.