configure: check for program_invocation_name

For portabiliy, check for program_invocation_name during configure and
define HAVE_PROGRAM_INVOCATION_NAME accordingly. Use of this symbol is
now enclosed with the appropriate #ifdef block.

The symbol program_invocation_name is only used for error message
handling using error(), so it's safe to omit this if it is not
available.
watch: Remove unused header

No declaration from proc/procps.h is actually used for watch.
configure: Check for stdio_ext.h

For portability, check for stdio_ext.h during configure and define
HAVE_STDIO_EXT_H accordingly.

If the current system does not provide this header, use a fallback for
__fpending(). This definition will not work on all systems as it relies
on internal data structures of libc. A more portable solution should be
preferred, for example by using gnulib.
configure: Check for error.h

For portability, check for error.h during configure and define
HAVE_ERROR_H accordingly.

If this header is not available, emulate the functionality of error()
from glibc with an inline wrapper in include/c.h.
Revert "Fixed last_value for loops over 99999"

This reverts bogus commit 2840d7f4c66a85676c79eeb2c89db4d450fd3fc4.
99 was already added with 7f15f07b3f0d4a9c1e1a39d95f8e784edb65e041

Signed-off-by: Gilles Espinasse <g.esp@free.fr>
sysctl return value

Gilles brought up a warning message in sysctl.c
sysctl.c: In function 'main':
sysctl.c:767: warning: value computed is not used

The return value of Preload was not being applied correctly to ret
meaning sysctl would not return the correct value.

Reference: http://www.freelists.org/post/procps/procpsng-337,18

Signed-off-by: Craig Small <csmall@enc.com.au>
library: make dynamic buffer management more efficient

When dynamic buffers were recently introduced for read
of the status, stat and statm subdirectories one extra
call to read() was required for end-of-file detection.

This patch avoids most all such extra calls to read().

Additionally, the frequency of memory reallocations is
reduced by overallocating each increase more than 25%.

Reference)s):
commit a45dace4b82c9cdcda7020ca5665153b1e81275f

Signed-off-by: Jim Warner <james.warner@comcast.net>
Signed-off-by: Craig Small <csmall@enc.com.au>
library: avoid SEGV if file2str should read zero bytes

When utility buffers were introduced for file2str read
requests, a subtle change was inadvertently introduced
such that a read of zero no longer returns a -1 value.

This commit ensures that zero bytes read returns a -1.

And although the solution differs from a merge request
submitted by sergey.senozhatsky@gmail.com, a thank you
is offered for revealing this potential abend problem.

References(s):
commit a45dace4b82c9cdcda7020ca5665153b1e81275f
http://gitorious.org/procps/procps/merge_requests/11

Signed-off-by: Jim Warner <james.warner@comcast.net>
Signed-off-by: Craig Small <csmall@enc.com.au>
Merge commit 'refs/merge-requests/10' of git://gitorious.org/procps/procps into merge-requests/10
miscellaneous: clean up trailing whitespace once again

An earlier commit attempted to cleanse our environment
of all useless trailing whitespace. But the effort did
not catch 'empty' lines with a single space before ^J.

This commit hopefully finishes off the earlier effort.
In the meantime, let's pray that contributors' editors
are configured so that such wasted crap is disallowed!

Reference(s):
commit fe75e26ab64dab88762230db0797e765507b73ac

Signed-off-by: Jim Warner <james.warner@comcast.net>
Improved regexp test for pmap

The change in pmap is necessary if it happens that the whole output of
pmap -X or -XX has been done before the second regexp is matched. Since
the matching is greedy, it is matched by the full output, so that
nothing is left for the third regexp and the test fails with
FAIL: extra extended output (footer).

Reference: http://comments.gmane.org/gmane.linux.lfs.devel/13961

Signed-off-by: Craig Small <csmall@enc.com.au>
build-sys: in top program, enable NUMA/Node extensions

This patch provides the build system support for those
top extensions dealing with the NUMA summary displays.

For providing the initial impetus for this enhancement
I wish to thank Lance Shelton <LShelton@fusionio.com>.

(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>
top: documentation update, enable NUMA/Node extensions

This commit provides the NEWS and man document changes
supporting the new NUMA/Node top program enhancements.

For providing the initial impetus for this enhancement
I wish to thank Lance Shelton <LShelton@fusionio.com>.

(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>
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>
build-sys: in top program, enable NUMA/Node extensions

This patch provides the build system support for those
top extensions dealing with the NUMA summary displays.

For providing the initial impetus for this enhancement
I wish to thank Lance Shelton <LShelton@fusionio.com>.

(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>
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 8d989c68c068541a814bf0d2340ac9b0373f24b5

Signed-off-by: Jim Warner <james.warner@comcast.net>
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 8d989c68c068541a814bf0d2340ac9b0373f24b5
. useless initialization evolution (old to new)
commit e54c8239b1c46cf7b99dd6120c9090303fa969c8
commit 9278134e49b6bf4d6e05c40f63cc6d6d6936e01b
commit fd62123562c2b71f292d3d3ee1a085709048b11a
commit f348575edc915db9df89acfb3f292920726ffe9a

Signed-off-by: Jim Warner <james.warner@comcast.net>
library: dynamic buffer management even more efficient

One recent patch to dynamic buffer management involved
over-allocating the buffer increase to lessen calls to
xrealloc. That was successful, but the actual increase
amount did not attempt to optimize size or alignments.

With this commit, we'll copy an approach recently used
by the top program and round up buffer sizes to 1 KiB.
More importantly, while buffers are quickly reaching a
KiB optimum multiple, no memcpy will ever be employed!

To illustrate just how effective top's algorithm would
be, just change the initial and subsequent allocations
from the current 1024 bytes to just a single byte then
add an fprintf.  Those one byte reallocations while on
the way to optimum buffer size will be a one-time cost
and won't represent any recurring performance penalty.

( gosh, that top program *must be* one fart smeller, )
( or was that a smart feller, i can't remember which )

Reference)s):
commit 6d605f521c54a7011b7a255762621febda4f67e8
commit a45dace4b82c9cdcda7020ca5665153b1e81275f

Signed-off-by: Jim Warner <james.warner@comcast.net>
ps: possibility to display systemd unit for a process

Library systemd-login offers possibility to display
name of a systemd unit file for specific pid. Note that
not all processes are part of a system unit/service
(e.g. user processes, or kernel threads).

This patch adds output option "sd_unit" which will
show name of systemd unit or "-", when process does not
belong to any unit.

To maintain compatibility with non-systemd systems,
procps must be configured with --with-systemd option
to enable this option.
ps: possibility to display login session for a process

Library systemd-login offers possibility to display name
of login session for specific pid.
Note that not all processes are part of a login session
(e.g. system service processes, user processes that are shared
between multiple sessions of the same user, or kernel threads).

This patch adds output option "sd_session" which will
show name of session or "-", when process does not belong
to any session.

To maintain compatibility with non-systemd systems,
procps must be configured with --with-systemd option
to enable this option.