Commit Graph

363 Commits

Author SHA1 Message Date
Jim Warner
4e2a1ba9b1 top: stop neglecting potential utf8 field descriptions
And I thought those strange characters I saw with only
certain translations in Fields Management descriptions
were resulting from my terminal emulator deficiencies.

Turns out that ol' top wasn't addressing possibilities
of such descriptions ending with multi-byte sequences.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-10-14 21:44:56 +11:00
Jim Warner
1ba0e999c6 top: eliminate that potential vulnerability for TOCTOU
Initially, I was going to ignore that coverity warning
CID #177876. But, since top may be running SETUID it's
best if it can be avoided instead. The fix was simple.

We'll trade the access() call for a real fopen() call.
This time-of-check-time-of-use warning should go away.
------------------------------------------------------

When XDG support was originally introduced in top, the
author made a poor choice in access(). A real question
that needed asking was 'does the file exist'. However,
the question that was asked was 'can this real user ID
or this real group ID access the file'. Then, when the
fopen() is finally issued, top would use the effective
user ID or the effective group ID to access that file.

That's what opened the potential TOCTOU vulnerability,
which was important only if top was running SUID/SGID.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-10-14 21:44:56 +11:00
Jim Warner
0f5d503103 top: make 'utf8_justify' independent of non-utf8 logic
By eliminating the call to 'fmtmk', the 'utf8_justify'
function could more easily be used in libproc someday.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-10-14 21:44:56 +11:00
Jim Warner
ac76afee36 top: utf8 utils should observe indentation conventions
Gosh, all this time we used indents of 4 spaces, not 3
spaces which were always the top standard indentation.

