1. 14 Oct, 2017 5 commits
    • top: stop neglecting potential utf8 field descriptions · b5104910
      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>
      jim warner committed
    • top: eliminate that potential vulnerability for TOCTOU · a02a31f7
      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>
      jim warner committed
    • top: make 'utf8_justify' independent of non-utf8 logic · d734d18f
      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>
      jim warner committed
    • top: utf8 utils should observe indentation conventions · 474f4da5
      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>
      jim warner committed
    • top: ensure bug report suggestion agrees with man page · 3afadf56
      The top man page was changed back on 10/20/15, in that
      commit shown below. There, freelists.org was suggested
      as the bug reports recipient. But, the program was not
      changed from the original Debian bug reports approach.
      
      Reference(s):
      commit b1f7b2a5
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
  2. 06 Oct, 2017 6 commits
    • top: make the 'utf8_proper_col' routine more efficient · a74f6044
      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>
      jim warner committed
    • top: make that 'make_str_utf8' function more efficient · ca566ad5
      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>
      jim warner committed
    • top: ensured one translation hint agrees with template · 0154ffb2
      Now that top can properly handle translated multi-byte
      strings I've been reviewing translated efforts so far,
      and weighing output against related translation hints.
      
      In one case, a translation hint has not kept pace with
      the current program state. In addition, that same hint
      could be expanded to suggest translation alternatives.
      
      [ frankly I never expected the translators to tackle ]
      [ some of those 'special' strings. the task appeared ]
      [ just too daunting. but they have done a great job! ]
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
    • top: again avoid multiple evaluation of macro argument · 53a1b965
      Before top was modified to exploit the new <pids> api,
      there was protection in that task_show() makeVAR macro
      to avoid multiple evaluation of this macro's argument.
      
      But, in that commit referenced below, such a safeguard
      was lost. This commit simply restores proper behavior.
      
      Reference(s);
      . offending change
      commit 77dc22b9
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
    • top: when did scale_mem parm lose 'unsigned' qualifier · e55016de
      Well, for some strange unknown reason it happened in a
      commit referenced below. But this patch reverts it and
      puts this newlib scale_mem on par with the master guy.
      
      [ a little more research reveals that it should have ]
      [ been reverted in the 2nd commit shown. that's when ]
      [ types were fixed after XTRA_PROCPS_DEBUG was used. ]
      
      Reference(s):
      . when 'unsigned' qualifier lost
      commit 911083bf
      . when 'unsigned' qualifier not restored
      commit 105058ae
      . when XTRA_PROCPS_DEBUG validation introduced
      commit e3270d46
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
  3. 02 Oct, 2017 3 commits
    • top: correct an insidious occasional truncation buglet · 1bc25e92
      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):
      #68
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
    • top: plug a small potential hole in multi-byte support · e189569d
      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>
      jim warner committed
    • ps: don't use '+' truncation indicator with multi-byte · 9ea00210
      The ps program generally supports multi-byte sequences
      in strings representing user and group names. However,
      should a multi-byte sequence span the maximum width of
      a column, the '+' inserted by ps to signify truncation
      will corrupt that sequence, misaligning the text line.
      
      Unfortunately, there's insufficient info returned from
      the escape_str function (who calls escape_str_utf8) to
      provide a robust response. So, this commit will revert
      to the old standby of displaying a number when the '+'
      character would've corrupted that multi-byte sequence.
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
  4. 01 Oct, 2017 9 commits
    • top: extend utf-8 multi-byte support to users & groups · d2aa8009
      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):
      #68
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
    • top: some minor tweaks to the utf-8 multi-byte support · 1c76d8e5
      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>
      jim warner committed
    • NEWS: acknowledged top's multi-byte support extensions · 9246b950
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
    • top: extend multi-byte support to 'Inspection' feature · b8bfa174
      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):
      #68
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
    • top: refactored for correct multi-byte string handling · 9773c56a
      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):
      #68
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
    • top: correct a minor instance of wrong NLS macro usage · 07530a86
      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>
      jim warner committed
    • library: fixed miscellaneous whitespace/comment issues · 28f40568
      . ensure whitespace exists between the code & comments
      [ changing txt slightly keeps right margin alignment ]
      
      . strive for more consistency with some comment styles
      [ don't use C '/*' style where C++ '//' style exists ]
      
      . removed the instance of double space in 1 assignment
      [ still striving for consistency in whitespace usage ]
      
      . fixed comment relating to number of 'derived fields'
      [ the <meminfo> api recently added one new such enum ]
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
    • library: normalize stacks_extent struct layout, <PIDS> · 89775d54
      This patch just rearranges 1 item in the stacks_extent
      struct to make it equivalent to all the other modules.
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
    • library: add delta values with swap too, <meminfo> api · daf7c86c
      As an oversight, delta values for SWAP amounts weren't
      included in the <meminfo> API. Since any runtime costs
      of including them only amount to slightly more storage
      this commit will simply correct the earlier oversight.
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
  5. 24 Sep, 2017 2 commits
    • vmstat: Fix alignment for disk partition format · ccbd818c
      The disk partition format translation hint, the actual text and the
      printf statements were all diagreeing with each other. This meant
      the disk partition output from vmstat was a mess.
      
      Now all the titles and values line up and everything is right-aligned
      which looks better than some half-hearted attempt at center-aligned
      for titles and right-aligned for values.
      
      Thanks to @goeran for the heads-up in #69
      Craig Small committed
    • whattime: Show 0 minutes in pretty output · 36512801
      When supplying the -p command to uptime, it does not display any
      sections where the value is less than 1; however, after a reboot, this
      causes the command to just output "up". Showing 0 minutes when the
      system has been up for less than a minute makes it clear a reboot just
      occurred.
      
      References:
       commit 325d68b7
      
      Signed-off-by: Craig Small <csmall@enc.com.au>
      Kyle Laker committed
  6. 19 Aug, 2017 9 commits
    • Avoid confusing messages caused by EIO on reading · c22fc572
      /proc/sys/net/ipv6/conf/*/stable_secret if those are not set yet.
      
      Signed-off-by: Werner Fink <werner@suse.de>
      Dr. Werner Fink committed
    • Increase standard I/O buffer a lot to be able to · 8af3db92
      read huge informations at once as otherwise all files below
      /proc/sys, not using the seq_file API at the kernel side,
      will return EOF on a second read.
      
      Signed-off-by: Werner Fink <werner@suse.de>
      Dr. Werner Fink committed
    • Fix out of boundary write on 1x1 terminals · e6e228e7
      If a terminal is merely 1x1 in size, setsize() will write a nul byte in
      front of the allocated memory, which is an out of boundary write.
      Tobias Stoeckmann committed
    • Port of merge request 49 to newlib · d8fb86db
      Wayne Porter made !49 which added Cygwin support to the master branch
      This is the port of those changes to newlib
      Craig Small committed
    • top: protect against the anomalous 'Mem' graph display · aab30a0a
      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):
      #64
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
    • top: address a Debian wishlist NLS man page suggestion · 86a7d65c
      Reference(s):
      https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=865689
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
    • NEWS: add issue and bugzilla references where possible · 4da00305
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
    • top: refresh interval accepts non-locale decimal value · 62da5ee3
      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):
      !50
      
      Prototyped by: Jan Rybar <jrybar@redhat.com>
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      Jan Rybar committed
    • top: at program startup, avoid a little extra overhead · bb19ac09
      There was a time when the PROCPS_PIDS_noop represented
      the highest valued enumerator. Therefore if one wished
      to prime an array consisting of pids_result structures
      with this specific item a loop would have been needed.
      
      Now that this enum is the first one, with the value of
      zero, we can avoid avoid such a loop with just calloc.
      
      But just in case, we'll use an 'if' to guarantee zero.
      
      [ and the nice thing is, since the value is known at ]
      [ compile time, that 'if' test plus subordinate loop ]
      [ can be discarded by the compiler as long as it's 0 ]
      
      Reference(s):
      . <pids> introduced (PIDS_noop > 0)
      commit 7e6a371d
      . top employs PIDS_noop at 'new' time
      commit f1bd82ff
      . <pids> relocated PIDS_noop (PIDS_noop == 0)
      commit e7585992
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
  7. 04 Jul, 2017 2 commits
    • top: fixing command line parsing errors is now a habit · 8c624ca9
      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 e3bad068
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
    • library: correct the #define FALSE_THREADS, <PIDS> api · 876aff85
      Awhile back, that former QUICK_THREADS #define evolved
      into the development (only) FALSE_THREADS which can be
      used to ensure a 'duplicate ENUM' convention is output
      when certain string fields can't be easily duplicated.
      
      Unfortunately, that original implementation was marred
      with zeros being displayed for /proc/$$/meminfo fields
      in all the child threads for a multi-threaded process.
      
      So this commit corrects that zero memory field buglet.
      
      Reference(s):
      . QUICK_THREADS becomes FALSE_THREADS
      commit c546d9dd
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
  8. 04 Jun, 2017 3 commits
    • misc: adapt 3 programs to some enum changes, <meminfo> · 105de626
      That preceding commit corrected a little mismanagement
      regarding the MEMINFO_MEM_CACHED enumerator, which was
      used in the following programs: free, top plus vmstat.
      
      This patch simply adapts those programs to use the new
      MEMINFO_MEM_CACHED_ALL enumerator, which reflects both
      the 'Cached' plus 'SReclaimable' values they expected.
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
    • library: correct 'used' memory calculations, <meminfo> · dbc880ed
      The <meminfo> module attempted to duplicate the former
      sysinfo memory calculations wherein 'SReclaimable' was
      added to 'Cached' for the 'kb_main_cached' equivalent.
      
      But, this original approach was wrong for two reasons.
      
      1. The addition occurred too late to impact the 'USED'
      calculation which could then cause an underflow in the
      top memory display if 'SReclaimable' was heavily used.
      
      2. In changing the actual /proc/meminfo 'Cached' value
      it meant that users could not rely on that proc(5) man
      page when interpreting the MEMINFO_MEM_CACHED results.
      
      So this commit adds a new enumerator for the inclusive
      cached amount plus repositions the calculation so that
      a MEMINFO_MEM_USED result will exclude 'SReclaimable'.
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
    • top: correct functioning of the '-p' command line args · e3bad068
      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 3e5c950a
      
      Signed-off-by: Jim Warner <james.warner@comcast.net>
      jim warner committed
  9. 22 May, 2017 1 commit