summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* top: add visual clue when focus toggle ('F') is activenewlibJim Warner2022-01-172-1/+10
| | | | | | | | | | | | | | | | | | | | When in forest view mode, that focus toggle ('F') is a useful tool occasionally. But, if a focused parent has enough cloned siblings to exceed screen rows, it could be hard to remember that such a toggle remains active. So, this patch will provide a subtle visual clue added to the leftmost position in the COMMAND column. Now if the focus toggle was active, regardless of total tasks affected, the users will always know when it's active. Reference(s): . -7/24/21, introduced new focus toggle commit 3e922e671daf09ae60ee211b5c0ef94996ee573d . 09/23/21, ensure focused tasks stay focused commit 69978e365043f27305e487709474947bb377084d Signed-off-by: Jim Warner <james.warner@comcast.net>
* top: correct one source comment plus one man page oopsJim Warner2022-01-172-2/+2
| | | | Signed-off-by: Jim Warner <james.warner@comcast.net>
* top: banish one more warning for '-Wformat-truncation'Jim Warner2022-01-171-1/+1
| | | | | | | | | | | | | | | | In the commit referenced below, I fixed what I thought was all the top 'truncation' warnings. For that commit I had been using CFLAGS='-ggdb -Wall'. However, if one uses just a vanilla './configure', then a hidden extra warning will surface. This patch will finally kill it. [ thanks a bunch gcc - we love this kind of behavior ] Reference(s): . 01/08/22, original warning fix commit 44ca06f1a05b31880ca0ec4e59923a3255f5816d Signed-off-by: Jim Warner <james.warner@comcast.net>
* sysctl: eliminate a warning '-Wmisleading-indentation'Jim Warner2022-01-131-25/+25
| | | | | | | | | | [ and in the affected function, we'll also eliminate ] [ all those f**king tab characters making a hot mess ] [ of any attempt at a properly formatted C function! ] [ plus i adjusted a little non-tab misalignment too! ] Signed-off-by: Jim Warner <james.warner@comcast.net>
* top: eliminate warnings for '-Wmisleading-indentation'Jim Warner2022-01-131-1/+2
| | | | Signed-off-by: Jim Warner <james.warner@comcast.net>
* top: eliminate every warning for '-Wformat-truncation'Jim Warner2022-01-132-3/+3
| | | | Signed-off-by: Jim Warner <james.warner@comcast.net>
* library: Better PID file checks (with one small tweak)Jim Warner2022-01-131-1/+1
| | | | | | | Since gcc no longer warns of 'unreachable code', we'll just deal with any such possibility ourselves I guess. Signed-off-by: Jim Warner <james.warner@comcast.net>
* library: Better PID file checksCraig Small2022-01-081-11/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This started off with fixing the compilier warning: proc/readproc.c: In function ‘simple_nextpid’: proc/readproc.c:1373:38: warning: ‘%s’ directive output may be truncated writing up to 255 bytes into a region of size 58 [-Wformat-truncation=] 1373 | snprintf(path, PROCPATHLEN, "/proc/%s", ent->d_name); | ^~ proc/readproc.c:1373:3: note: ‘snprintf’ output between 7 and 262 bytes into a destination of size 64 1373 | snprintf(path, PROCPATHLEN, "/proc/%s", ent->d_name); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We know that ent->d_name will fit under 64 bytes because we check the name starts with a digit. The first change was simple and changed the printf to use tgid like the task function below it. Is everything under /proc that starts with a digit a directory with a PID only? Today, it is but there are no guarantees. The entire function works ok if every non-pid directory doesn't start with a number. We don't check for strtoul() having an issue nor if the for loop just falls off the end. The moment the kernel guys (or some module writer) think "/proc/12mykernelval" is a neat idea this function is in trouble. We won't get buffer overflow as we are using snprintf at least. This change now: We check if strtoul() actually came across a number Process the pid directory as a conditional branch Treat falling off the for loop as a not-found Signed-off-by: Craig Small <csmall@dropbear.xyz>
* pmap: Fix minor compiler warningCraig Small2022-01-081-1/+1
| | | | | | | | | | | | | | /usr/include/x86_64-linux-gnu/bits/error.h:40:5: warning: ‘%s’ directive argument is null [-Wformat-overflow=] 40 | __error_noreturn (__status, __errnum, __format, __va_arg_pack ()); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ pmap.c: In function ‘main’: pmap.c:760:35: note: format string is defined here 760 | xerrx(EXIT_FAILURE, "%s: '%s'", _("failed to parse argument"), optarg); A simple check for optarg being null silenced this, not sure why only this one was a problem. Signed-off-by: Craig Small <csmall@dropbear.xyz>
* misc: fixed several inconsistencies in email addressesJim Warner2022-01-0810-10/+10
| | | | | | | | [ you wouldn't believe how many back-and-forths were ] [ involved in Craig convincing me there were several ] [ inconsistencies. i am so dense sometimes (often?). ] Signed-off-by: Jim Warner <james.warner@comcast.net>
* top: Fix my email addressCraig Small2022-01-074-4/+4
| | | | Signed-off-by: Craig Small <csmall@dropbear.xyz>
* doc: updated 3 man pages for 'LIBPROC_HIDE_KERNEL' varJim Warner2022-01-073-7/+31
| | | | | | | | | | | | | | This patch was prompted by Björn Fischer's merge #147 request referenced below. And since the library change may impact all users, multiple man pages were updated. [ and thanks to Björn for initiating this extension ] Reference(s): https://gitlab.com/procps-ng/procps/-/merge_requests/147 Prototyped-by: Björn Fischer <bf@CeBiTec.Uni-Bielefeld.DE> Signed-off-by: Jim Warner <james.warner@comcast.net>
* library: add support for the 'LIBPROC_HIDE_KERNEL' varJim Warner2022-01-072-1/+15
| | | | | | | | | | | | | | This patch was prompted by Björn Fischer's merge #147 request referenced below. It has been generalized such that it now embraces both of those 'pids_fetch' types. [ and thanks to Björn for initiating this extension ] Reference(s): https://gitlab.com/procps-ng/procps/-/merge_requests/147 Prototyped-by: Björn Fischer <bf@CeBiTec.Uni-Bielefeld.DE> Signed-off-by: Jim Warner <james.warner@comcast.net>
* top: bust up that overly large 'summary_show' functionJim Warner2022-01-072-217/+243
| | | | | | | | | | | | | | | | | | | | | Over the years the summary_show function has increased from around 77 lines of code & comments to its current size of 243 lines. This is well beyond an ideal length of available screen rows. So this patch will split it. We'll take the cpu and memory duties and make separate functions out of them. Of course, this will incur some additional call overhead but, given current cpu/memory logic, any such increase really becomes insignificant. Now summary_show's a svelte 57 lines of code/comments. [ this is like what was done to that do_key function ] [ a decade ago except overhead of new function calls ] [ plus table lookup was even less of a concern since ] [ a human was involved, not normal iterative output. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
* top: provide for avoiding task focus ('F') distortionsJim Warner2022-01-072-4/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | In the patch referenced below the focus task logic was improved to ensure that newly cloned tasks 'above' the focused task did not force an effect like the up arrow key. That commit also acknowledged that when some task 'above' ended, it *would* act like the down arrow key. Well, with this commit a task ending 'above' a focused task no longer distorts the focus. That's assuming the new '#define FOCUS_HARD_Y' is specified plus the total focused tasks does not exceed the current screen rows. Thus, the manual scrolling with up and down arrow keys is allowed when the total focused exceeds screen rows. [ but keep in mind that when a focused task has been ] [ hardened some otherwise useful toggles will not be ] [ available. keystrokes like 'v' and even 'F' itself ] [ can not be applied to another task with no scroll. ] Reference(s): . Sep, 2021 - 'focus' logic improved commit 69978e365043f27305e487709474947bb377084d Signed-off-by: Jim Warner <james.warner@comcast.net>
* sysctl: eliminate a warning of '-Wmaybe-uninitialized'Jim Warner2022-01-071-1/+1
| | | | Signed-off-by: Jim Warner <james.warner@comcast.net>
* sysctl: eliminate some warnings of '-Wunused-function'Jim Warner2022-01-071-0/+4
| | | | Signed-off-by: Jim Warner <james.warner@comcast.net>
* sysctl: eliminate some warnings of '-Wunused-variable'Jim Warner2022-01-071-5/+0
| | | | Signed-off-by: Jim Warner <james.warner@comcast.net>
* library: eliminate that warning of '-Wunused-variable'Jim Warner2022-01-071-1/+1
| | | | Signed-off-by: Jim Warner <james.warner@comcast.net>
* library: eliminate warning '-Wunused-but-set-variable'Jim Warner2022-01-071-2/+1
| | | | Signed-off-by: Jim Warner <james.warner@comcast.net>
* library: eliminate those warnings for '-Wpointer-sign'Jim Warner2022-01-072-6/+6
| | | | Signed-off-by: Jim Warner <james.warner@comcast.net>
* misc: amend the man page & source file copyright datesJim Warner2022-01-0726-29/+49
| | | | | | | This just updates the copyright dates in the documents where I was already represented. Others are unchanged. Signed-off-by: Jim Warner <james.warner@comcast.net>
* nls: Update man translationsCraig Small2021-12-228-10706/+13593
| | | | | | | | | Fixed comment in Makefile.am too, thanks to Göran Uddeborg Signed-off-by: Craig Small <csmall@dropbear.xyz> References: https://www.freelists.org/post/procps/A-comment-needing-an-update
* top: make the __LINE__ usage and whitespace consistentJim Warner2021-12-201-14/+14
| | | | Signed-off-by: Jim Warner <james.warner@comcast.net>
* top: touch up that code for proc mounted as subset=pidJim Warner2021-12-201-4/+3
| | | | Signed-off-by: Jim Warner <james.warner@comcast.net>
* top: adapt for running with proc mounted as subset=pidJim Warner2021-12-173-12/+51
| | | | | | | | | | | | | | | | | | | | | | | | As the issue cited below illustrates, a pids namespace with proc mounted as subset=pid denies our library any access to non-task data. In top's case, the result was a fatal error message which involved "cpu statistics". With this patch top will now assume an error involving global cpu (stat) or memory (meminfo) data means we're running under a restricted pids namespace. As such, an attempt will be made to still display task level data. [ if our assumption is incorrect, it's of no matter. ] [ instead of a fatal error, we'll still try to offer ] [ a user some minimally useful bit of functionality. ] Reference(s): https://gitlab.com/procps-ng/procps/-/issues/227 https://www.freelists.org/post/procps/three-for-newlib,1 . 1st cut at subset=pid commit bcb837b8c73f23536a2403b61deeb2b7b3c6be20 Signed-off-by: Jim Warner <james.warner@comcast.net>
* library: reposition those 'info' structures in headersJim Warner2021-12-166-12/+12
| | | | | | | | For some unknown reason all the 'info' structures were declared between macros and function prototypes rather than right after all the other structure declarations. Signed-off-by: Jim Warner <james.warner@comcast.net>
* ps,top: convert 'PIDS_PROCESSOR' into a signed integerJim Warner2021-12-162-6/+3
| | | | | | | | Not only does that library tweak help to simplify some top code, but now that ps snprintf fmtstr will finally be accurate. That is two birdies with a single pebble! Signed-off-by: Jim Warner <james.warner@comcast.net>
* library: change 'PIDS_PROCESSOR' into a signed integerJim Warner2021-12-162-3/+3
| | | | | | | This change is really being made on behalf of the ps & top programs. Besides, over 2 billion CPUs are plenty! Signed-off-by: Jim Warner <james.warner@comcast.net>
* First cut at subset=pid proc mount handlingCraig Small2021-12-165-29/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The procfs mount option subset=pid only shows the processes, not things such as /proc/stat etc. For certain programs, this should mean they still work, but have reduced functionality. This is the first cut at some of them. pgrep - Removed always loading uptime which we never used anyway. The program now works fine unless we use --older. Add note in man page stating it will silently fail. ps - Load boot time and memory total only when required instead of always. Changed the error messages to something the user actually cares about "can't get system boot time" vs "create a structure". Works for most fields except starts and percent memory. uptime - Give more useful error messages if uptime not available. vmstat - move header generation after testing for required proc files, makes the default output more consistent with the rest of the options. References: procps-ng/procps#227 https://www.kernel.org/doc/html/latest/filesystems/proc.html#chapter-4-configuring-procfs https://github.com/torvalds/linux/commit/6814ef2d992af09451bbeda4770daa204461329e Signed-off-by: Craig Small <csmall@dropbear.xyz>
* vmstat: Use KiB instead of pages for paged in/outCraig Small2021-11-141-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | While the kernel calls the fields pgpgin and pgpgout, the units here are not pages, but KiB (or 2x 512 sectors). The comments come from the referenced merged request, this commit fixes the "vmstat -s lies" part: https://elixir.bootlin.com/linux/v5.15-rc7/source/block/blk-core.c#L1057 has submit_bio() which includes the count_vm_events(PGPGIN, count) but what is count? it is usually what bio_sectors() returns. bio_sectors() is a macro in https://elixir.bootlin.com/linux/v5.15-rc7/source/include/linux/bio.h#L49 that defines that as bio->bi_iter.bi_size >> 9. 2^9 is 512 or the sector size. So our count is incremented by the number of 512-byte sectors. As @dublio has already pointed out before this result is printed to vmstat, it is /= 2 to give the number of kibibytes (as the sectors were 512 bytes, we now made the block size 2*512 or 1024). The code even has "sectors -> kbytes". So unless there is something very strange going on, pgpgin and pgpgout in /proc/vmstat return kibibytes. What about pages (which is sort of implied in the name) or blocks (as described on the man page)? Pages can vary, but they are generally 4 KiB so they're out. That also means vmstat -s lies :( Blocks are harder to discount. While these too can vary, they can be 1 KiB; they could also be something else (e.g dd its 512, filesystems 4096). However, for memory management inside the kernel, there are sectors and there are (near userland export) KiB, nothing else. It's probably more accurate to say sectors are shifted in and out of block devices and the kernel expresses these transfers to userland as KiB by halving the numbers. What all this means is that using KiB for bi/bo aka pgpgin/pgpgout is more accurate than saying blocks or pages. Signed-off-by: Craig Small <csmall@dropbear.xyz> References: procps-ng/procps!64
* vmstat: use KiB/s for bi/bo instead of blocks/sWeiping Zhang2021-11-141-2/+2
| | | | | | | | | | | /proc/vmstat provide kbytes to pgpgin and pgpgout instead of blocks, correct unit for bi/bo. References: procps-ng/procps!64 Signed-off-by: Weiping Zhang <zhangweiping@didichuxing.com> Signed-off-by: Craig Small <csmall@dropbear.xyz>
* library: refine support for multiple concurrent accessJim Warner2021-11-145-19/+19
| | | | | | | | | | | | | | | | | | | | | | Our new library's now well protected against potential problems which arise when a multi-threaded application opens more than one context within the same API at the same time. However, with a single-threaded application designed along those same lines, some problems remain. So, to avoid potential corruption of some data (which was classified as local 'static __thread') from those single-threaded designs, we'll move several variables to the info structure itself and remove the '__thread' qualifier. Now they're protected against both designs. [ we'll not be protected against some multi-threaded ] [ application that shares a single context yet calls ] [ that interface from separate threads. this is just ] [ bad application design & no different than sharing ] [ other modifiable global data between such threads! ] Signed-off-by: Jim Warner <james.warner@comcast.net>
* library: this is why we hate those darn tab charactersJim Warner2021-11-141-1/+1
| | | | Signed-off-by: Jim Warner <james.warner@comcast.net>
* lib: Initialise uptime variablesCraig Small2021-11-021-1/+1
| | | | | | | | | | | | | | upminutes and uphours could both not get initialised in the procps_uptime_sprint_short() function. Error was probably introduced at the referenced commit. References: Coverity 240787 Uninitialized scalar variable Coverity 240776 Uninitialized scalar variable commit 0496b39876d569fe1cecb76ad5ef212cd14c0374 Signed-off-by: Craig Small <csmall@dropbear.xyz>
* pgrep: Fix format securityCraig Small2021-11-021-1/+1
| | | | | | | | | do_regcomp() error message didn't use a string literal for the format string. pgrep.c:538:24: error: format not a string literal and no format arguments [-Werror=format-security] Signed-off-by: Craig Small <csmall@dropbear.xyz>
* pmap: minor Coverity fix for -N optionCraig Small2021-11-021-1/+4
| | | | | | | | 99126 Explicit null dereferenced Not 100% sure this is valid (the same branch that sets the variable is the one that sets N_option) but not too hard to fix. Signed-off-by: Craig Small <csmall@dropbear.xyz>
* top: tweak some end-of-job logic when separate threadsJim Warner2021-10-311-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The separate threads for background updates were added to top in the commit shown below. At that time cleanup logic was added to end-of-job processing to cancel any active threads and destroy any semaphores then in use. That seemed like simple good stewardship with an added benefit of avoiding potential valgrind 'possibly lost' warnings for 320 byte blocks. Those blocks represented an initial stack allocation for each of three threads. All of that worked perfectly if such code was executed under the main thread. In other words, if the keyboard or a signal directed to any thread was used to trigger program end. However, it might not always be the case. Each of those 'refresh' routines supporting a separate thread interacts with a newlib interface. As a result, each is required to check the library's return result. Should some error be detected, 'error_exit' is called. Now we've got big problems with that eoj cleanup code. One can't 'pthread_cancel' and 'pthread_join' a thread from withing that same thread. Thus, when an error was returned by the library with threads active, top would hang with no possibility of removal short of a reboot. So, this commit only executes that cancel/join cleanup code when we are running under the main thread. Should program end be triggered by a library error under some sibling thread, all such cleanup will now be bypassed. In the latter case, we will rely on documentation that says any thread calling exit(3) will end every thread. [ now, the only time we'll see any valgrind warnings ] [ is with a library error, which is the least likely ] [ scenario for running valgrind & top to begin with. ] [ besides, if the valgrind warnings became a problem ] [ one could easily add a 'warning-suppression' file. ] Reference(s): . Sep 2021, top introduced threads commit 29f0a674a85bfb92443c56f070956a7dd60bb5f7 Signed-off-by: Jim Warner <james.warner@comcast.net>
* library: remedy several 'coverity scan' resource leaksJim Warner2021-10-281-3/+13
| | | | | | | | | | This commit will place the 'file2strvec' function on a par with the 'file2str' function if ENOMEM was raised. Plus, just to keep coverity happy, we'll also clean up after potential failures with the 'openproc' function. Signed-off-by: Jim Warner <james.warner@comcast.net>
* library: oh no, failed to right-justify 1 comment lineJim Warner2021-10-281-1/+1
| | | | Signed-off-by: Jim Warner <james.warner@comcast.net>
* pgrep: Match on cgroup v2 pathsCraig Small2021-10-263-5/+56
| | | | | | | | | | | | | | | | | | | | | | You can match or filter on cgroup paths. Currently the match is only done for version 2 cgroups because these are way simpler as they have a unified name and always start with "0::". cgroup v1 can have: named groups "1:name=myspecialname:" controllers "9:blkio:" multiple controllers! "4:cpu,cpuacct:" So they are very much more complicated from a options parsing and cgroup matching point of view. In addition, both my Debian bookworm and bullseye systems use v2 cgroups. $ ./pgrep --cgroup /system.slice/cron.service 760 Signed-off-by: Craig Small <csmall@dropbear.xyz>
* NEWS: Add entry for free -h --si fixCraig Small2021-10-261-0/+1
| | | | | | | References: commit 91e58792282d676fbcb3781d2ed48d6b082c6c56 Issues #133 #223 merge !140
* fix uid/gid > 2^31Todd Lewis2021-10-263-8/+14
| | | | | | | | | | | | | | | | This MR revisits a partial fix from 2018. The problem stems from incorrect handling of unsigned 32-bit uid_ts and gid_ts as signed when values are large - i.e. when the high bit is set. In that case, pgrep and pkill fail to identify processes by uid. (They succeed when finding the same processes by username.) The primary fix for this is to impliment the "FIXME" comment in proc/readproc.h, the implementation of which allows the removal of the (int) casts from the partial fix from 2018. The other fixed code in this MR consists of tests in strict_atol() that detects and errors out on overflows. References: Merge !146
* library: expand warnings in 'warning-suppression' fileJim Warner2021-10-251-9/+41
| | | | | | | | | | | | | | With the addition of more '__thread' attributes in the previous commit, additional valgrind warnings might be encountered if developing multi-threaded applications. So, this patch expands the libproc.supp file which was originally introduced with the patch referenced below. Reference(s): commit be1ddc275623b6cf16060d8a0fa1fb36f677010a Signed-off-by: Jim Warner <james.warner@comcast.net>
* library: extend thread safety to more static variablesJim Warner2021-10-253-5/+5
| | | | | | | | | | | | | | | In the commit referenced below, a '__thread' attribute was added to numerous static variables to protect them from concurrent access conflicts with multi-threading. Unfortunately, that patch did not go quite far enough. So, this commit adds a few more '__thread' qualifiers. Reference(s): commit 23cfb7136636f2d522b31417892de79b011ad3e4 Signed-off-by: Jim Warner <james.warner@comcast.net>
* doc: added the new valgrind 'warning-suppression' fileJim Warner2021-10-181-4/+15
| | | | Signed-off-by: Jim Warner <james.warner@comcast.net>
* library: created a valgrind 'warning-suppression' fileJim Warner2021-10-182-1/+48
| | | | Signed-off-by: Jim Warner <james.warner@comcast.net>
* top: only use 'pthread_sigmask' under separate threadsJim Warner2021-10-181-3/+17
| | | | | | | | | | | | | | | | | | When multi-threading was introduced in the patch shown below, the former calls to sigprocmask were traded for a pthread_sigmask call. This was done unconditionally. As a result, even when those threads weren't enabled a need to link with libpthread was created. In hindsight the need should only arise when top is multi-threaded. This commit will make pthread_sigmask use conditional. Reference(s): . 09/2021, separate threads introduced commit 29f0a674a85bfb92443c56f070956a7dd60bb5f7 Signed-off-by: Jim Warner <james.warner@comcast.net>
* uptime: Correctly print pretty/short formated neville2021-10-142-2/+39
| | | | | | | | | | | uptime -p would show empty output after 52 weeks of uptime. This commit is largely the work of Ed but reformatted for newlib branch. Signed-off-by: Craig Small <csmall@dropbear.xyz> References: procps-ng/procps!141 procps-ng/procps#217
* vmstat: Add NEWS and man page for previousCraig Small2021-10-142-0/+4
|