[ and we made our 'utf8_embody' a little more robust ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-10-14 21:44:56 +11:00
Jim Warner
f762cd5660 top: make the 'utf8_proper_col' routine more efficient
This patch better exploits short-circuit evaluation in
two 'if' tests. In every case, the 1st of 2 conditions
in each 'if' test must take place but it always proves
true with each iteration for 1 of the 'if' statements.
Thus, the 2nd condition will have to be evaluated too.

By reordering 2 tests in each 'if', we can ensure that
the 2nd condition will then be tested much less often.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-10-07 09:01:55 +11:00
Jim Warner
abde5d7d5e top: make that 'make_str_utf8' function more efficient
Upon reflection, there was absolutely no justification
for that call to strlen() which was then followed by a
call to snprintf(). The latter provides this needed #.

[ also make that 'delta' value a little more visible ]
[ instead of hiding it at the end of a its code line ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-10-07 09:01:55 +11:00
Jim Warner
f6ee2c0085 top: correct an insidious occasional truncation buglet
With the help of our Swedish translator, hopefully the
final buglet has now been vanquished in the multi-byte
translation support. This one was a real nasty bugger.

Although it didn't occur with every terminal emulator,
occasionally random text lines were being chopped off.

As it turns out, those terminals were blameless. There
were two separate places in top's show_special routine
where potential multi-byte sequences were inadequately
addressed. Solution: exploit existing utf-8 functions.

[ it also became apparent that the translation hints ]
[ in the top_nls module were deficient. so a special ]
[ caution was added regarding the final line of txt. ]

Reference(s):
https://gitlab.com/procps-ng/procps/issues/68

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-10-02 22:20:58 +11:00
Jim Warner
d5a9965cde top: plug a small potential hole in multi-byte support
Unlike the insp_mkrow_raw function the insp_mkrow_utf8
routine is not equipped to print non-ctl, non-printing
characters like '<7f>'. However, technically that very
value currently slips through the cracks. So with this
patch top will now print a space in the unlikely event
a character with the value of 127 is ever encountered.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-10-02 22:20:58 +11:00
Jim Warner
cd88d4538b top: extend utf-8 multi-byte support to users & groups
Since all the necessary utf-8 plumbing is now in place
this commit will extend multi-byte support to user and
group names. Now top will be on a par with the ps guy.

[ plus, it's also my way of showing appreciation for ]
[ all those investments silently made by translators ]

Reference(s):
https://gitlab.com/procps-ng/procps/issues/68

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-10-01 22:30:16 +11:00
Jim Warner
d002bdc455 top: some minor tweaks to the utf-8 multi-byte support
Translatable column headers are supposed to be limited
to no more than 7 characters, even though some columns
are wider than that or even variable width. That value
of 7 is dictated by the Fields Management screen which
will otherwise truncate a column header longer than 7.

Our new utf-8 support did not adequately deal with the
potential need for truncation of column headers should
that limit of 7 be exceeded. This patch corrects that.

[ a few comments were also tweaked just a little bit ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-10-01 22:30:16 +11:00
Jim Warner
fad0c62076 top: extend multi-byte support to 'Inspection' feature
The previous commit implemented multi-byte support for
the basic top user interaction and display provisions.
This commit completes multi-byte support by addressing
that 'Inspect Other Output' feature (the 'Y' command).

Few people probably exploit this very powerful feature
which allows the perusing of any file or piped output.
And even if nobody uses 'Y', someone will stumble over
it on the help screen and try it out. Assuming top was
not built with INSP_OFFDEMO defined, they'll end up on
the screen our translators have faithfully translated.

Without this patch, such a screen would display with a
bunch of 'unprintable' characters which will then show
in the standard (less-like) way as: '^A', '<C3>', etc.
In other words, those poor screens will be a big mess!

[ this program can even display an executable binary ]
[ while at that same time supporting Find/Find Next. ]
[ imagine, a file with no guarantee of real strings! ]
[ just try a Find using less with such binary files. ]

With this commit, the translated 'Y' demo screens will
now be properly shown, providing no invalid multi-byte
characters have been detected. Should that be the case
then they'll be displayed in that less-like way above.

And, if users go on to fully exploit this 'Y' command,
there is a good chance that a file or pipe might yield
output in a utf-8 multi-byte form. Should that be true
such output will thus be handled appropriately by top.

[ in many respects, this change was more challenging ]
[ than the basic support within the previous commit. ]
[ story of my life: least used = most effort needed. ]

Many thanks to our procps-ng translators which enabled
a proper test of these changed 'Y' command provisions:
. Vietnamese: Trần Ngọc Quân
. Polish: Jakub Bogusz
. German: Mario Blättermann
. French: Frédéric Marchal, Stéphane Aulery

[ and my sincerest apologies too, for my negligence! ]

Reference(s):
https://gitlab.com/procps-ng/procps/issues/68

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-10-01 22:19:58 +11:00
Jim Warner
7ef38420a4 top: refactored for correct multi-byte string handling
When this project first began implementing translation
support nearly 6 years ago, we overcame many 'gettext'
obstacles and limitations.  And, of course, there were
not any actual translations at the time so our testing
was quite limited plus, in many cases, only simulated.

None of that, however, can justify or excuse the total
lack of attention to top's approach to NLS, especially
since some actual translations have existed for years.

When the issue referenced below was raised, I suffered
immediate feelings of anxiety, doubt and pending doom.
This was mostly because top strives to avoid line wrap
at all costs and that did not bode well for multi-byte
translated strings, using several bytes per character.

I was also concerned over possible performance impact,
assuming it was even possible to properly handle utf8.

But, after wrestling with the problem for several days
those initial feelings have now been replaced by guilt
over any trouble I initially caused those translators.

One can only imagine how frustrating it must have been
after the translation effort to then see top display a
misaligned column header and fields management page or
truncated screens like those of help or color mapping.
------------------------------------------------------

Ok, with that off my chest let's review these changes,
now that top properly handles UTF8 multi-byte strings.

. Performance - virtually all of this newly added cost
for multi-byte support is incurred during interactions
with the user. So, performance is not really an issue.

The one occasion when performance is impacted is found
during 'summary_show()' processing, due to an addition
of one new call to 'utf8_delta()' in 'show_special()'.

. Extra Wide Characters - I have not yet and may never
figure out a way to support languages like zh_CN where
the characters can be wider than most other languages.

. Translated User Name - at some future point we could
implement translation of user names. But as the author
of the issue acknowledged such names are non-standard.
Thus task display still incurs no new multi-byte costs
beyond those already incurred in that escape.c module.

For raising the issue I extend my sincerest thanks to:
Göran Uddeborg

Reference(s):
https://gitlab.com/procps-ng/procps/issues/68

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-10-01 22:19:58 +11:00
Jim Warner
01fb8d5a78 top: correct a minor instance of wrong NLS macro usage
The 'N_fmt' and 'N_txt' macros are interchangeable and
just highlight the 2 str types found in Norm_nlstable.

The change in this patch (strictly cosmetic) was found
during the coding for what will be the next 2 commits.
It has not been squashed into either of those so as to
not muddy up the waters for what was a major refactor.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-10-01 22:19:58 +11:00
Jim Warner
a2ceb95e2a top: protect against the anomalous 'Mem' graph display
Until this patch, top falsely assumed that there would
always be some (small) amount of physical memory after
subtracting 'used' and 'available' from the total. But
as the issue referenced below attests, a sum of 'used'
and 'available' might exceed that total memory amount.

I'm not sure if this is a problem with our calculation
of the 'used' amount, a flaw in the kernel 'available'
algorithms or some other reason I cannot even imagine.

Anyway, this patch protects against such a contingency
through the following single line addition of new code
. if (pct_used + pct_misc > 100.0 || pct_misc < 0) ...

The check for less than zero is not actually necessary
as long as the source numbers remain unsigned. However
should they ever become signed, we'll have protection.

[ Most of the changes in this commit simply separate ]
[ a variable's definition from its associated logic. ]

Reference(s):
https://gitlab.com/procps-ng/procps/issues/64

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-08-19 20:55:46 +10:00
Jan Rybar
d9c4b6b011 top: refresh interval accepts non-locale decimal value
For the past 3 years top has fully honored that locale
LC_NUMERIC setting which impacts his refresh interval.
For the past nearly 5 years top has saved that refresh
value in a locale independent form in his config file.

With this commit we'll intentionally break top so that
a comma or period will be accepted for the radix point
regardless of what that LC_NUMERIC may have suggested.

The current locale LC_NUMERIC will, however, determine
how the delay interval is displayed in the 'd' prompt.

[ This position is better than the approach employed ]
[ by those coreutils 'sleep' and 'timeout' programs. ]
[ Both claim to permit floating point arguments. But ]
[ neither one will accept the comma separator should ]
[ the locale be a country that in fact uses a comma. ]

Reference(s):
https://gitlab.com/procps-ng/procps/merge_requests/50

Prototyped by: Jan Rybar <jrybar@redhat.com>
Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-08-14 22:13:28 +10:00
Jim Warner
ac76e4db2c top: fixing command line parsing errors is now a habit
Ok, I admit it. I'm now tired of cleaning up after me.

This is the 3rd related tweak after that '-1' argument
was originally introduced. And with this patch we will
once again properly honor the '-o' and '-u|U' switches
without a need to be followed by an additional switch.

[ one can follow my unfortunate trail of alterations ]
[ beginning with my most recent fix referenced below ]

Reference(s):
commit 4b44aebd80

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-07-04 20:29:26 +10:00
Jim Warner
0998225651 top: ensure necessary proc_t support if '-U' filtering
While the effective user id would always be present in
each proc_t, thus supporting 'u' filtering, other user
ids would only be present if /proc/$$/status was read.

This commit just puts the 'master' branch top on a par
with the 'newlib' branch when user filtering with 'U'.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-07-04 20:29:25 +10:00
Jim Warner
4b44aebd80 top: correct functioning of the '-p' command line args
With the introduction of a new '1' command line toggle
I have gone and broken a provision of the '-p' command
line switch (pids monitoring). Multiple pids could not
be specified through the use of comma delimited lists.

Thus, this commit simply corrects that newly added bug
which was born in the 'adjustment' commit shown below.

Reference(s):
. adjustment to '-1' implementation
commit 909b37d755

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-06-04 21:28:39 +10:00
Jim Warner
c409f5a433 top: address the argument parsing quirk involving '-h'
There exists the possibility that a 'putp' call can be
issued before the 'setupterm' invocation has occurred,
as is reflected in a bugzilla report referenced below.

Strangely, such a SEGV isn't always triggered as logic
would suggest it ought to be. I experienced a fault in
these environments with the associated curses version:
. archlinux, procps-ng 3.3.12, ncurses 6.0.20170429
. fedora-25, procps-ng 3.3.10, ncurses 6.0.20160709
. opensuse-42.2, procps-ng 3.3.9, ncurses 5.9.20140201
. gentoo, procps-ng 3.3.12, ncurses 6.0.20150808
. slackw-14.2, procps-ng 3.3.12, ncurses 6.0.20160910

Whereas under these environments there was no problem:
. ubuntu-17.04, procps-ng 3.3.12, ncurses 6.0.20160625
. debian-test, procps-ng 3.3.12, ncurses 6.0.20161126
. mageia-5.1, procps-ng 3.3.9, ncurses 5.9.20140323

[ as an aside, the expected result in the bug report ]
[ is incorrect and should mention the '1' parameter. ]

[ however, until release 3.3.13 when the '1' becomes ]
[ a valid switch, numbers are not detected when used ]
[ with any switch which doesn't require an argument. ]

[ you're welcome to treat that as a separate bugglet ]

Reference(s):
https://bugzilla.redhat.com/show_bug.cgi?id=1450429

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-05-22 21:34:38 +10:00
Jim Warner
1422c219ac top: now includes that NUMA node field display support
[ this patch has been adapted from the newlib branch ]

Reference(s):
https://gitlab.com/procps-ng/procps/issues/58

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-05-22 21:34:32 +10:00
Jim Warner
56d79b9d13 top: provide more accurate cpu usage stats for startup
The top program already incorporated a modest delay at
startup so that some minimal process cpu history could
be established. However, Summary Area system level cpu
statistic history reflected usage since boot. As such,
unchanging % values would be shown with every restart.

This commit just adopts the same approach used in task
%CPU history for the Summary Area statistics. In other
words, it introduces a 'priming read' at startup as is
found in the newlib implementation for the <stat> API.

Reference(s):
https://gitlab.com/procps-ng/procps/merge_requests/42

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-03-29 22:07:44 +11:00
Jim Warner
909b37d755 top: make command line switch parsing even more robust
This program has always tried to maintain an extermely
robust command line parsing procedure, far more robust
that what's available with the getopt stuff. But, with
the introduction of our first numeric switch it should
have been made even more robust than, in fact, it was.

This commit will now accomplish such a desirable goal.

Reference(s):
. added '1' command line switch
commit 89db82d143

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-03-29 22:07:44 +11:00
Jim Warner
90ac0dabf5 top: just update all of the copyright dates in sources
Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-03-16 21:59:53 +11:00
Jim Warner
89db82d143 top: provide -1 command line switch as 'Cpu(s)' toggle
If built without ./configure --disable-modern-top, the
program displays each cpu individually providing there
is sufficient vertical screen real estate. For massive
SMP environments this will necessitate use of a config
file where the cpu summary toggle ('1') could be saved
via the 'W' command. But, an rcfile may not be viable.

So this commit introduces a '1' command line switch to
emulate exactly the effects of the interactive toggle.

And since it is our first numeric switch some existing
parsing logic had to be changed slightly. Such changes
are, in truth, an improvement. For example, instead of
seeing "inappropriate '2'" with ./top -2 we'll now see
the vastly more appropriate error "unknown option '2'.

References(s):
https://gitlab.com/procps-ng/procps/issues/55

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-03-16 21:59:53 +11:00
Jim Warner
fb48b5d9fb top: provide -E command line switch for memory scaling
In their 3.2.7 version of top, Redhat introduced an -M
switch to automatically scale Summary Area memory data
to avoid truncation (and the resulting '+' indicator).

The procps-ng top does not employ suffixes with memory
data nor does it allow for different scaling with each
separate value. Rather, scaling appears at line start.

If built without ./configure --disable-modern-top, the
Summary Area memory will be scaled at GiB which should
lessen chance of truncation. Otherwise KiB was used to
reflect such memory, increasing the truncation chance.

And while 'W' can be used to preserve some appropriate
scaling value, there are arguments against such rcfile
approaches as cited in the issue and bug report below.

So this commit will bump the Summary Area memory scale
factor from KiB to MiB when using --disable-modern-top
as a concession to that Redhat bug report noted below.

And it also introduces a new command line switch which
can force any desired scaling regardless of the rcfile
or which ./configure option might have been specified.

[ for top's help text we'll show 'E' as if it were a ]
[ switch without arguments in order to keep the help ]
[ text displayable without wrap in an 80x24 terminal ]

[ the man page, however, will show all k-e arguments ]

Reference(s):
https://gitlab.com/procps-ng/procps/issues/53
https://bugzilla.redhat.com/show_bug.cgi?id=1034466

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-03-16 21:59:53 +11:00
Jim Warner
fe6e03d8a9 top: show fewer decimal places for memory (by default)
After much reflection I've come to the conclusion that
displaying 3 decimal places (usually) when memory data
had been scaled is no longer optimal with today's ever
increasing amounts. And given that not all task memory
fields are the same widths, inconsistencies can easily
arise as illustrated and discussed in the issue below.

Instead of unilaterally reducing the number of decimal
places, this commit will sneak in such a change via an
existing configure option that was very likely unused.

The former 'disable-wide-memory' option has now become
'enable-wide-memory', which can be used if the current
behavior (3 decimal places) is preferred. Without that
option, whenever memory is scaled beyond KiB, just one
decimal place will be shown in Summary and Task areas.

And Task area field width will no longer be changed by
this revised configure option. Instead, all such field
widths will now be fixed at the former maximum values.

Reference(s):
https://gitlab.com/procps-ng/procps/issues/50

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-03-16 21:59:53 +11:00
Earnestly
af53e170b9 top: Add unobtrusive XDG support
By default the file HOME/.toprc will be prefered.  This ensures there
should be minimal breakage even if this file is later created by some
other means.  Otherwise we will follow the new behaviour described by
the XDG Base Directory Specification:

If the XDG_CONFIG_HOME environment variable is available we will attempt
to use this as XDG_CONFIG_HOME/procps/toprc otherwise we will fall-back
to HOME/.config/procps/toprc instead.

Signed-off-by: Earnestly <zibeon@gmail.com>
2017-01-17 23:47:40 +00:00
Jim Warner
398b83f40f top: make for consistent & enhanced cpu % calculations
That issue cited below prompted some changes under the
newlib branch to standardize the calculation involving
busy, idle, user & system accumulated plus delta tics.

This patch will bring our master branch version of top
into agreement with that newlib version which exploits
some of those newly added library extended provisions.

Reference(s):
https://gitlab.com/procps-ng/procps/issues/48

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-01-04 08:14:42 +11:00
Jim Warner
5c78e785ee top: accumulated misc tweaks to code/comments/man page
Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-12-07 21:50:52 +11:00
Jim Warner
c6407ef125 top: make that 'forest view' just a tad more efficient
It makes no sense to begin our tracked nested level at
'1' then later require a '1' to be subtracted from the
level as artwork and indentation is added for display.

By beginning such tracked levels at zero, we can avoid
the need to adjust it & use it directly in a snprintf.

[ this commit parallels a patch in our newlib branch ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-10-16 08:18:31 +11:00
Jim Warner
18b1a887b7 top: finally circumvent that minor libnuma memory leak
Still unhappy with a minor memory leak associated with
libnuma, I experimented with omitting the dlclose that
was issued at module's end. For some reason which will
remain a mystery, the valgrind leak then went bye-bye.

So this patch just omits one use of dlclose and relies
on whatever kernel magic is at work to free the memory
when each process ends. We kept, however, the original
code (now commented-out) to serve as a future caution.

There remains one potential (but unlikely) dlclose use
near the original dlopen. But there will be no leak as
that 'numa_node_of_cpu' will not yet have been called.
This seems to be the culprit that triggers such leaks.

None of this libnuma shit would likely have come close
to hitting our fan had the numa developers provided us
with 'new' and 'unref' functions like our newlib does.

[ this commit parallels a patch in our newlib branch ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-09-18 20:39:12 +10:00
Jim Warner
5313852596 top: avoid yet more overhead of accessing /proc/status
After discovering those terrible costs associated with
/proc/status vs. /proc/stat, the build_header function
changed to favor the latter for a field found in both.

Well, low-and-behold, this top program still used some
flags that needlessly caused 'status' to still be read
when 'statm' could have served. And, while top's needs
require conversion from pages to KiB, that's still far
less costly than reading that gosh darn 'status' file.

[ this patch parallels similar changes to newlib top ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-08-23 21:12:32 +10:00
Jim Warner
7df87ea7cf top: when setting library flags favor stat over status
Long ago, in a galaxy far away, top was convinced that
/proc/stat was to be favored over /proc/status if some
field could be satisfied with either. This was done to
avoid extra costs of 64-bit math for 32-bit platforms.

Well, its time to acknowledge the prevalence of 64-bit
platforms. And in such an environment there is a large
hidden cost currently if using status instead of stat.
In fact, that cost difference can be as high as 1400%.

So, this commit will coax top into favoring that least
costly route while also fixing an EU_TGD library flag.

[ this patch parallels similar changes to newlib top ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-08-23 21:12:32 +10:00
Jim Warner
b4fdb27a05 top: provide for expanded potential displayable fields
This commit provides for raising the total displayable
fields from its current 70 to 86. It also bumps the id
in an rcfile representing the version from 'i' to 'j'.

The increase in number of fields will make sharing the
rcfile with an older top, once it's saved, impossible.

These changes are being done via a #define rather than
hard coded so any such sharing will still be possible.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-08-01 20:11:11 +10:00
Jim Warner
63f8c16fa4 top: make compilation possible under netbsd-curses too
Whoa, I had never considered an alternative to ncurses
until the issue referenced below was raised. Thus, I'm
surprised to find that 'tparm' was the only impediment
to ultimately utilizing this alternate curses library.

And, while we could have substituted that non-standard
'tiparm' with only 2 arguments, we'll utilize the full
parms compliment in the spirit of that original patch.

Frankly, the task of developing an alternative library
to that ncurses implementation really boggles my mind.

Congratulations to rofl0r, whoever that masked man is.

Reference(s):
. issue raised
https://gitlab.com/procps-ng/procps/issues/38
. netbsd-curses home
https://github.com/sabotage-linux/netbsd-curses

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-07-17 08:52:50 +10:00
Jim Warner
eca9168617 misc: adapted others to that new proc_t 'cgname' field
This patch adapts the ps program to a newly add proc_t
field and provides for new support in that top program
along with his man document (ps was already ok there).

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-07-06 21:33:17 +10:00
Jim Warner
5e33325f9a top: improved that #define PRETENDNOCAP implementation
This development (only) define can be used to turn top
into a simple text program, disabling termcap effects.
But input (at screen bottom) suffers from a line wrap.

So, this commit just makes the input prompt processing
a little more effective by adding one leading newline.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-07-06 21:33:17 +10:00
Jim Warner
29079d35e5 top: accommodate the loss of that OOMEM_ENABLE #define
Now that the conditional OOMEM_ENABLE has been removed
and all users exposed to those 'out of memory' fields,
it's about time we added them to the top man document.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-06-07 20:49:30 +10:00
Jim Warner
10503c03d4 top: make more responsive when toggling cpu off/online
Using the <STAT> api under the newlib branch, that top
program is very responsive to changes in the number of
on-line cpus. However under the master branch this top
program is very responsive only to losses of some cpu.

When a cpu is brought back on-line potential delays of
60 seconds could be encountered. That delay was simply
an attempt to reduce costs and reflected the erroneous
assumption that adding a cpu required physical effort.

So without redesigning the cpu refresh code to emulate
that of newlib, this commit just reduces the potential
delay to 3 seconds (the same that is used for memory).

[ As an aside, if one wants to have their confidence ]
[ in that htop program badly shaken, try taking some ]
[ cpus off-line & on-line again while it is running. ]

[ Poor ol' htop just continues to report results for ]
[ whatever were the cpus when started. Nice feature, ]
[ but I wonder where those phantom results are from. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-06-07 20:49:30 +10:00
Jim Warner
ac8f49e79e top: miscellaneous accumulated tweaks of code/comments
This commit just tries to parallel that newlib branch.
It contains the following changes, which were prompted
by the newlib coverity analysis which Craig initiated:

. comment typo predicting 'String not null terminated'
. eliminate 'Logically dead code' from insp_make_row()

Some tweaks, unrelated to coverity, are also included:

. use more modern (recommended) approach for time call

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-06-07 20:49:30 +10:00
Jim Warner
5e26512980 top: extend 'zero suppression' scope to several fields
This commit just tries to parallel the implementations
in the newlib branch. The config file Rc.zero_suppress
will be extended to include both out-of-memory fields.

And while we're at it, we'll also extend zero suppress
to that NI (nice value) field, which already should've
had it. Plus we trade those namespaces custom suppress
logic for our now slightly enhanced make_num function.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-06-07 20:49:30 +10:00
Jim Warner
6306050a65 top: exploit new linux-4.5 resident memory enhancement
Since support already exists in the newlib branch this
represents an equivalent master branch implementation,
and this commit message is shared with 2 more patches.

Beginning with linux-4.5, the following new fields are
being added under that /proc/<pid>/status pseudo file:
 . RssAnon - size of resident anonymous memory
 . RssFile - size of resident file mappings
 . RssShmem - size of resident shared memory

p.s. Locked resident memory support was also added but
isn't directly related to the kernel 4.5 enhancements.

p.p.s. Archlinux, Debian-stretch and Fedora-23 already
are currently using a 4.5 linux kernel (as of 6/2/16).

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-06-07 20:49:30 +10:00
Jim Warner
717d73f1dd top: tweaks to vertical scroll management & 'i' toggle
The commit referenced below claims to disable vertical
scrolling when idle tasks weren't being shown. However
it really addresses only a point in time when that 'i'
toggle is keyed. Left untouched were the up/down keys.

So this commit will simply finish the job of disabling
vertical scrolling whenever tasks which have used some
CPU are the only ones which are currently being shown.

Reference(s):
commit c07f6c5e6d

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-03-12 14:50:57 +11:00
Craig Small
da715e3ca0 Replace %Lu with standard %llu
Multiple scanf()s use the GNU-permitted %Lu. This is not supported in
other libraries and isn't to the POSIX specification. The L modifier
is only used for floats in POSIX.

Replacing %Lu with %llu is the same for GNU libc (scanf(3) says as much)
but means other libraries will work fine.

Closes: #19

References:
 http://pubs.opengroup.org/onlinepubs/009695399/functions/fscanf.html
2016-03-03 21:43:52 +11:00
Jim Warner
94e4749be3 top: extend '=' key to include active 'locate' request
It is documented behavior that when certain other keys
are active, sorts column highlighting will temporarily
be disabled. Among those keys is the 'L' (locate/find)
provision. The equals ('=') key can be used to restore
column highlighting by resetting other keys, except 1.

When a locate/find is active, the '=' key will have no
effect on 'x' column highlighting, which still remains
disabled. Further, when 'L' is active an 'x' keystroke
is processed changing the state of column highlighting
but without any visual clue (since it's yet disabled).

So this commit just extends the '=' key to embrace 'L'
processing resets, just like other highlight disabling
keys while avoiding 'x' state changes if approproiate.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-28 21:01:49 +11:00
Jim Warner
489d23a132 top: ATEOJ_RPTHSH prints hash table entries less often
We'll following the newlib <pids> approach to hashing:

. a 'PIDs at max depth:' portion of that UNREF_RPTHASH
enabled #define is now published only when the maximum
depth of hash table entry chains exceed depths of one.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-28 21:01:28 +11:00
Jim Warner
e1cd74eec9 top: do not co-mingle strings/numbers under namespaces
Craig's recent commit under that newlib branch dealing
with namespace support has prompted me to review top's
handling of those fields. Currently, when such a field
is zero, top displays a dash ('-'). This will mean the
justification toggles ('j/J') will behave incorrectly.

This patch simply allows the potential zero to display
or be suppressed with the already existing '0' toggle.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-28 21:01:23 +11:00
Jim Warner
c7201d52eb top: miscellaneous accumulated tweaks to code/comments
A patch containing the following miscellaneous tweaks:

. remove a function that handled former library errors
[ that function should have gone bye-bye with 3.3.11 ]
[ when those 'wchan' provisions were much simplified ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-28 21:01:16 +11:00
Jim Warner
3da298c1d6 top: fix unlikely edge case wherein all fields are off
While testing a newlib interface for pids acquisitions
I encountered some unexpected results if an idiot user
(me) turns off all displayable fields. So, this commit
ensures that the PID field will be shown as a minimum.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-08-06 21:56:27 +10:00
Jim Warner
8226ca9838 top: avoid an unnecessary conversion for 'USED' column
When the USED column was introduced the proc_t.vm_swap
& proc_t.resident values were added together. However,
using 'resident' required an additional PROC_FILL flag
not to mention extra conversion of pages to kibibytes.

So now we'll use an already present vm_rss value which
removes any special handling for top's derived column.

And while we're at it we'll trade some more 'resident'
field uses with that more immediately usable 'vm_rss'.

Reference(s):
commit 709785e20b

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-08-06 21:56:02 +10:00
Jim Warner
9ba65bad8e top: miscellaneous accumulated tweaks to code/comments
Jeeze, to correct spelling on one single word (incure)
you had to go and align the entire comments paragraph?

[ well, at least there's one other minor code change ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-08-06 21:52:11 +10:00
Jim Warner
9cc6ed10c8 top: eliminate 'user' from the inspection view headers
Since it's possible that euser name is not being shown
or the horizontal position had been scrolled past that
USER column, then part of those headers will be blank.

So it doesn't make sense to try and show the USER that
is associated with a process at all. Thus, this commit
simply removes the 'user' provision from both headers.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-08-06 21:50:49 +10:00
Jim Warner
c07f6c5e6d top: improve vertical scroll management for 'i' toggle
When a user is taking advantage of the scroll features
it is likely a scrolled vertical position is well past
the first displayable task. That is especially true of
top's forest view ('V') mode where those early systemd
attached processes are generally not very interesting.

As such, should the idle mode toggle ('i') be employed
a distorted display is almost guaranteed because tasks
that have used some cpu, and thus should be displayed,
have already been skipped by virtue of their position.

So this patch temporarily nullifies vertical scrolling
during the period when idle tasks are not being shown.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-07-21 21:23:44 +10:00
Jim Warner
88fe45ef68 top: sacrifice a redundant procps_linux_version() call
With the commit referenced below, the linux version is
no longer available via an external variable. So we'll
eliminate the extra superficial function call employed
at program end as part of a debugging (only) o/p spew.

[ the user will soon be returned to the command line ]
[ & he/she can run their own 'uname -r' if in doubt! ]

Reference(s):
commit 56d9d5e7e7

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-06-21 08:05:59 +10:00
Craig Small
56d9d5e7e7 library: Change linux version
Added function procps_linux_version() which used to be an
exported integer instead.  Also changed the method of obtaining
the linux version (more correctly the os release) to use a specific
procfs entry. This works for both Linux and FreeBSD.
2015-06-19 21:00:46 +10:00
Jim Warner
93666da62c top: adapt to a simplified library interface for wchan
This patch was made necessary by those library changes
in support of recently revised/simplified wchan logic.

Reference(s):
http://www.freelists.org/post/procps/WCHAN,11

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-06-19 19:09:20 +10:00
Craig Small
505f257a8c library: remove procps_version functions
It doesn't make any sense to have the binary version strings
embedded into the library. The version strings are defined
already either in the Makefile or in include/c.h
2015-06-18 22:37:24 +10:00
Jim Warner
2ba7aa8b7d top: add support exploiting new library LXC containers
Reference(s):
https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1424253
https://bugs.launchpad.net/ubuntu/+source/procps/+bug/1424253

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-06-14 15:36:06 +10:00
Jim Warner
e107f5d63b top: miscellaneous accumulated changes to program code
This commit just tweaks top in the following respects:

. for alphabetic integrity, change 'INSP_hdr...' names

. eliminate the -Wsometimes-uninitialized warning that
was found under OSX Yosemite (llvm 6.0/clang-600.0.56)

. update program 'comments' reflecting copyright dates

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-04-07 20:46:15 +10:00
Jim Warner
da06b8fa59 top: tweak forest view protections for forking anomaly
A recent commit eliminated the potential for a storage
violation with forest view mode. It occurred when some
program (erroneously?) created a lengthy forking loop.
However, the associated commit message was misleading.

The message implied that an unexpected order following
a sort on start_time was the cause of storage overruns
and a 'char' used to track nesting level only distorts
the display when it goes negative. Actually, the truth
is really just the opposite. Any start_time sort quirk
causes no harm while that 'char' can yield corruption.

Should some child end up sorted ahead of its parent by
way of an extremely unlikely shared start_time the end
result is such a child will be displayed unnested just
like init or kthreadd along with all its own children.

However, if nesting levels exceeded 255 (and became 0)
a massive array overrun could be triggered when such a
task and *all* its children were added to an array for
the second time. Exactly how much storage was violated
depended on the number of children that zeroed process
had spawned (hinted at via either SIGSEGV or SIGABRT).

The earlier commit limited nested levels to 100 so the
root cause of the storage violation was already fixed.
The potential for distorted nesting levels due to sort
on start_time would seem to remain. But it's extremely
unlikely that 2 tasks would share the same start_time.

Even so, a new #define has been introduced which makes
top impervious to the order of tasks such that a qsort
is no longer necessary (providing an init/systemd task
exists & was harvested as the first task by readproc).
It can be utilized if distorted nesting ever becomes a
real issue. But since there is a 5-10% performance hit
with that, we'll continue using start_time as default.

References(s):
commit ce70017eb1

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-10-29 17:00:03 +01:00
Jim Warner
ce70017eb1 top: provide some protection against forking anomalies
This commit will eliminate a very nasty bug associated
with top's forest view mode.  It addresses a potential
SIGSEGV/SIGABRT that was only encountered when another
program (erroneously?) creates a lengthy forking loop.

If the growing list of nested children is sufficiently
fast such that proc_t start_time is duplicated between
children then the sort upon which top relies might not
produce the expected order. That, in turn, could cause
the forest_adds function to initially miss some child.

But that missed child would be caught by forest_create
and eventually would cause our array boundary overrun.
Such overrun occurs when some child of that originally
*missed* child is found and a duplicate add attempted.

In correcting this bug we'll also use this opportunity
to prohibit a borrowed proc_t padding byte (char) from
going negative. If the nesting level exceeded 127, the
effect was an "unnesting" with the snprintf width then
viewed as flag+width also yielding left justification.

Henceforth, we'll limit nesting to 100 with subsequent
children shown as " +  ", not the usual " `- " prefix.

References(s):
https://bugzilla.redhat.com/show_bug.cgi?id=1153642
http://www.freelists.org/post/procps/Bug-in-the-forrest-view,6

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-10-27 17:18:47 +01:00
Jim Warner
b0767bd391 top: ensure previously saved rcfile honored completely
When startup defaults were changed users with existing
rcfiles would likely find their previous configuration
was not being honored in all respects. The disparities
involved Graphs modes and Summary/Task memory scaling.

This patch simply restores what was always intended as
the proper behavior for previously saved config files.

References(s):
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=762928
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=762947
. new startup defaults
commit 8ef6cd91fc

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-09-29 08:22:13 +10:00
Jim Warner
8adf4acc03 top: final tweak to recent changes for new graph modes
Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-08-11 16:39:51 +02:00
Jim Warner
e92b692932 top: swat a potential buglet affecting new graph modes
This patch will cure a potential aberration associated
with a terminal's size (SIGWINCH) and top's new graphs
modes. The symptoms were a dangling tilde (~) plus the
potential loss of a graph's right-most visual content.

The condition was only apparent when a %Cpu approached
100% usage. Also the apparent loss of content affected
the 'block' graph only. With 'bar' graphs, that affect
became the loss of proper right-most bar graph colors.

The cause was determined to be a combination of: 1) an
unnecessary snprintf precision specification; and 2) a
rounding quirk for any graphs which displayed distinct
types of information (as for user/syst, used/unavail).
These could then combine to produce an extra bar/block
which, in turn, resulted in the truncation of a pseudo
termcap attribute used by the show_special() function.

What was originally interpreted as an intractable race
condition turns out to be just a self inflicted wound.

Reference(s):
http://www.freelists.org/post/procps/top-Possible-bug-in-the-graphs,1

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-08-08 22:14:21 +02:00
Fredrik Fornwall
dfe1f7d104 top: replace <values.h> with <limits.h> plus <float.h>
This fixes a compilation problem on Android which lacks values.h.

Reference(s):
https://gitorious.org/procps/procps/merge_requests/26

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-08-08 22:14:21 +02:00
Jim Warner
5380ef9022 top: adapt global memory support to new library format
Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-31 15:10:42 +02:00
Jaromir Capik
cbba7ad7a7 top: exclude reclaimable slabs from used 2014-07-22 14:07:45 +02:00
Jim Warner
d310a18fc2 top: exploit new kb_main_available, make Jaromir happy
This patch will trade a former pessimistic calculation
of free physical memory for a more optimistic one that
uses the newly added kb_main_available library export.

But in case one might wish to return to the old former
method, there's a new #define that was made available.

[ the new calculation will affect graphing mode only ]

Reference(s):
http://www.freelists.org/post/procps/systemd-support-to-library,9

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-18 20:49:57 +02:00
Jim Warner
9500dc198c top: trade Page_size for that newly exposed page_bytes
Might as well use the newly exposed sysinfo.h variable
'page_bytes' rather than our own. Plus, in the process
we can avoid incurring yet one more function call hit.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-18 20:49:57 +02:00
Jim Warner
6cd8691720 top: fix potential 'nan', should a system have no Swap
Gosh, just because most of us might run with some swap
file allocated, not every system might. I only wish my
testing methodology was as sophisticated as Jaromir's.

Reference(s):
http://www.freelists.org/post/procps/latest-top-enhancements,7

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-07 18:43:52 +02:00
Jim Warner
c75586f523 top: eliminated unreferenced macros & an error message
Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-07 18:43:52 +02:00
Jim Warner
2199af404a top: maximize recent locale aware numeric enhancements
When startup argument parsing was recently enhanced to
account for LC_NUMERIC settings, some user input logic
dealing with numbers fails to exploit that capability.

This patch extends such enhancements to a running top.

Reference(s):
commit f7b84f45c7
http://www.freelists.org/post/procps/topwatch-floating-point-input,2

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-01 21:30:45 +10:00
Jim Warner
96c330e3b3 top: afford each window its own cpu/memory graph modes
When those new cpu/memory graphs modes were introduced
they had global impact. In other words, the modes that
were chosen for a 'current' window affect Summary Area
appearance for every other window as well, even though
each window sets unique View_STATES/View_MEMORY flags.

I do not know how widespread the use of top's separate
window provisions is, but I do know that documentation
promises every window (field group) provides "a unique
separately configurable summary area". And even though
that promise does not include memory scaling (separate
'E' command) the graph modes are integral to 't' & 'm'
and those were already observed on a per window basis.

So this patch just takes the cpu and memory graph mode
values out of global scope in the configuration file &
gives each window its own unique pair of graph values.

Reference(s):
commit 1d171ec741

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-06-28 23:46:40 +10:00
Jim Warner
f7b84f45c7 top: tweak argument parsing for some locale situations
Boy I hate locale stuff. For code I thought was pretty
robust, Jaromir sure proved that it wasn't. Anyway, me
thinks this commit closes some gaps and will cause top
to behave appropriately under various locale settings.

It does *not* permit top to respond to the ',' and '.'
floating point separator without regard to the locale.
It does, however, enforce proper LC_NUMERIC responses.

Let's look on this commit as an interim solution until
Jaromir can create that proposed 'fp_decode' function.
Who knows, he might even borrow some of our mkfloat().

[ An aside: the coreutils sleep and timeout programs ]
[ claim to permit floating point arguments. However, ]
[ neither one will accept the comma separator should ]
[ the locale be a country that in fact uses a comma. ]

[ In other words, with this commit we are way ahead! ]

Reference(s):
http://www.freelists.org/post/procps/topwatch-floating-point-input
http://www.freelists.org/post/procps/topwatch-floating-point-input,1

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-06-25 13:58:31 +02:00
Jim Warner
cec1976511 top: let's not pretend top can catch SIGKILL & SIGSTOP
While there was no harm done setting a handler for the
above two signals, they are in fact uncatchable. Thus,
whenever we ran with valgrind we're politely reminded.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-06-25 13:58:30 +02:00
Jim Warner
db6381ae04 top: scale length for new graphs to a terminal's width
When the beginning of the Mem/Swap graphs was variable
scaling them to the current terminal's width was a bit
of a costly nightmare. So the graph size was fixed and
subject to truncation. However now that the start of a
graph can be easily predicted, I've revisited scaling.

As it turns out, any cost is minimal & mostly incurred
at an opportune time, at SIGWINCH or user interaction.
Plus, most of the apparent arithmetic is actually just
a means of documenting and will disappear thru compile
time constants in the ultimate generated machine code.

Note: those graphs will now behave just like any other
Summary Area element - they will scale from full sized
down to a terminal width of 80 columns, at which point
those displayed graphs are then subject to truncation.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-06-24 20:38:30 +10:00
Jim Warner
41ab7f005e top: with new bar graphs, make 'b' toggle unrestricted
While the 'b' toggle remains window based (vs. global)
it should no longer require that the window be visible
and either the 'x' or 'y' toggles to be on. Previously
those requirements were intended to remind a user that
there must be something for this command to highlight.

With the introduction of graph modes (specifically the
the bar graph) the 'bold/reverse' toggle has important
implications beyond highlighting some columns or rows.

The %Cpu(s) graph and Mem portion of the memory graphs
are designed to offer a visual clue as to the separate
elements comprising them. But that separation could be
lost under some X color schemes or when top is running
without color (in monochrome mode) and the block graph
is selected. But, if the graph is then changed to bars
any separation always becomes visible whenever the 'b'
toggle is turned off. Portions then show in 'reverse'.

So from now on we'll check nothing, we'll just toggle.

[ Besides, with all the code thrown at restricting a ]
[ 'b' toggle use, it might have all been for naught. ]
[ That toggle could still be set/unset using the 'Z' ]
[ command and the color mapping screen. Geez Louise! ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-06-24 20:38:30 +10:00
Jim Warner
b8614adcb5 top: make '#define GRAPHS_ALIGN' an immutable solution
My original graph modes implementation made no attempt
to align the Cpu & Mem/Swap graphs. I thought, rather,
that such alignment could be best achieved by the user
using top's 'E' memory scaling command toggle. In that
way Mem/Swap prefixes could be reduced by 3 positions,
bringing the beginning '[' into line with the %Cpu(s).

If that proved to be too cumbersome a #define could be
enabled making the Mem/Swap prefix static while adding
a few padding bytes to the %Cpu line(s) for alignment.
It was those waisted bytes that were the most concern.

What I had not counted on was the fact that the memory
lines themselves might become misaligned & that became
likely with more physical memory present. That too can
be cured with the 'E' command but as scaling is raised
we soon reach a meaningless total such as '0.003' even
though the displayed % remains valid (and unchanging).

So this commit implements unconditionally what used to
be conditional. But, instead of waisting padding bytes
we'll put that space to good use with a new 'total %'.

Reference(s):
http://www.freelists.org/post/procps/latest-top-enhancements,1
commit 1d171ec741

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-06-24 20:35:20 +10:00
Jim Warner
f33d49c6cf top: shorten some lines by changing a few declarations
My first blush graphs modes implementation went just a
tad overboard on identifier lengths. As a result, some
program lines were getting quite long. So, this commit
will simply shorten some excessively long identifiers.

Reference(s):
http://www.freelists.org/post/procps/latest-top-enhancements
commit 1d171ec741

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-06-24 20:35:20 +10:00
Jim Warner
1d171ec741 top: add graphs modes for cpu and memory, program code
This patch makes 't' (View_STATES) & 'm' (View_MEMORY)
commands into 4-way toggles. The two new modes provide
for two different graphs of the cpu and/or memory use.

These new capabilities are similar to those offered by
the 'htop' program. However they're aesthetically more
pleasing (to me) plus the scalings are more authentic.

Poor ol' top has long been troubled by the comparisons
offered up by the 'htop' program. Many of those things
were only true of the original redhat top while others
are no longer true of this current top program. So let
me use this commit msg to begin to correct the record.

Corrected comparisons between 'htop' & 'top' programs:
------------------------------------------------------
+ htop does not start faster, actually reverse is true
+ top offers scrolling vertically and horizontally too
. (and top offers better <Home> and <End> key support)
+ unassigned keystrokes don't subject top to any delay
. (but htop suffers that annoying ncurses <Esc> delay)
+ in top one need not type the PID to kill the process
+ in top one need not type the PID to renice a process

Some things the 'htop' program was not bragging about:
------------------------------------------------------
+ top can outperform the htop program by a wide margin
+ htop + SIGWINCH = corrupted display + restart likely
+ htop cannot preserve its screen data at suspend/exit
+ the htop column management scheme is very cumbersome
+ htop allows columns to be duplicated again and again
+ htop displays only full command lines, not pgm names
. (and that 'Command' column must always be displayed)
. (and it must always remain as the last column shown)
+ htop does not provide for any sort of command recall
+ htop's search feature does not highlight any matches
+ there is no 'find next' outside of htop search modes
+ htop does not allow Header or Process memory scaling
+ htop provides no flexibility on column justification
+ htop does not provide the means to change col widths
+ htop provides less control over colors configuration
+ htop always overwrites the rcfile with any UI change

Someday, maybe we'll provide a better comparison as an
addendum for (or replacement of) that README.top file.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-06-22 21:39:55 +10:00
Jim Warner
318919094d top: rearrange Mem & Swap lines and standardize 'used'
In anticipation of upcoming memory graphing provisions
the abbreviations 'Mem' and 'Swap' are being made into
individual translatable strings in order to be reused.

Additionally, the Mem 'used' amount will now no longer
included the 'buffers' and 'cached' values. Thus, each
Mem category becomes unique. This is the approach used
by tools such as 'htop' or the gnome 'System Monitor'.

Lastly, with that change to the 'used' category it has
been repositioned after 'free' on the Mem & Swap lines
making a comparison between 'total' and 'free' easier.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-06-22 21:39:55 +10:00
Jim Warner
23ebb9f44d top: tweak hotplugged response and frame refresh logic
For some time now, top has refrained from updating the
current number of cpus and memory totals with each and
every refresh cycle. Rather, to lessen overhead costs,
such values are updated periodically (5 min & 3 secs).

The delay in updating the cpu count was only important
with the addition of a cpu, since any loss is detected
immediately. And the large interval was chosen because
of the costs once associated with a glibc sysconf call
and an unlikely scenario of physically adding the cpu.

But the ease with which cpus can be taken offline then
placed back online under linux suggests that 5 minutes
may be too high. So, without addressing the likelihood
of that act, top is now more responsive in these ways:

1) that 5 minute interval has been reduced to 1 minute
2) any key, not just Enter/Space, refreshes cpus & mem

Note: we leave the man document as is, suggesting that
only the Enter/Space keys force an update for hotplug.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-05-28 06:53:19 +10:00
Jim Warner
0caa6d6e67 top: miscellaneous accumulated changes to program code
. prevent any input recall overrun if window downsized
. adjust translation notes for true column hdr maximum

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-05-13 16:39:49 +02:00
Jim Warner
bef6b0f025 top: standardize <Esc> key support with prompted input
In release 3.3.6, some commands were equipped with the
concept of a 'default pid'. The initial implementation
meant that the intuitive <Esc> key would not always be
treated as one would expect under any well behaved UI.

This patch ensures the expected <Esc> key behavior of:
terminating user input while still making possible the
necessary distinction between 'no input' & 'defaults'.

Reference(s):
http://www.freelists.org/post/procps/top-Escape-doesnt-abort-kill-command

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-04-28 20:56:48 +02:00
Jim Warner
fe37ad15cd top: avoid a 'nan' when the delay interval is very low
The granularity of /proc/uptime is fixed at hundredths
of a second. And, since we can cycle faster than that,
we are exposed to 'nan' when calculating elapsed time.

This commit will protect us from that outcome when the
delay interval has been set to an extremely low value.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-04-28 20:56:48 +02:00
Jim Warner
e2868da34e top: update copyright dates plus 1 preprocessor change
Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-04-28 13:46:06 +02:00
Jim Warner
22e6582974 top: protect against distortion when system time reset
If a system's time is adjusted backwards, then elapsed
time could appear as negative. This yielded a negative
%CPU value. Alternately if zeros were suppressed ('0')
the result was a blank %CPU column. In both cases that
distortion would last for one display cycle or until a
user forced a display refresh via some keyboard input.

The original recommendation was trading gettimeofday()
for clock_gettime() using CLOCK_MONOTONIC. But on some
systems that might not be possible, forcing the use of
CLOCK_REALTIME instead. Not only would that complicate
the build system, but it may leave us with minus %CPU.

Another approach was to ensure that elapsed time could
never be negative. Of course, this produced distortion
of %CPU values but it would be proportionally correct.
This wasn't dissimilar to a distortion already present
should the time be adjusted forward or backward within
any 'remaining' top delay intervals. These aberrations
would be avoided with clock_gettime & CLOCK_MONOTONIC,
but that is a less than ideal solution as noted above.

This final solution, which originated down under, will
simply rely on the /proc/uptime seconds, which will be
immune to *any* tampering with the system clock. Thus,
we now have a fix for the distortion we didn't know we
suffered plus a negative %CPU that began this odyssey.

Thanks to:
sk.alvin.x@gmail.com, for the original effort
jcapik@redhat.com, for a heads up on CLOCK_MONOTONIC
csmall-procps@enc.com.au, for the best suggestion of all

Reference(s):
. original post/patch
http://www.freelists.org/post/procps/PATCH-top-use-clock-gettime-instead-of-gettimeofday
. heads up on CLOCK_MONOTONIC
http://www.freelists.org/post/procps/PATCH-top-use-clock-gettime-instead-of-gettimeofday,2
. the final solution
http://www.freelists.org/post/procps/PATCH-top-use-clock-gettime-instead-of-gettimeofday,11

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-04-28 13:46:06 +02:00
Yuri Chornoivan
2ec9f5c22e Minor i18n fixes
Minor fixes that the translator (Yuri) has found in some of the
strings. You only know how many typos and thinkos you have when
someone is trying to translate it.

Signed-off-by: Craig Small <csmall@enc.com.au>
2014-03-03 21:58:56 +11:00
Jim Warner
24f1fbd9d0 top: avoid name conflict in the next version of stdlib
Since its inception top has always used enumerators to
identify displayable fields. They've taken the form of
P_PID, etc. As it turns out, something has changed for
libc6-dev versions beyond 2.17-93 wherein 'P_PID' will
now be exposed via stdlib.h. I have not pinpointed the
exact cause but it may depend on header include order.

This patch just trades top's long standing 'P_' prefix
convention for that of 'EU_' (short for enumerator). I
cannot find *any* header under /usr/include/ currently
utilizing this particular three character combination.

And as a further safeguard top will henceforth include
'system' specific headers after the standard includes.

Reference(s):
http://www.freelists.org/post/procps/top-wont-compile-anymore

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-02-27 06:30:44 +11:00
Jim Warner
bcf4f5a830 top: restore the former behavior after stderr redirect
When top originally responded to the potential libnuma
stderr write, the library was consistently called with
each refresh cycle. That, in turn, guaranteed that any
warning message would be seen at program end by virtue
of: 1) having been issued before the 2nd refresh cycle
and; 2) benefiting from inherited /dev/null buffering.

A later efficiency refactor meant the numa library may
not always be called with every refresh cycle. Rather,
it was only called if top was in one of two numa views
(the '2' or '3' toggles). That, in turn, resulted in a
loss of any warning message at program end unless numa
mode had been preserved in the rcfile. In other words,
if top was started normally then a single cycle stderr
redirect would have long passed by the time the '2' or
'3' toggle was activated. The warning message actually
was spewed but quickly lost to the full screen refresh
which follows all keyboard interactions with the user.

This commit simply moves the restoration of our stderr
redirect to program end (instead of that first display
refresh). Now, any libnuma stderr warning message will
appear as the concluding output line upon quitting top
without regard to when any numa mode view was invoked.

And since this technique might be useful in some other
context (as an example of how to 'buffer' stderr) it's
been generalized with its own #define. But to maximize
its usefulness, the original redirect should be issued
much earlier in pgm startup than top has chosen to do.

Reference(s):
. original libnuma stderr response (msg seen)
commit 35dc6dcc49
. numa refractoring for efficiency (msg lost)
commit f12c0d5c6e

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-02-22 11:16:22 +11:00
Jim Warner
b6fcb602ce top: provide for discontinuous (not active) NUMA nodes
Apparently there are occasions when NUMA nodes may not
always be contiguous. Under such conditions nodes that
were not used would still occupy precious Summary Area
space showing 100% idle, under the '2' command toggle.

With this commit top will no longer display numa nodes
that have no associated cpu when the '2' toggle is on.
But just in case we wish to return to former behavior,
a new #define called OFF_NUMASKIP has been introduced.

And as an aside, a recent refactor mentioned below set
the stage for this patch to be 'self-tuning'. In other
words, if an inactive/non-displayed node should become
active (if even possible), then top will begin showing
such a node automatically with the next screen update.

Unfortunately, all inactive nodes now 'suppressed' are
still accessible via the '3' command. Those nodes will
just be displayed as empty (no associated cpus shown).
This is not really a top problem but more of a libnuma
and/or user deficiency. The library lacks the means to
validate a node id and the user then input a node that
was not even shown under a '2' toggle Summary display.

( too bad libnuma does not offer an 'is_node_active' )
( type function so top could warn a user when such a )
( discontinuous node was requested using his '3' cmd )

( sure, top could achieve this objective himself but )
( that would require making yet another array global )
( which i'm just not in the mood to do - besides, we )
( have already made enough concessions to libnuma.so )

Lastly, an existing #define (PRETEND_NUMA) was changed
to 'disable' node #1 so as to simulate a discontinuous
node. This allows testing of the '2' and '3' commands.

Reference(s):
http://www.spinics.net/lists/util-linux-ng/msg08671.html
. set stage for self tuning
commit f12c0d5c6e

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-01-20 19:10:22 +01:00
Jim Warner
14ef47af57 top: do not forget the fscanf %s terminating null byte
Reference(s):
http://www.freelists.org/post/procps/procpsng-339-defects-found

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-12-19 15:27:11 +01:00
Jim Warner
4c464acf28 top: follow usual name conventions for global variable
A recent change involving a one cycle stderr redirect,
to handle a libnuma potential transgression, failed to
follow normal global variable naming conventions. This
patch will capitalize the 1st letter of 'Stderr_save'.

Reference(s):
commit 35dc6dcc49

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-12-02 21:37:36 +01:00
Jim Warner
57ab5eed15 top: do not lie about purported alphabetical orderings
Excluding those special X_XON/X_XOF enums, which might
not even be present, restore strict collating order of
all the case labels in the task_show switch statement.

Also, adjust a few sort callbacks for the same reason.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-12-02 21:37:36 +01:00
Jim Warner
af4e6533ba top: increase the maximum number of displayable fields
The recent addition of namespaces, combined with those
potential suse out-of-memory fields, means that we are
close to the maximum number of fields poor ol' top can
display. Imagine, the really old top was limited to 26
fields (28 with the suse hack) and this top had neared
the version 'g' rcfile limits which were a healthy 55.

This patch adds another 15 fields to the maximum while
making it even easier to increase in the future. Also,
top still silently accommodates older config files all
the way back to the original pre-ng version top-3.2.8!

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-11-25 20:57:32 +11:00
Jim Warner
2aa0951d1b top: expand this program to include namespaces support
Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-11-25 20:57:32 +11:00
Jim Warner
89c2f28e39 top: eliminate yet more gcc subscript resolution bloat
This patch is inspired by the 'minimize numa overhead'
patch. It trades the use of subscripts for pointers to
avoid gcc repeated subscript offset calculation bloat.

Now, throughout the cpus_refresh function, a subscript
will be resolved just once & this will (dramatically?)
reduce the path-length taken for each and every frame!

For example, a non-optimized compilation could produce
400+ fewer machine instructions through pointer usage.

[ ok, optimized compiles only save 18+ instructions! ]

Lastly, any residual 'symmetry only' crap is now gone!

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-11-25 20:57:32 +11:00
Jim Warner
f12c0d5c6e top: minimize the statistics overhead for numa support
A recent libnuma potential corruption problem solution
has caused me to reevaluate some associated numa logic
for efficiency. Here is a summary of the problems that
exist with current libnuma/user possible interactions:

. Whenever the numa library was present extra overhead
would always be incurred in maintaining the node stats
even when the '2' or '3' commands were not being used.

. As part of such overhead a separate loop was used to
reinitialize each cpu/node structure with each display
cycle so that prior accumulated totals were preserved.
Again, it didn't matter if numa data was really shown.

This commit attempts to refocus on the 'critical path'
costs in a running top by optimizing for the occasions
when numa node data is not being displayed. Under such
conditions, no extra overhead will be incurred whether
or not a distribution has the libnuma library present.

To achieve this goal, some additional overhead will be
incurred, but only when actually displaying numa data.
And all such new costs have been minimized in spite of
the gcc inclination to duplicate subscript resolution.

Reference(s):
commit 24bd950cb2e1722d459461f0f9c0c30a4b9ffdaa

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-11-25 20:57:32 +11:00
Jim Warner
bdb2fe0056 top: add some flexibility to dlopen() for numa support
A recent libnuma potential corruption problem solution
suggests that libnuma could change in the future so as
to not spew to stderr. This then raises a question how
top could exploit any such library change since we are
currently locked into version #1 of the library by way
of our dlopen("libnuma.so.1", RTLD_LAZY) runtime call.

While not an ultimate solution, this commit will first
try for the most recent version of that library during
top's startup before trying the original libnuma.so.1.
We do this via the unqualified library soname symlink.

For this new dlopen() call to succeed, technically the
numa 'devel' package would usually have been required,
but that's not always true with every distro. And when
the libnuma.so symlink isn't present, it can always be
manually added should a newer & better behaved library
arrive & users tire of the stderr warning at top exit.

Reference(s):
commit 24bd950cb2e1722d459461f0f9c0c30a4b9ffdaa

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-11-25 20:57:32 +11:00
Jim Warner
35dc6dcc49 top: address some potential libnuma display corruption
There is a chance that the libnuma library may corrupt
top's display with some stderr warning messages in the
event something under /sys/devices/system/node/ cannot
be accessed. And, while 2 overridable 'weak' functions
are provided to alter such behavior, we can't use them
since top dynamically links to the library via dlopen.

This commit will redirect stderr to '/dev/null' during
just the first screen display cycle. Thus we can avoid
the corruption which would have remained visible until
the underlining screen row's data had finally changed.

Lastly, this patch should allow such a library warning
to actually appear when one finally exits our program.

[ i think the libnuma folks should consider changing ]
[ the error/warning interfaces to accommodate dlopen ]
[ rather than forcing something like the ugly kludge ]
[ we have employed or libnuma dependency on everyone ]

Reference(s):
https://bugzilla.redhat.com/show_bug.cgi?id=998678

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-11-04 16:00:42 +01:00
Jim Warner
e6a78f2745 top: swat bug impacting 'idle' mode & 'user' filtering
When Other filtering was introduced the nature of what
constituted a displayed row changed. No longer would a
task_show() call guarantee that another line is shown.
Rather, a non-empty string must have also been tested.

Unfortunately, when any task window was being filtered
for 'idle' mode or a particular 'user', the proc index
was incremented twice due to the perils of copy/paste.
Combining such an index increment with the new test of
task_show results works fine if filtering is inactive.

This was a particularly insidious bug which meant that
an adjacent task would be skipped whenever the current
task met 'idle' and/or 'user' filter criteria, and was
not otherwise excluded due to 'Other' filter criteria.

And, since it was the very next task that was ignored,
the bug was very susceptible to a window's sort order.
This could be illustrated when filtering on some user,
while sorting on PID. Then, toggling Forest View could
make otherwise unseen tasks appear and then disappear.

User workarounds are possible via interactive commands
trading the 'i' and 'u'/'U' provisions for the 'o'/'O'
other filtering capability thus avoiding an extra i++.
But that is certainly less than ideal and doesn't help
the 3.3.7 and 3.3.8 distorted command line provisions.

( this little buggie may end up costing me my pocket )
( protector, my coding badge & maybe even my cubicle )

Reference(s):
http://www.freelists.org/post/procps/Idle-elides-nonidle-processes
. bug originated with 'Other' filtering
commit 5edc6fb317

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-09-29 11:51:39 +10:00
Jim Warner
4141efaf13 top: restore the lost final newline when in Batch mode
This patch adds the final newline when exiting 'Batch'
mode. Interestingly, it has been missing since release
3.3.5 but undetected until the Redhat bugzilla report.

Reference(s):
https://bugzilla.redhat.com/show_bug.cgi?id=1008674

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-09-17 20:27:02 +02:00
Craig Small
5e4d9d5a92 Merge commit 'refs/merge-requests/2' of git://gitorious.org/procps/procps into merge-requests/2
Conflicts:
	uptime.c
2013-09-11 20:50:48 +10:00
Jim Warner
06c19f5ba4 top: swat bug affecting batch mode and width provision
Normally, the internally tracked 'Screen_cols' can not
exceed the lessor of 512 or actual screen width. There
was one case, however, where that 512 byte upper limit
was no longer properly imposed as it should have been.

When operating in 'Batch' mode the actual screen width
was allowed to be exceeded when the optional -w switch
was also used. But, it should never have exceeded 512.

This patch ensures the upper limit is always observed.

Reference(s):
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=721204

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-08-30 22:08:26 +10:00
Jim Warner
819ede1a6b top: correct, improve and otherwise tweak configs_read
This patch addresses the four '-Wunused-result' errors
generated whenever an optimized compile is invoked. It
also made the configs_read() guy a little more robust.

In the process, some logic was rearranged slightly and
some comments were re-indented simply for consistency.

Reference(s):
warning: ignoring return value of 'fgets', declared with attribute warn_unused_result [-Wunused-result]
warning: ignoring return value of 'fscanf', declared with attribute warn_unused_result [-Wunused-result]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-08-30 22:08:25 +10:00
Jim Warner
80e6783436 top: modest efficiency change to message line handling
When the final solution for cursor positioning for all
^Z or ^C cases was introduced the revised placement of
message line management introduced with the window mgr
'screen' refactor was retained. Those two commits mean
that a former tgoto was no longer needed when clearing
that msg line or displaying the scroll coordinate msg.

This patch eliminates the tgoto employed by frame_make
while assimilating a now defunct show_scroll function.

Reference(s):
. final cursor positioning for ^Z or ^C
commit 46a1356219
. 'screen' window manager refactor
commit 0fe393ff27

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-08-30 22:08:25 +10:00
Jim Warner
46a1356219 top: correct cursor positioning for all ^Z or ^C cases
Some more (very obscure) conditions where a suspension
or program end might embed the shell prompt within top
output have been uncovered beyond the 2 already known.

We had already covered some suspend/end contingencies:
1. the users were using the 'fields management' screen
2. the users were prompted for any line oriented input

However, there remained some situations where ^Z or ^C
could still produce a misplaced cursor + shell prompt:
3. the 'g' command while waiting for the window choice
4. the 'W' command if about to overwrite an old rcfile
5. the '=' command when exploiting the Inspect feature
6. the period during which any error message was shown

But, even when all those bases are covered there still
remains a remote possibility that such interrupts will
occur during a top repaint cycle. So rather than throw
yet more code at these self-inflicted problems perhaps
it is better if we just throw in the proverbial towel.

Thus, I'll take the only sane approach and restore the
results expected ever since top's inception and before
scrollback buffers entered the picture. Namely, with a
^Z or ^C the cursor will be placed on the final screen
row. That usually means it will immediately follow the
last output line but it may follow many blank lines if
the user interrupts top when *not* on the main screen.

Reference(s):
. expanded repositioning (for line oriented input)
commit 33104a2bcc
. introduced repositioning (for fields management)
commit 5c974ff44d
. scrollback buffers (the cursor handling changes)
commit dedaf6e1a8

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-08-08 19:21:22 +02:00
Jim Warner
30e90e4269 top: tweak cursor state code to swat an obscure buglet
An obscure bug has been discovered where a 'W' with an
old rcfile, warning against overwrite, would display a
cursor that should normally be hidden. This followed a
user's reply. So some logic was rearranged just a bit.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-08-08 19:21:22 +02:00
Jim Warner
6967bf80a6 top: correct, improve or otherwise tweak some comments
Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-08-08 19:21:22 +02:00
Jim Warner
33104a2bcc top: cursor repositioning includes line oriented input
A recent patch introduced the ability to recognize the
need to reposition the cursor at suspension or program
end. There remained unmet 1 additional potential need.

This commit extends that ability to embrace line input
so that if a user issues ^Z or ^C while being prompted
the resulting shell output will no longer be embedded.

Reference(s):
http://www.freelists.org/post/procps/top-library-miscellaneous-tweaks,7
commit 5c974ff44d

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-07-02 14:49:46 +02:00
Jim Warner
25ed080eaa top: refine some miscellaneous signals interrupt stuff
This commit mostly justs renames a few identifiers but
it also will now suppress any end-of-job report if top
wasn't ended via the 'q' key convention (i.e. signal).

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-07-02 14:49:46 +02:00
Jim Warner
5c974ff44d top: enable screen contents preservation at end-of-job
The title of this commit is actually quite misleading.

Were it more accurate, it would at least mention a tty
emulator's scrollback buffer, which was the cumulation
of a long pursuit to reduce the SIGWINCH overhead when
a window manager carelessly floods an application with
that signal *while* a user is still resizing a window!

Disabling and enabling that scrollback buffer resulted
in the final top display replaced with original screen
contents, a phenomenon acknowledged at the time but it
also represented a user interface change which has now
produced the first request for return to old behavior.

After the SIGWINCH dust settled, another problem arose
regarding behaviors under the 'screen' window manager.
In response, top was refactored a bit to avoid display
corruption. That was before discovering 'screen' could
duplicate the scrollback buffer behavior top expected.

As it turns out, the 'screen' refactoring had probably
made scrollback buffer manipulation unnecessary. Still
one could argue that a window should not be allowed to
scroll while a constantly updating program was active.

The solution represented in this commit returns former
behavior at program end (retaining top's last screen).
And if we ever wish to disable scrollback buffers, the
associated logic was retained but made conditional. It
is not reflected in configure.ac but might be someday.

Lastly, this commit corrects cursor positioning when a
^C is issued under 'Fields Management' at any terminal
that didn't have a scrollback buffer (i.e. a console).

Reference(s):
https://bugzilla.redhat.com/show_bug.cgi?id=977561
http://www.freelists.org/post/procps/top-library-miscellaneous-tweaks,1
. screen program refactor
commit 0fe393ff27
. scrollback buffer disabled
commit dedaf6e1a8
. sigwinch management defines
commit adca737758
commit 4f33b6b8c5

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-07-01 19:10:57 +02:00
Jim Warner
b55f9b97db top: add the major version to dlopen of libnuma soname
When the plug-in approach to NUMA support was added, I
carelessly employed the compile-time linker convention
for naming the library. Technically this then required
the 'devel' package for NUMA support to be present for
the unqualified soname symlink to be available. Either
that or one must have manually created such a symlink.

This commit adds the missing major version to dlopen()
of libnuma.so.1 so simply having a more likely package
such as 'numactl' will enable both '2' & '3' commands.

References(s):
http://www.freelists.org/post/procps/top-NUMA-node-CPU-utilization-support,25
. initial dlopen support
commit edba932a7e

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-06-10 15:43:12 +10:00
Jim Warner
0fe393ff27 top: inoculated against a window manager like 'screen'
If top were invoked under the 'screen' window manager,
writing the terminfo string 'exit_ca_mode' at top exit
would not restore the display to the state existing at
the time top was started. That's what occurs normally.
The net result of that failure was a corrupted screen.

However, there is a 'screen' configuration option that
will produce proper 'rmcup' behavior, but it is off by
default. That screencr option is known as 'altscreen'.
I stumbled across this provision by cloning the screen
git repository then searching for references to 'cup'.

If 'altscreen on' had been in either the /etc/screenrc
or the $HOME/.screenrc configuration file, my poor old
top would never have been accused of such corruptions.
Of course, the Programming Gods decree that any simple
solution for our problem must always be revealed last.

So before discovering that rc option, another approach
was taken involving top only. With just a little extra
refactoring of top display logic he was made immune to
any such quirk in the implementation of 'smcup/rmcup'.

I always feel good about any enhancement that actually
reduces the total number of lines of code. Even though
this change involved mostly rearranging some logic, it
yielded one less line (can't judge by diffstat because
of braces & notes). Anyway, rather than requiring some
change to a screenrc file, now we are self-sufficient.

Reference(s):
  procps ---------------------------------------------
https://bugzilla.redhat.com/show_bug.cgi?id=962022
http://www.freelists.org/post/procps/top-procpsng337-no-screen-cleaning-at-exit,3
. top : disable tty scrollback buffer to improve SIGWINCH
commit dedaf6e1a8
  screen ---------------------------------------------
git://git.sv.gnu.org/screen.git
. Improve cursor store/restore on smcup/rmcup.
commit f95352946080be803b794c9f2733d8c809c1a39a
. Fix using alternate screen buffers in some cases.
commit ad56f746c6243d45124485d198d577bdbb78071c
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=558724

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-05-22 14:55:40 +02:00
Jim Warner
77abe18d01 top: revert %CPU and %MEM precision to former defaults
When summary & task area memory scaling was introduced
in release 3.3.6, the percentage columns were expanded
to provide 3 decimal places of precision. In hindsight
that may have been overkill, making those columns more
of a distraction than useful, with just too much info.

This patch will revert those columns to the former one
decimal place. And as was true, that decimal point may
be sacrificed depending on the number of cpus present.

And, in case anyone might prefer additional precision,
a build option can provide it (--enable-wide-percent).

Reference(s):
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=707648
http://www.freelists.org/post/procps/What-happened-to-my-top,1
commit 21e550bc08

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-05-19 09:40:42 +10:00
Jim Warner
ae102f359f top: reduce function call overhead in the NUMA support
Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-05-19 09:40:41 +10:00
Jim Warner
edba932a7e top: introduce a plug-in approach for the NUMA support
The NUMA/Nodes support in top has gone through several
evolutions (primarily dealing with build-sys options).
With this commit the library dependency issues are now
moot and the responsibilities for run-time loading and
dynamic linking are assumed by the top program itself.

Henceforth, if top is executed in an environment where
libnuma.so is present, top will offer such extensions.
Even more importantly, when a missing libnuma is later
installed, top will offer numa support auto-magically.
All NUMA/Node build-sys dependencies are thus removed.

The former NUMA_ENABLED define has become NUMA_DISABLE
should anyone wish to test user interface implications
in an environment that *does* have libnuma. It is also
represented as the ./configure option: --disable-numa.

Lastly, the 't' (View_STATES) toggle will be forced on
for sanity whenever the '1', '2' or '3' keys are used.

Reference(s):
. original idea from: Dr. Fink <werner@suse.de>
http://www.freelists.org/post/procps/top-NUMA-node-CPU-utilization-support,18
. original numa suppoort
commit 8d989c68c0

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-05-05 09:12:08 +10:00
Jim Warner
d16fd8e462 top: snapshot /proc/stat reads to minimize distortions
Almost forever, top has been accessing the /proc/stat/
directory one line at a time until either smp_num_cpus
was reached or (more recently) Screen_rows is reached.

When NUMA/Nodes support is enabled screen rows will no
longer serve as a limit because all cpus must be read.

With this commit, the entire /proc/stat/ directory can
be read at once so all statistics will be frozen. Thus
individual cpus will no longer keep "ticing" until top
gets around to accessing them via some separate fgets.

The distortion this commit eliminates was quite easily
seen when comparing old/new tops using: individual cpu
stats vs. cpu summary; a healthy delay interval of 3-5
seconds; manually synchronized update cycles (the hard
part); some system loading (maybe another top at -d0).

Additionally, this patch eliminates some long standing
unnecessary initialization made possible because of an
allocation via calloc. If some parts are never touched
by sscanf due to a kernel version, it's unnecessary to
repeatedly re-initialize those portions to zero again.

Reference(s):
. numa extensions added
commit 8d989c68c0
. useless initialization evolution (old to new)
commit e54c8239b1
commit 9278134e49
commit fd62123562
commit f348575edc

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-04-24 08:29:22 +10:00
Jim Warner
3ac09447e5 top: change number of emulated cpus from four to eight
With the addition of NUMA/Node support and the ability
to emulate such support even in the absence of libnuma
and numa.h, the maximum number of cpus top can emulate
was increased to make numa emulation more interesting.

( whew, that's an awful lot of "emulates", me thinks )

Reference(s):
commit 8d989c68c0

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-04-24 08:29:21 +10:00
Lance Shelton
8d989c68c0 top: program code changes, enable NUMA/Node extensions
This commit extends the top Summary Area cpu states to
include information on Non-Uniform Memory Architecture
nodes. It is based upon changes originally proposed by
Lance Shelton who was instrumental in the final patch.

With this change, the user will have new commands that
will provide alternatives to the individual cpu stats:

. '2' toggles between cpu & numa node summary displays
. '3' provides node summary and related cpu statistics

These extensions required some minimal system support.
Typically, the numactl package (and maybe libnuma-dev)
are all that's needed to show a single node which owns
all the processors. Failing that, or for slightly more
variety, top also offers a #define named PRETEND_NUMA.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Signed-off-by: Jim Warner <james.warner@comcast.net>
Signed-off-by: Lance Shelton <LShelton@fusionio.com>
2013-04-14 22:21:42 +10:00
Jim Warner
4aa917455c top: fix the bug affecting certain Find/Locate results
When 'Other Filtering' was introduced the idea of what
constituted a displayed row changed. No longer was any
call to task_show assured of consuming one screen row.
Now the determining factor was whether or not the rows
were empty. This worked Ok until a certain Find string
was active then the entire display could be corrupted.

With Find active, the task_show() function alters each
returned row while highlighting each visible match. If
the search was on a single byte value & matched at the
beginning of a row the match got overwritten with '\0'
which then appears empty upon return to window_show().
So that row would not be counted as having been shown.

This was best illustrated with a Find on a single ' '.

This patch will restore proper 'Find/Locate' behavior.

Reference(s):
commit 5edc6fb317

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-26 20:35:53 +11:00
Jim Warner
a6c5e31022 top: tweak 'Inspect' code for isolated edge situations
If the 'Inspect' feature was used to view a file which
contained binary (unprintable) data, and when the last
line for such a file was purely unprintable, then that
line length would be overstated by the terminal width.

This was also the occasion where valgrind might object
over potential reference to some unitialized value(s).
It was a harmless situation and somewhat rare to begin
with. Anyway this commit will eliminate the potential.

Additionally, supporting readfile logic was simplified
and the 'status line' bytes read is now more accurate.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-23 16:00:02 +01:00
Jim Warner
7b708ca334 top: rename a single Other Filter variable for clarity
There is a member of the osel_s structure called 'flg'
that is used to reflect whether a particular filter is
one of inclusion or exclusion (negation). So by golly,
from now on we'll refer to it as 'inc', and not 'flg'!

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-14 12:36:47 +01:00
Jim Warner
1a50f39971 top: fine tune (ie. fix) 'other filter' negation logic
Two too many of these '=' (cooks) spoiled top's broth.

There exists an unintentional variation on the classic
error: off-by-one. When a negation symbol is used with
top's new relational 'other filter' provision, one too
many 'matches' are excluded. This happened because top
covered only 2 of the 3 potential strcmp return codes.
When the strings were equal, they were simply dropped.

So this patch will uninvent that particular variation!

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
commit 2c2c5f5cd2

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-07 17:55:20 +01:00
Jim Warner
2c2c5f5cd2 top: introduce relational operators with other filters
When I originally entertained thoughts of maybe adding
relational operators to the new 'Other Filter' feature
the programming challenges seemed just too great. Yet,
when Jaromir suggests its desirability it now suddenly
becomes a reality. Another of life's little mysteries!

At any rate what was already an extremely powerful new
feature is even better by several orders of magnitude!

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

References:
http://www.freelists.org/post/procps/top-beyond-infinity,1

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-06 14:37:40 +01:00
Jim Warner
5edc6fb317 top: enable other filtering via inclusion or exclusion
This change represents the extension of user filtering
based on inclusion or exclusion. However where 'U'/'u'
filtering provides an either/or choice, this extension
offers multiple choices applicable to multiple fields.

The 'inclusion' and 'exclusion' criteria can be freely
combined making a powerful tool to fine tune a display
and avoid clutter associated with uninteresting tasks.

I'm convinced it offers unimagined future flexibility!

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
http://www.freelists.org/post/procps/top-over-the-top,22
http://www.freelists.org/post/procps/top-over-the-top,8

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-04 18:46:34 +01:00
Jim Warner
5e4bade595 top: minor refactor in preparation for other filtering
While it's only documented (so far) in commit text and
an occasional email I've tried to maintain some coding
standards primarily for reference/navigation purposes.
They also served, I felt, as useful mental challenges.

Someday I will get around to formerly documenting them
but in the meantime here are the ones for this commit:

. functions are grouped into logical (i hope) sections
. functions & sections are ordered to avoid prototypes
. function names are alphabetical within every section

Thus, given those constraints/objectives, and in order
to prepare for an upcoming Other_Filter feature, a few
things had to be renamed and rearranged. Plus a couple
of other (unrelated) tweaks were made for consistency.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
commit 270e8e7eeb
http://www.freelists.org/post/procps/PATCH-12-top-restore-terminal-state-on-exit,4

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-04 18:46:31 +01:00
Jim Warner
b9976f7056 top: finish the job of correcting the response to a ^Z
if top is suspended while on the 2nd level help screen
the <Enter> key is no longer honored. Thus, users must
use <Esc> to exit help and return to the main display.

Also, line input that was only partially complete when
suspended would still require one additional keystroke
before the read was aborted and the display refreshed.

Lastly, some user interactions might require two input
lines before an operation can be considered completed.
Thus the 2nd line offers another opportunity for users
to suspend top. Resumption would require an extra key.

These issues stem from 2 recent enhancements: preserve
the user context when signaled; complete input editing
with cursor movement keys, insert/overtype modes, etc.

With this patch, the <Enter> key is once again honored
on help screen #2 and partial reads are now completed.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
       bug reported
http://www.freelists.org/post/procps/top-over-the-top,25
       response to ^Z (partial solution)
commit 5c3fffcf28
       line input editing
commit 477b10c0bd
       preserve context with SIGWINCH
commit ba9092ad83

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-01 14:25:35 +01:00
Jim Warner
709785e20b top: add the field 'USED' to top's existing repertoire
After revisiting the issue of a new field, combining 2
existing fields (RES and SWAP), I've decided it indeed
makes sense. After all, with the vastly expanded field
capability and the ease of adding new fields, it would
save some precious horizontal screen real estate while
also eliminating some mental/manual user calculations.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
http://www.freelists.org/post/procps/top-enhancements-i-hope
http://www.freelists.org/post/procps/top-regression-reports

Signed-off-by: Jim Warner <james.warner@comcast.net>

 top/top.1     |   23 ++++++++++++++---------
 top/top.c     |   14 ++++++++++++--
 top/top.h     |    6 ++++++
 top/top_nls.c |    3 +++
 4 files changed, 35 insertions(+), 11 deletions(-)
2013-03-01 14:25:31 +01:00
Jim Warner
9dd7251ca3 top: consolidate logic dealing with resetting a window
This commit just gathers all the logic associated with
resetting/normalizing a single window in one function.

In the future, should the window structure be expanded
to support added functionality, the act of maintaining
it will have been made a little bit easier, hopefully.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-01 14:25:28 +01:00
Jim Warner
a458871cde top: make user's choice for insert/overtype persistent
When true line input editing with paste capability was
was re-introduced in the commit below, the concept for
the distinct insert/overtype mode was also introduced.
But such a distinction did not survive an <Enter> key.

With this commit, the cursor state is made persistent.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
commit 477b10c0bd

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-01 14:25:22 +01:00
Jim Warner
6d0765a03c top: allow no input with the maximum task ('n') prompt
When both 'kill' and 'renice' commands were changed to
provide a default pid, the 'n' command (maximum tasks)
should have also changed to continue to accept just an
<Enter> key under the get_int function's new protocol.

This patch corrects that behavior, accepting no input.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
commit 39f4067c66

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-01 14:25:15 +01:00
Jim Warner
5ee1286625 top: allow re-ordering of saved line input upon recall
The original implementation of input line recall keeps
strings in the order established when initially added.
With this commit, that has been changed so any matched
string moves to the top of the saved input line stack.

[ well technically not the top since that's occupied ]
[ by an 'empty' string which serves multiple masters ]

Thus, the most frequently referenced strings over time
will percolate up and remain the most easily recalled.
But just in case anybody prefers the strict historical
ordering, a #define can restore the original behavior.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
commit 2efe275512

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-02-27 17:03:54 +01:00
Jim Warner
5c3fffcf28 top: improve the response to ^Z if awaiting line input
Now that line input offers users full editing freedom,
if top were to be suspended after issuing a prompt for
input, upon resumption an extra keystroke is necessary
to satisfy the outstanding read & refresh the display.

With this patch that extra keystroke is not necessary.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
commit 477b10c0bd

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-02-27 17:03:51 +01:00
Jim Warner
d497b1025a top: some idiot broke 'idle' mode with u/U 'exclusion'
This patch fixes the single stinkin' source line which
was responsible for breaking the top idle-mode toggle.

Without this change, either 'u' or 'U' must be invoked
just once before the 'i' command would show something.

(yes, everything's perfectly justified once again but)
(i'm not very happy over the need for this damn patch)

Reference(s):
commit d04297843f

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-02-27 17:03:49 +01:00
Jim Warner
2efe275512 top: enable recall of previous input lines for re-edit
With this commit, users can now retrieve previous line
input for re-editing and/or re-input using the Up/Down
arrow keys (or their aliases). This mirrors the 'bash'
or 'less' interface and represents a major enhancement
achieved via a somewhat minor impact to our code base.

[ 33 lines of code, 5 closing braces & some comments ]
[ all in 1 function, when TERMIOS_ONLY isn't defined ]

Currently, the upper limit for such recallable strings
has been set at 50 but that could be easily increased.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-02-24 08:43:45 +11:00
Jim Warner
477b10c0bd top: enable true line input editing with paste support
This patch changes the TERMIO_PROXY define back to the
former TERMIOS_ONLY thus changing the top default too.

Plus we can now use true line input editing while also
retaining paste capability. That former native termios
support provided only a limited destructive backspace.

Now we exploit the Left/Right arrow keys, Home/End and
Delete. Plus, the Insert key can toggle overtype mode!

[ The stage is now set for a really huge improvement ]
[ to any user input terminated with the <Enter> key. ]
[ So please stay tuned for the next patch to arrive! ]

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
commit fa21a6ca81

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-02-24 08:43:45 +11:00
Jim Warner
d04297843f top: enable user filtering via inclusion and exclusion
With this commit top can now display users which match
a user id/name or just those users which do not match.

The distinction is based on the presence or absence of
a leading exclamation point '!' (C negation operator).

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
Wishlist, http://bugs.debian.org/682086

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-02-24 08:43:45 +11:00
Jim Warner
c856a80ad5 top: end reliance on strdup not failing & roll our own
Lately, top has begun to rely more and more on dynamic
memory allocations rather than the static buffers that
were found in many of its structures. This was perhaps
most evident in the increasing use of the strdup call.

This commit trades that function call for the internal
equivalent which will protect us from malloc failures.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-02-24 08:43:44 +11:00
Jim Warner
bc5af4ae51 top: keep cursor hidden after Inspect 'Locate' request
A recent commit, that was intended to normalize cursor
handling, unintentionally exposed the cursor following
an Inspect 'Locate' request. This change will hide the
cursor once again through inst_view_choice's lifetime.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
commit f3a87cf634

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-02-24 08:43:44 +11:00
Jim Warner
e2c2bc5a95 top: the third time was charmed for end-of-job reports
When top was changed to allow some core dumps, the two
potential end-of-job reports were disabled by mistake.
Later, that was corrected so that those reports always
were allowed, if the respective #defines were enabled.

However, if there was an early exit via a command line
option or an error, those reports should not be shown.

This commit may have gotten it right on our third try!

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
commit 1da293bf59
commit d747659ad8

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-02-24 08:43:44 +11:00
Jim Warner
ca76af22ca top: lift the field management 6 col width restriction
When two somewhat cryptic error messages were recently
changed to more user friendly text, the logic limiting
maximum columns was left unchanged at six. This always
was a rather arbitrary limit but now the revised error
message could actually be misleading (ok, a huge lie).

With a 1 line code change (macro actually), this patch
lifts the internal restriction on maximum columns. Now
the real limit is based on a window's physical x-axis.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
commit 5a27c8095e
http://www.freelists.org/post/procps/top-won-the-sigwinch-war,6

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-02-05 22:11:22 +11:00
Jim Warner
dedaf6e1a8 top: disable tty scrollback buffer to improve SIGWINCH
A scrollback buffer used in several terminal emulators
could be a real inconvenience to a user following some
resize operations. Extra keystroke(s) would frequently
be required in order to properly render top's display.

After much sleuthing we unearthed two terminfo strings
which have the effect of disabling/restoring that darn
scrollback buffer. They were well hidden under a title
of strings 'to start/end programs using cup'. In turn,
'cup' deals with a tty's cursor addressing capability.

We don't care what you call them or what they refer to
so long as they get the job done. And these really do!
Be advised, however, that there are some side effects,
several of which can even be considered as beneficial:

. enter_ca_mode/smcup/ti disables scrollback buffering
( and that's good, it's what we had always hoped for )

. exit_ca_mode/rmcup/te restores the scrollback buffer
( but also restores screen contents existing pre-top )
( which is different from former program end results )
( where that last rendered screen was left untouched )

. the above screen replacement would impact ^Z suspend
( thus we keep the scrollback buffer disabled during )
( the suspend/resume sequence so that the users will )
( have a visual clue that top is suspended not ended )

If a terminal does not support these terminfo strings,
we will revert to top's former behavior at program end
where we position the cursor at screen bottom and then
output a single newline character. This will prevent a
shell prompt from embedding within top's final screen.

This commit's approach has been tested under a variety
of emulators and window managers, many of which linked
with libvte and others that employed their own scheme.
Examples are: gnome_terminal; kde konsole; lxterminal;
terminator; terminology; urxvt; xfce4-terminal; xterm.

I do now believe that the whole SIGWINCH deal is done!

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
http://www.freelists.org/post/procps/top-won-the-sigwinch-war
http://www.freelists.org/post/procps/top-won-the-sigwinch-war,4

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-02-05 22:11:22 +11:00
Jim Warner
5a27c8095e top: make field management window size error non-fatal
Reference(s):
http://www.freelists.org/post/procps/top-won-the-sigwinch-war,3

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-01-30 10:53:49 +11:00
Jim Warner
f3a87cf634 top: normalize miscellaneous putp screen manipulations
This commit standardizes the usage of several terminfo
strings concerned with cursor position and visibility.

Henceforth we will adopt the following informal rules:

. Cap_home vs. Cap_clr_scr is preferred where possible
. Cap_curs_huge will be used with prompts for line i/p
. Cap_curs_huge will be used with help & color mapping
. Cap_curs_hide will be in effect in any other context

We've also added a missing Cap_clr_scr to the 2nd help
screen whenever the SIGWINCH interrupt was recognized.
This prevents a 'duplicated' row from appearing at the
top of the display (when resizing from small to large)
depending on an emulator's scrollback buffer contents.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-01-30 10:53:49 +11:00
Jim Warner
6f25f956e7 top: a few small adjustments to reduce display flicker
This change involves the Fields Management logic only.

With user position being maintained after signals, the
previous algorithm unfortunately used Cap_clr_eos with
each iteration of the loop. The screen flicker invited
with that choice was not apparent under all emulators.

With this commit, clearing to end-of-screen has become
conditional on whether or not there was a true resize.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
commit ba9092ad83

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-01-30 10:53:49 +11:00
Jim Warner
adca737758 top: change default allow/suppress define for SIGWINCH
No top #define is enabled and that constitutes default
behavior. So whenever a default behavior should change
the define must be changed too if it is to remain off.

This commit simply changes top's default behavior with
respect to allowing/suppressing any potential flood of
SIGWINCH during resize operations, if running under X.

Formerly top would block those signals to reduce costs
of repeated refreshes. That yields a requirement where
the user would have to provide another keystroke for a
final display update. That keystroke may not always be
needed now, but it ultimately depends on some terminal
emulator's scrollback buffer. In any case, the cost of
re-sizing may go up a bit, under most window managers.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
commit 4f33b6b8c5
http://www.freelists.org/post/procps/top-won-the-sigwinch-war
http://www.freelists.org/post/procps/top-won-the-sigwinch-war,4
http://www.freelists.org/post/procps/top-won-the-sigwinch-war,5

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-01-30 10:53:48 +11:00
Jim Warner
4f33b6b8c5 top: offer define to allow/suppress excessive SIGWINCH
After carefully working our way to the point where the
excessive SIGWINCH interrupts are now throttled, along
comes a commit which reverses all those prior efforts.

Actually it doesn't. It simply allows one to choose if
all those efforts should be reversed or remain active.

Why in the world would you even want to consider that?

Quite simply, to opt for responsiveness over overhead.
Oh, and depending on the terminal emulator used for X,
by enabling this OFF_SIGWINCH #define you will be able
to avoid the need for an extra keystroke after resize.

Besides it was an interesting programming challenge to
see just how few lines of code would be needed to make
it possible. Bottom line? Only 1 source line required!
(actually 0 lines, since the define disables one line)

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
http://www.freelists.org/post/procps/unwanted-topinspect-window-enclosure-with-the-terminal-size-change

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-01-24 21:29:24 +11:00
Jim Warner
dd357e70e7 top: immunize against window manager flood of SIGWINCH
Whew, it was nip-and-tuck there for awhile but finally
we solved the SIGWINCH overload problem one finds with
most X window managers. Now if a window manager should
try to inundate ol' top with repeated SIGWINCH signals
they won't even be received so can't impact us at all.

And we achieve this miracle having never even issued a
sigprocmask, so all the top code executes with signals
totally unblocked. Intuition suggests it probably rubs
even more salt in the wound, but au contraire mon ami!

The key to our success was simply trading the 'select'
call for its cousin 'pselect'. Not only does that call
provide nanosecond granularity (vs. the former's usec)
but it takes a sigset_t parm which can then atomically
block the troublesome SIGWINCH guy until user input or
optional timeout. Net result? No more signal overload!

Now, if only we could just coax all terminal emulators
into one identical standard buffering scheme plus find
some way to emulate the most recent SIGWINCH, it would
be perfect. We would then obviate the user requirement
of typing yet 1 more key before seeing proper results.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
http://www.freelists.org/post/procps/unwanted-topinspect-window-enclosure-with-the-terminal-size-change
http://www.freelists.org/post/procps/Sourceforge-project,7

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-01-24 21:29:24 +11:00
Jim Warner
de6df7d736 top: refactor all the low-level i/o logic for SIGWINCH
This commit primarily involves renaming functions plus
reorganizing logic in preparation for the next changes
which will hopefully yield the 'final solution' to the
excessive SIGWINCH signals under most window managers.

In this specific patch, the most significant change is
the introduction of a new 'ioa' function (io avail) to
focus all logic dealing with unsolicited user keyboard
input and exposed to signals and/or optional timeouts.

That new function is where our signal overload will be
ultimately defeated, if it is at all humanly possible.

(everything is perfectly justified plus right margins)
(are completely filled, but of course it must be luck)

Reference(s):
http://www.freelists.org/post/procps/unwanted-topinspect-window-enclosure-with-the-terminal-size-change

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-01-24 21:29:23 +11:00