Commit Graph

416 Commits

Author SHA1 Message Date
Craig Small
5576c8e438 library: build on non-glibc systems
Some non-glibc systems didn't have libio.h or __BEGIN_DECLS
Changes to make it more standard.

References:
 issue #88
2018-04-10 21:28:11 +10:00
Craig Small
f46865eaf3 sysctl: fixup build system
Remove the external definition of the procio function.
2018-03-12 13:06:08 +11:00
Craig Small
c9be22a8c0 sysctl: Bring procio functions out of library
The procio functions that were in the library have been
moved into sysctl. sysctl is not linked to libprocps in
newlib and none of the other procps binaries would need
to read/write large data to the procfs.

References:
 be6b048a41
2018-03-01 21:25:04 +11:00
Craig Small
063838a7f5 docs: Change name of fprocopen man page
Add NEWS for sysctl large buffers
Rename manpage to fprocopen

References:
 be6b048a41
 procps-ng/procps!56
2018-02-28 21:24:03 +11:00
Werner Fink
e0ab7cff1f Add flexible buffered I/O based on fopencookie(3)
to be able to read and write large buffers below /proc.
The buffers and file offsets are handled dynamically
on the required buffer size at read, that is lseek(2)
is used to determine this size. Large buffers at
write are split at a delimeter into pieces and also
lseek(2) is used to write each of them.

Signed-off-by: Werner Fink <werner@suse.de>
2018-02-28 20:46:58 +11:00
Sven Eden
776b0791ba Add support for elogind
A session manager similar to logind from systemd.
See https://github.com/elogind/elogind

Signed-off-by: Lars Wendler <polynomial-c@gentoo.org>
2017-12-29 15:57:14 +11:00
James Clarke
bd72ba3a4b sig: Move runtime signal count check to compile time
Since the value of number_of_signals is known at compile time, we can
use a compile-time check instead. This also adds SIGLOST for the Hurd,
uses the correct signal counts for the Hurd and FreeBSD, and only gives
a compile-time warning when compiled on an unknown platform that it does
not know whether the number of signals is correct.
2017-12-23 17:48:36 +11:00
Jim Warner
0003d704ac library: relocate the typedef used in alloc.h override
There is no longer justification for placing a typedef
employed in overriding that alloc.h message handler in
the procps.h header file. So this commit just moves it
to the alloc.h header file itself where's it's needed!

[ gosh, sure wish i had thought to relocate this guy ]
[ when the changes in the 1st commit shown were made ]

Reference(s):
. most recent related changes
commit 18e5aecd2b
. place where it *should* have been relocated
commit 2865ded64e

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-12-23 17:41:37 +11:00
Jim Warner
18e5aecd2b top: exploit msg handler override to avoid corrupt tty
Way back in November of 2011, the library was equipped
with an overridable error message handler function. It
was done expressly for a program like top which alters
the tty. But that support was withdrawn shortly after.

This was all done in the lead up to v3.3.2. That's the
release where NLS support was added and it represented
a hectic time. In hindsight, the changes went too far.

So this commit, in a minimal fashion, restores ability
to address a potential fatal library error. After all,
any properly behaving library would never unilaterally
subject a caller to a stderr message and then an exit.

[ when exposing 1 variable in libprocps.sym, 2 other ]
[ existing symbols were repositioned alphabetically. ]

Reference(s):
. generalized library memory provisions
commit 7126cc4491
. top exploit library memory provisions
commit 88087ec5a5
. library xalloc type functions made private
commit 2865ded64e
. restored prior top memory logic
commit 05f5deb97c

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-12-20 21:07:44 +11:00
Kyle Laker
5979696ada whattime: Fix formatting
Update formatting within the if block to two spaces
2017-09-23 17:32:29 +10:00
Kyle Laker
325d68b7c3 whattime: Show 0 minutes in pretty output
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.
2017-09-23 17:32:29 +10:00
Wayne Porter
53e101452f Consolidated patch of previously merged CYGWIN support
The combined results of merge request #49 without that
overhead plus distortion in this repository's history.

Prototyped-by: Wayne Porter <wporter82@gmail.com>
2017-09-03 20:59:23 +10:00
Jim Warner
1a2ec0390a library: set stage for NUMA node field display support
In response to that suggestion referenced below, these
changes allow display of task/thread level NUMA nodes.

Currently, only the 'top' program offers any NUMA type
support and it is limited to the Summary Area display.
With this commit both the 'top' and 'ps' programs will
be able to display NUMA nodes associated with threads.

[ this patch has been adapted from the newlib branch ]
[ and implemented so as to preserve the existing ABI ]

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
629fa81b57 misc: eliminate all those remaining gcc -Wall warnings
Reference(s):
proc/readproc.c: In function 'statm2proc'
proc/readproc.c:627:9: warning: variable 'num' set but not used [-Wunused-but-set-variable]

ps/output.c: In function 'pr_context':
ps/output.c:1273:14: warning: unused variable 'tried_load' [-Wunused-variable]
ps/output.c:1272:16: warning: unused variable 'ps_is_selinux_enabled' [-Wunused-variable]
ps/output.c:1272:16: warning: 'ps_is_selinux_enabled' defined but not used [-Wunused-variable]
ps/output.c:1273:14: warning: 'tried_load' defined but not used [-Wunused-variable]
ps/output.c:1837:18: warning: 'shortsort_array_count' defined but not used [-Wunused-const-variable=]
ps/output.c:1803:18: warning: 'aix_array_count' defined but not used [-Wunused-const-variable=]

ps/parser.c: In function 'arg_type':
ps/parser.c:1098:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
ps/parser.c:1099:34: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'

ps/sortformat.c: In function 'format_parse':
ps/sortformat.c:241:1: warning: label 'out' defined but not used [-Wunused-label]

ps/stacktrace.c:176:13: warning: 'stack_trace_sigsegv' defined but not used [-Wunused-function]

watch.c: In function 'process_ansi':
watch.c:234:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
watch.c:237:2: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the 'if'

Signed-off-by: Jim Warner <james.warner@comcast.net>
2017-05-22 21:34:32 +10:00
Jan Rybar
19649938ec Merge branch 'fix-99d71ad' into 'master'
Fix 99d71ad

My previous patch has a regression. Please merge the fix of regression.

This is based on the following post.
http://www.freelists.org/post/procps/fix-regression-created-by-99d71ad

See merge request !29
2016-12-20 15:01:18 +00:00
Jim Warner
dc8e89119a misc: remove some trailing whitespace newly introduced
The commit (merge) referenced below added some useless
trailing whitespace, and this patch will correct such.

[ this also updates the NEWS file for the buglet fix ]

Gosh, if folks cannot coax their editors into avoiding
such crap they should remove the '.sample' suffix from
their '.git/hooks/pre-commit.sample' file. Thereafter,
git itself will reject changes with whitespace errors.

Reference(s):
commit cc1f49aeba

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-12-07 21:50:59 +11:00
Jan Rybar
fc7f60a6bc ps: removed stripping of prefixes off wchan data
resolves Red Hat Bugzilla #1322111
2016-11-22 16:58:14 +01:00
Takayuki Nagata
23ba442c88 libprocps: use float to calculate %use of slabtop
In some environments, 100 * nr_active_objs is calculated at first,
and the result of lower 32bits is divided by nr_objs. This occurs
even in a 64-bit architecture. So nr_active_objes > 42949672, %use
will be incorrect.

This fix casts type of nr_active_objs to float to calculate
correctly the %use in 32-bit/64-bit architectures.

Signed-off-by: Takayuki Nagata <tnagata@redhat.com>
2016-10-12 16:59:01 +09:00
Takayuki Nagata
636b48efd8 Revert "bprocps: fix order of operations for %use of slabinfo"
This reverts commit 99d71ad581.

When nr_active_objs / nr_objs is calculated, the result will be 1
or 0 since the variables are integer. So the commit is wrong.
2016-10-12 16:58:56 +09:00
Olof Sivertsson
586bfb7655 kill: Fix free() with bad pointer on SIG-prefixed signal-name
kill -l SIGHUP (or any other signal-name prefixed with "SIG")
would cause free() to be called with a bad pointer instead of
a pointer to what was allocated. Fix this and add test-case.
2016-09-08 22:32:18 +02:00
Jon Boden
8abd0c92ab library: Don't use SIGPWR on FreeBSD
FreeBSD doesn't have SIGPWR so makes no sense in warning and assuming
its 29.

References:
 https://bugs.debian/org/832148

Signed-off-by: Craig Small <csmall@enc.com.au>
2016-08-28 19:14:32 +10:00
Jim Warner
67a634dc4c library: revert one ancient 'escape_str_utf8' deletion
Profiling revealed a large amount of time spent in the
'escape_str_utf8' function (escape.c) with both of our
NLS branches (newlib and master). That same result was
not seen under an ancient top-3.2.8 program & library.

Well, the 3.2.8 result was ultimately explained by the
absence of a 'setlocale', necessary under NLS support.
Thus, when that ancient library tested for locale, all
it got was 'ANSI_...' & assumed 'UTF-8' wasn't active.

But after a hack to that ancient code to place it on a
par with newlib/master, I still found cost differences
that led me to revisit an old change referenced below.

It turns out that 'iswprint' costs far more than would
a call of 'isprint', even with the extra support code.
So this commit just reverts that five year old change.

[ this patch parallels a similar change under newlib ]

Reference(s):
commit 7b0fc19e9d

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-08-23 21:12:32 +10:00
Craig Small
1955657461 Merge branch 'find_elf_note_fix' into 'master'
Fixing invalid reads in find_elf_note due to setenv invocation

Resolves issue on mailing list from 12 Nov 2014 and Red Hat Bugzilla 1163404.

See merge request !20
2016-08-15 11:08:15 +00:00
Jan Rybar
ecabdaca41 Fixing invalid reads in find_elf_note due to setenv invocation
Resolves issue on mailing list and Red Hat Bugzilla 1163404.
2016-08-05 15:21:49 +02:00
Jan Rybar
c63a5a4af0 Fixing is_disk() which mistakes devices with name longer than 20 chars for partitions.
Associated with previous vmstat -d enhancement commit.
2016-08-04 13:55:01 +02:00
Craig Small
2e4959bab8 library: dont use vm_min_free on non-Linux systems
For a specific slice of kernel versions we can get a better
estimate of the available memory before the "real" available
figure appears around kernel 3.2

However, that middle method requires a /proc/sys/vm directory.
FreeBSD 9.x used to emulate a < 2.6.27 kernel procfs meaning
it never tried the middle method. FreeBSD 10.x emulates something
more modern, but without the available figure and without a
/proc/sys/vm, so the library falls into a hole.

Hurd may to one day have this bug so we'll exclude him as well
as its triggered by whatever number appears in
/proc/sys/kernel/osrelease

References:
 commit 3f3b1a59ad
 https://bugs.debian.org/831396
2016-07-17 09:06:24 +10:00
Jim Warner
25a6ecdbfb library: avoid QUICK_THREADS, swat Redhat bug #1284091
For this release, what's likely to be our last oldlib,
we really no longer care when top or ps threads access
is made a little less efficient. This is especially so
when efficiency was gained at the expense of accuracy.

The newlib branch already has turned off QUICK_THREADS
so this patch just brings the master branch into line.

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

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-07-09 13:23:27 +10:00
Craig Small
639c58312b library: rename clashing pwcache functions
On MacOS the system already has user_from_uid and group_from_gid.
These are renamed pwcache_get_user and pwcache_get_group.

For the old library, pwcache_get_user needs to be exported
for skill.

References:
 https://gitlab.com/procps-ng/procps/issues/34

Signed-off-by: Craig Small <csmall@enc.com.au>
2016-07-06 22:26:02 +10:00
Jim Warner
5d54dc0d2e library: play catchup with a new proc_t 'cgname' field
Since we're about to break the ABI/API anyway, why not
go ahead and add yet another field to our proc_t which
the newlib branch has had for awhile. This then allows
the top program to offer 'control group name' and will
also permit a few reductions in that ps program logic.

And let's also clean up some unrelated warnings below.

Clang warnings:
proc/readproc.c:1178:50: warning: address of array 'ent->d_name' will always evaluate to 'true' [-Wpointer-bool-conversion]
    if(unlikely(unlikely(!ent) || unlikely(!ent->d_name))) return 0;
                                           ~~~~~~^~~~~~
proc/readproc.c:1205:50: warning: address of array 'ent->d_name' will always evaluate to 'true' [-Wpointer-bool-conversion]
    if(unlikely(unlikely(!ent) || unlikely(!ent->d_name))) return 0;
                                           ~~~~~~^~~~~~

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-07-06 21:33:17 +10:00
Simon Tatham
365cb37029 library: find tty device name of process quicker
The procps library attempts to work out the tty of a process
through several methods. For things like /dev/tty123 or
/dev/foo it works fine.

For tty devices that put the minor number in a directory
of the major name this fails. So then we have to fallback
to stating things like the processes STDERR and try again.

Considering a lot of processes sit on ttys such as
/dev/pts/3 this is a lot of wasted time. At the point of
entering driver_name we know "/dev/pts" and we know "3"
we just didn't join them up the right way as this is old
code.

This change now looks for /dev/pts/3 as well. It does it
after looking for /dev/pts3 so the behaviour is the same.

References:
 https://bugs.debian.org/770215

Signed-off-by: Craig Small <csmall@enc.com.au>
2016-07-03 10:08:18 +10:00
Jan Rybar
47497dd240 - Fixing sysinfo - devices with length exceeding 15 chars are not displayed in vmstat -d 2016-06-30 18:29:50 +02:00
Jim Warner
32db4e99a6 library: make sure that the proc_t is now fixed length
The former variable length structure created potential
problems for library users like that referenced below.

We will now parallel the same approach newlib uses for
the configure options --enable-oomem & --with-systemd.
Thus, the --enable-oomem and OOMEM_ENABLE #define have
been eliminated and the --with-systemd option (#define
WITH_SYSTEMD) will hereafter impact one function only.

The proc_t struct itself will now *never* be impacted.

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

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-06-07 20:49:30 +10:00
Jim Warner
cb0e210930 library: exploit 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
Takayuki Nagata
99d71ad581 bprocps: fix order of operations for %use of slabinfo
In some environments, 100 * nr_active_objs is calculated at first,
and lower 32bit of the result is divided by nr_objs.
If 100 * nr_active_objs > 42949672, %use will be incorrect.

Signed-off-by: Takayuki Nagata <tnagata@redhat.com>
2016-04-25 20:20:08 +10: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
Craig Small
05d751c4f0 free: use SReclaimable in cached
The previous commit added all of slab into the cache value. The
thing was is cached in this context is something you can get
back and reclaim if under memory pressure.

The problem was slab parameter includes both reclaimable and
unreclaimable values which doesn't make sense in this context.
This commit make cached only use the reclaimable component.

References:
 http://www.freelists.org/post/procps/OmegaPhilxxxxxxxxxxxxx-Bug799716-free-considers-cached-to-include-SUnreclaim
 https://github.com/brndnmtthws/conky/issues/130
 https://bugs.debian.org/799716

Commits:
 6cb75efef8
2015-10-24 14:21:23 +11:00
Jim Warner
4129c758ac miscellaneous: remove some trailing whitespace buildup
wish folks (craig) would use these in their .gitconfig

[core]
  whitespace = trailing-space, space-before-tab, blank-at-eof
[apply]
  whitespace = warn

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-06-20 07:46:23 +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
3600f652e8 documentation: fix man pages due to refactor for wchan
This patch will bring three of our man pages into line
with the recent refactor of the libprocps wchan logic.

[ and also eliminates more damn eol whitespace which ]
[ snuck in our repo with the commit referenced below ]

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

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-06-19 19:09:21 +10:00
Jim Warner
6b8dc5511f library: refactor and rely on modern kernels for wchan
Several Debian based distributions were recently found
to have omitted a kernel configuration option that had
the effect of rendering /proc/#/stat and /proc/#/wchan
useless for providing any 'sleeping in function' info.

That problem also prompted a reevaluation of the whole
approach to wchan matters which had grown increasingly
complex as our library evolved over the last 13 years.

The net result was a decision to rely on /proc/#/wchan
which arrived along with the 2.5 kernel. This then let
us vastly simplify the internal code plus the external
interface which will benefit both the top and ps pgms.

Reference(s):
http://www.freelists.org/post/procps/WCHAN,11
https://lkml.org/lkml/2008/11/6/12
https://bugs.debian.org/711592

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
0557504f9c library: add support for displaying LXC container name
This commit adds a lxc container name to every proc_t.
If a process is not running in a container, then a '-'
will be provided, making such a field always sortable.

Unlike other proc_t character pointers, lxc containers
will find many duplicate shared values. So rather than
strdup 'em (with a later free required upon reuse), we
try to keep track of those already seen and share that
address among all tasks running within each container.

We rely on the lines in the task's cgroup subdirectory
which may initially seem somewhat unsophisticated. But
the lxc library itself uses a similar approach when it
is called to list active containers. In that case, the
/proc/net/unix directory is parsed for the '/lxc' eye-
catcher, with potential complications from hashed path
and names that are too long (something we don't face).

[ too bad docker abandoned lxc - our commit won't do ]
[ anything for the users of those kind of 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:05 +10:00
Jim Warner
96bce4e11e library: address memory aberration with LXC containers
Under a lxc container, the /proc/meminfo 'MemFree' and
'MemAvailable' amounts will be equal, unless memory is
being limited via cgroups in which case 'MemAvailable'
could exceed that for 'MemTotal'. And when a container
has been nested, there exist additional memory quirks.

A program might then display used or available amounts
greater than total memory (assuming unsigned honored),
or negative values (should a signed cast be employed).

This anomaly primarily impacted the top and free pgms.
Thus, two simple sanity checks have been introduced to
avoid any illogical kb_main_available or kb_main_used.

( Busybox top & free also display anomalous although )
( different results when running in a lxc container. )

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

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-06-14 15:36:05 +10:00
Filipe Brandenburger
c1c73c0d00 build-sys: merge automake subdirs into toplevel
This will be required for subdir-objects, otherwise automake will have
problems with more than one Makefile.am having rules to build the same
files.

Tested that it builds and both `make check` and `make distcheck` work.

Tested `make install` and compared the tree with the one installed
before this commit, both installed the binaries to the same locations.
The binaries are also in the same location in the build tree (for
instance, ps/pscommand is still there.)

Checked the binaries for the correct libraries linked into them. Binary
sizes matched before and after this change.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
2015-05-01 23:19:31 -07:00
Filipe Brandenburger
90cc5460aa build-sys: add $(top_srcdir) to include search dir
This is required for out-of-tree build to work, since many source files
include e.g. proc/*.h which is not under the include/ directory.

Tested that `make distcheck` starts working after this patch.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
2015-05-01 17:09:55 -07:00
Jaromir Capik
3477439278 3.3.10 API 2014-09-09 18:35:44 +02:00
Fredrik Fornwall
00279d692a Use <dirent.h> instead of <sys/dir.h>
Using <dirent.h> and struct dirent instead of <sys/dir.h> and struct direct
is preferred and works on Android which lacks sys/dir.h.

See:
http://pubs.opengroup.org/onlinepubs/009695399/basedefs/dirent.h.html
2014-08-26 16:01:57 +02:00
Jim Warner
bcbc3c5a02 misc: result after checking all files for misspellings
Reference(s):
https://github.com/lyda/misspell-check.git

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-08-08 22:14:21 +02:00
Jaromir Capik
2538b5ac03 library: increasing meminfo()/namebuf size from 16 to 32 2014-08-05 19:15:03 +02:00
Jaromir Capik
6cb75efef8 library: cached += slabs, used -= cached + buffers
From now we include slabs in cached
and exclude buffers and cached from used.
2014-07-31 15:10:42 +02:00
Jaromir Capik
3f3b1a59ad library: MemAvailable fallback now uses /proc/meminfo
Taking the values from /proc/vmstat was unnecessary
and prone to race conditions.
2014-07-31 15:10:42 +02:00
Jaromir Capik
784c6eda1c library: use LINUX_VERSION macro in the MemAvailable fallback 2014-07-22 18:18:51 +02:00
Jaromir Capik
cdc95efe74 library: fix kb_slab_*reclaimable names and export both 2014-07-22 13:52:11 +02:00
Jim Warner
c437faf8d3 library: evolve MenAvailable algorithm on older kernel
Let's not report zero for kb_main_available when older
kernels don't have MemAvailable. Instead, if we simply
duplicate the 'free' amount we can avoid all ancillary
problems, such as those involving top's graphing mode.

Reference(s):
http://www.freelists.org/post/procps/kb-main-available-etc,3

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-21 16:17:52 +02:00
Jim Warner
e4f0b4ebf3 library: tweak newly added MemAvailable fall-back code
This commit just ensures recalculation of some amounts
for iterative processes, like top. It also trades some
repeated runtime calls to sysconf for a one time cost.

Reference(s):
http://www.freelists.org/post/procps/systemd-support-to-library,7
. fall-back calculations
commit b779855cf1

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-18 20:49:57 +02:00
Jim Warner
6c148b4f8b docs: with systemd now in library, remember openproc.3
[ plus remove just a little darn trailing whitespace ]

Reference(s):
. systemd migrated to library
commit 9d8ad6419f
. added library documentation
commit a74fb8fade

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-18 20:49:57 +02:00
Jim Warner
1da2c98937 library: disable a potential 'ELF note' is missing msg
The stderr message regarding ELF notes appears on some
systems (openSUSE-13.1 for example) but I have not yet
isolated why. Since at startup we go on to determine a
Hertz value the old fashion way, this patch just turns
off the useless message until the cause is understood.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-17 13:31:06 +02:00
Jim Warner
9d8ad6419f library: generalize then add former 'ps' systemd logic
Signed-off-by: Jim Warner <james.warner@comcast.net>
2014-07-17 13:31:06 +02:00
Jaromir Capik
b779855cf1 library: fallback MemAvailable evaluation if missing
This commit adds support for fallback calculation
of the MemAvailable field if not exported by the
kernel. The MemAvailable field appeared in kernel
3.14, but it's possible to calculate it from other
fields since 2.6.27 (splitLRU changes).
2014-07-15 19:17:02 +02:00
Jaromir Capik
d75d8addc6 library: additional comments to the buffer size increase 2014-07-14 19:44:14 +02:00
Jaromir Capik
b2ad21990a library: fixing buffer sizes in sysinfo.c 2014-07-14 19:07:25 +02:00
Jaromir Capik
d4ddc96bc1 library: changing P_G_SZ from 20 to 33
Nowadays the usernames can be 32 characters long
(typically OpenShift usernames use the whole length)
and the old limit was preventing us from processing
them correctly.
The macro change affects the proc_t structure size.
2014-07-14 16:21:52 +02:00
Jaromir Capik
0393047a4f library: removing note about PROC_{PID,UID} being obsolete 2014-07-14 16:12:53 +02:00
Jaromir Capik
a74fb8fade docs: adding openproc(), readproc() and readproctab() man 2014-07-14 16:07:23 +02:00
Jaromir Capik
ba6396f886 free: support for MemAvailable
This commit adds a new switch -a/--available that
appends a new column called 'available' to the
output. The column displays an estimation
of how much memory is available for starting
new applications, without swapping. Unlike the data
provided by the 'cached' or 'free' fields, this
field takes into account page cache and also that
not all reclaimable memory slabs will be reclaimed
due to items being in use.
2014-07-11 22:34:06 +02:00
Jaromir Capik
2f96eef7f8 library: reverting tmpfs subtraction from cached (18-FEB-2014)
The subtraction was marked as reinforcing the misconception,
that memory in the page cache can be considered free.
The Cached value is not a sum of page cache and tmpfs,
as the tmpfs memory lives in the page cache and therefore
it's an inseparable part of it.
2014-04-30 13:59:34 +02:00
Jakob Unterwurzacher
3569c0351f library: properly handle memory used by tmpfs
tmpfs has become much more widely used since distributions use it for
/tmp (Fedora 18+). In /proc/meminfo, memory used by tmpfs is accounted
into "Cached" (aka "NR_FILE_PAGES",
 http://lxr.free-electrons.com/source/mm/shmem.c#L301 ).

The tools just pass it on, so what top, free and vmstat report as
"cached" is the sum of page cache and tmpfs.

free has the extremely useful "-/+ buffers/cache" output. However, now
that tmpfs is accounted into "cached", those numbers are way off once
you have big files in /tmp.

Fortunately, kernel 2.6.32 introduces "Shmem", which makes tmpfs memory
usage accessible from userspace (
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=4b02108ac1b3354a22b0d83c684797692efdc395 ).

This patch substracts Shmem from Cached to get the actual page cache
memory. This makes both issues mentioned above disappear. For older
kernels, Shmem is not available (hence zero) and this patch is no-op.

Additionally:
* Update the man pages of free and vmstat to explain what is happening
* Finally drop "MemShared" from the /proc/meminfo parser, it has been
  dead for 10+ years and is only causing confusion ( removed in kernel
  2.5.54, see
  https://git.kernel.org/cgit/linux/kernel/git/tglx/history.git/commit/?id=fe04e9451e5a159247cf9f03c615a4273ac0c571 )
2014-02-27 14:07:10 +01:00
Craig Small
5a34ff0a99 Check for presence of disks in vmstat
vmstat -d or vmstat -p would crash mysteriously under different
circumstances. The problem was eventually tracked down to /sys not
being mounted which meant is_disk() always returned false.
The partition would then be attempted to be linked to a non-existent
disk causing a segfault.

vmstat will now not link to a disk if none exists.
The change in testing will skip those tests when /sys/block doesn't
exist.

Many thanks to Daniel Schepler for his analysis and suggestions.

Bug-Debian: http://bugs.debian.org/736628
2014-01-29 22:22:11 +11:00
Jaromir Capik
ae9676a337 library: skip replacement of trailing '\0' in read_unvectored()
Under some circumstances the ksh shell doesn't fork new processes
when executing scripts and the script is interpreted by the
parent process. That makes the execution faster, but it means
ksh needs to reuse the /proc/PID/cmdline for the new script name
and arguments while the file length needs to stay untouched.
The fork is skipped only when the new cmdline is shorter than
the parent's cmdline and the rest of the file is filled
with '\0'. This is perfectly ok until we try to read the cmdline
of such process. As the read_unvectored() function replaces
all zeros with chosen separator, these trailing zeros are replaced
with spaces in case of the ps tool. Consequently it appends
multiple spaces at the end of the arguments string even when these
zeros do not represent any separators and therefore shouldn't
be replaced.
With this commit the read_unvectored() function skips the
replacement of trailing zeros and separates valid content only.

Reference: https://bugzilla.redhat.com/show_bug.cgi?id=1057600
2014-01-24 18:32:20 +01:00
Jaromir Capik
38cbeedeb7 library: fixing uninitialized variable 'pos' in whattime.c 2014-01-02 18:21:31 +01:00
Craig Small
85fff468fa Update the library version to 3:0:0
We have had some API changes which means the library version needs to
be incremented.
2013-12-03 22:16:18 +11:00
Jim Warner
583cdaca1a library: normalize recently added namespaces interface
While 'invisible' thread subdirectories are accessible
under /proc/ with stat/opendir calls, they have always
been treated as non-existent, as is true with readdir.

This patch trades the /proc/#/ns access convention for
the more proper /proc/#/task/#/ns approach when thread
access is desired. In addition some namespace code has
been simplified and made slightly more efficient given
the calloc nature of proc_t acquisition and its reuse.

Reference(s):
commit a01ee3c0b3

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-11-25 20:57:32 +11:00
Craig Small
71305c095a Fix integer overflow in getstat()
Merge request 16
2013-09-11 21:57:10 +10:00
Craig Small
dd6f24dbed Merge commit 'refs/merge-requests/13' of git://gitorious.org/procps/procps into merge-requests/13
Conflicts:
	pgrep.c
	ps/output.c
	ps/ps.1
2013-09-11 21:34:05 +10: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
Adrian Brzezinski
13f20a4811 free: reusing 'shared' for Shmem
Previously the shared memory column was always zero
for 2.6 series kernels (and later) due to the fact,
that the value was taken from the MemShared entry
that disappeared with 2.6 series kernels.
Later a new Shmem entry appeared in the /proc/meminfo
file and the 'shared' column now displays either
the MemShared or the Shmem value (depending on their
presence - the presence is mutually exclusive).
If none of the two entries is exported by the kernel,
then the column is zero.
2013-09-09 16:54:00 +02:00
Jaromir Capik
827fc0302e free: clarification of credits for the Shmem support
An unpleasant thing happened when I comitted the shmem support
for the 'free' tool. We already had a merge request from
Adrian Brzezinski in the queue, doing exactly the same.
As Adrian deserves credits, I'm reverting the change
and re-applying with the next commit in order to make
him a part of the project history.
2013-09-09 16:54:00 +02:00
Jaromir Capik
9315d00f01 free: reusing 'shared' for Shmem
Previously the shared memory column was always zero
for 2.6 series kernels (and later) due to the fact,
that the value was taken from the MemShared entry
that disappeared with 2.6 series kernels.
Later a new Shmem entry appeared in the /proc/meminfo
file and the 'shared' column now displays either
the MemShared or the Shmem value (depending on their
presence - the presence is mutually exclusive).
If none of the two entries is exported by the kernel,
then the column is zero.
2013-08-07 18:21:43 +02:00
Vadim Ushakov
5c9c7c8b1f Fix overflow of "running" value in getstat()
It seems in some cases procs_running field of /proc/stat can contain 0 even if vmstat itself is running. At least this can be reproduced on Linux 3.9.3 compiled with BFS scheduler.

Since getstat() decrements value of procs_running by 1, we get overflow:

$ vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa
 0  0 667732 918996  57376 911260   21   30    36    40   98   45 14 82  4  1
 4294967295  0 667728 916716  57376 911264    8    0     8     0 1958 3733 28  7 65  1
 0  0 667700 915996  57376 911416   24    0   152     0 1735 3600 23  5 71  1
 4294967295  0 667700 915872  57376 911392    0    0     0     0 1528 3165 21  4 76  0
2013-06-11 12:09:05 +08:00
Craig Small
ce0539ecac 3.3.8 NEWS and API
NEWS mentions systemd unit support for ps

Library REVISION (internal change only) incremented

Signed-off-by: Craig Small <csmall@enc.com.au>
2013-05-26 08:03:01 +10:00
Markus Mayer
a6c7923106 Fix btime handling reading from /proc/stat
Function getbtime() currently makes the assumption that btime==0 equals
btime not being present in /proc/stat. This is not quite accurate, as
timestamp 0 is, in fact, also a valid time (Epoch), and /proc/stat may
report it as such.

We introduce a flag to indicate whether btime was found in /proc/stat.
In this way, btime==0 becomes a valid case, provided /proc/stat
actually reports this as the boot time.

procps can still detect the case of btime actually not being reported
by the kernel.

Signed-off-by: Markus Mayer <mmayer@broadcom.com>
2013-05-12 07:17:07 +10:00
Jim Warner
95d0136281 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 6d605f521c
commit a45dace4b8

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-04-24 08:29:22 +10:00
Aristeu Rozanski
a01ee3c0b3 procps: add support for linux namespaces
Each process in Linux has a /proc/<pid>/ns directory which contains
symbolic links to pipes that identify which namespaces that process
belongs to. This patch adds support for ps to display that information
optionally.

Signed-off-by: Aristeu Rozanski <arozansk@redhat.com>
2013-04-16 15:05:21 -04:00
Jim Warner
7888f6a679 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 fe75e26ab6

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-04-07 18:05:01 +10:00
Jim Warner
526bc5dfa9 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 a45dace4b8
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>
2013-04-07 17:35:49 +10:00
Jim Warner
6d605f521c 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 a45dace4b8

Signed-off-by: Jim Warner <james.warner@comcast.net>
Signed-off-by: Craig Small <csmall@enc.com.au>
2013-04-07 17:35:49 +10:00
Craig Small
fc503b442d Update library version-info to 2.1.1
Internal changes to libproc means the revision number
is incremented. This does not mean an ABI or API change has
occured, we just do the stuff under the covers better or in this
case reduce the compile warnings mainly.

See Jim, I do read the commit messages :)
2013-03-26 21:41:55 +11:00
Gilles Espinasse
a75f698977 procps-ng : fix readproc gnu_scanf format warnings
readproc.c: In function 'stat2proc' :
readproc.c:516: warning: use of assignment suppression and length modifier together in gnu_scanf format
readproc.c:516: warning: use of assignment suppression and length modifier together in gnu_scanf format

Signed-off-by: Gilles Espinasse <g.esp@free.fr>
2013-03-26 20:53:35 +11:00
Gilles Espinasse
46e47a527f procps-ng : fix multi-line comment warnings
slab.c:110:1: warning: multi-line comment
slab.c:115:1: warning: multi-line comment
slab.c:122:1: warning: multi-line comment
slab.c:127:1: warning: multi-line comment

Signed-off-by: Gilles Espinasse <g.esp@free.fr>
2013-03-26 20:51:37 +11:00
Jim Warner
a45dace4b8 library: utility buffers now immune to buffer overflow
A recent Debian bug report, dealing with release 3.2.8
and its even more restrictive buffer sizes (1024) used
in stat, statm and status reads via file2str calls, is
a reminder of what could yet happen to procps-ng. Size
needs are determined by kernel evolution and/or config
options so that bug could resurface even though buffer
size is currently 4 times the old procps-3.2.8 limits.

Those sizes were raised from 1024 to 4096 bytes in the
patch submitted by Eric Dumazet, and referenced below.

This patch makes libprocps immune to future changes in
the amount of stuff that is ultimately found in a proc
'stat', 'statm' or 'status' subdirectory. We now trade
the former static buffer of 4096 bytes for dynamically
allocated buffers whose size can be increased by need.

Even though this change is solely an internal one, and
in no way directly affects the API or the ABI, libtool
suggests that the LIBprocps_REVISION be raised. I hope
Craig remembers to do that just before a next release.

We don't want a repeat of the procps-ng-3.3.4 boo-boo,
but with no API/ABI impact that probably can't happen.

p.s. A big thanks to Jaromir Capik <jcapik@redhat.com>
who reviewed my original version and, of course, found
some of my trademark illogic + unnecessary code. After
his coaxing, he helped make this a much better commit.

Reference(s):
. procps-3.2.8
http://bugs.debian.org/702965
. allow large list of groups
commit 7933435584

Signed-off-by: Jim Warner <james.warner@comcast.net>
Reviewed by:   Jaromir Capik <jcapik@redhat.com>
2013-03-23 16:00:02 +01:00
Jim Warner
fac3b34ff9 miscellaneous: fixed current misspell-check's findings
Reference(s):
https://github.com/lyda/misspell-check

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-14 12:36:47 +01:00
Jim Warner
fe75e26ab6 miscellaneous: clean up trailing whitespace throughout
The entire tree's polluted with inappropriate trailing
whitespace. This commit rids our environment of all of
those useless keystrokes. Unfortunately, it sure ain't
a permanent solution and requires every contributor to
instruct their editor(s) to prevent or eliminate them.

Plus it's strongly recommended we all insert something
like what's shown below to our '.gitconfig' file so as
to provide at least some warnings when we try to apply
any patches (git am) that do contain the #@!%& things!

References(s):
~/.gitconfig excerpt ---------------------------------
[core]
  whitespace = trailing-space, space-before-tab, blank-at-eof
[apply]
  whitespace = warn
--------------------------------- ~/.gitconfig excerpt

Signed-off-by: Jim Warner <james.warner@comcast.net>
2013-03-14 12:36:47 +01:00
Craig Small
f7c418155a Expose freeproc for libproc
freeproc was missing from the libproc API which meant while you could
allocate proc structures, you couldn't free them!

Bug-Debian: http://bugs.debian.org/681653
2013-01-01 13:13:44 +11:00
Sami Kerola
c043c47ddd pmap: use correct types for memory allocation
Fixes error which did not happen always.  Changes of being affected by
the bug where greater the more there where pids defined as pmap argument.
The debian bug referral can almost certainly reproduce the problem,
especially when tried multiple times in row.

pmap: malloc.c:3096: sYSMALLOc: Assertion `(old_top == (((mbinptr)
(((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct
malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >=
(unsigned long)((((__builtin_offsetof (struct malloc_chunk,
fd_nextsize))+((2 * (sizeof(size_t))) - 1)) & ~((2 * (sizeof(size_t))) -
1))) && ((old_top)->size & 0x1) && ((unsigned long)old_end & pagemask) ==
0)' failed.

Reported-by: lee <lee@yun.yagibdah.de>
Bug-Debian: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=688180
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-11-06 22:22:11 +11:00
Craig Small
0c74162049 Bump the soname 2012-10-30 21:34:40 +11:00
Eric Dumazet
7933435584 ps: allow large list of groups
Current linux kernels output no more than 32 groups
in /proc/{pid}/status.

Plan is to increase this limit.

This patch allows ps to not core dump if the buffer used to read status
file was too small.

# ps aux
Signal 11 (SEGV) caught by ps (procps-ng version 3.3.3).
ps:display.c:59: please report this bug

Also increases the size of the buffer from 1024 to 4096, since even with
32 groups we are close to the limit.

cat /proc/12731/status | wc
     39     128     961

Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
2012-10-24 21:43:37 +11:00
Jim Warner
6c8e9d9581 library: fix proc_t page fault delta counts alignment
When the maj_delta and min_delta fields were added to
the proc_t, they necessitated some compiler generated
padding bytes.

With this slight reordering, those padding bytes are
no longer generated.  And since the original commit
already broke the library ABI, now is an opportune
time to correct that misalignment.

Reference:
commit 7753bd1004

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-10-02 20:56:39 +10:00
Dimitrios Apostolou
faec340719 Two new options for pmap, -X and -XX
Both options provide more information about a process using -X and -XX
flags. The data comes from /proc/PID/smaps so it may vary.

Signed-off-by: Craig Small <csmall@enc.com.au>
2012-09-27 22:08:04 +10:00
Jim Warner
7753bd1004 library: adapt proc_t for top 'page fault delta' counts
Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-29 17:37:11 +10:00
Jim Warner
348e6091cb library: add a single vector string choice for 'environ'
In preparation for top scrollable environment display,
the new flag PROC_EDITENVRCVT was added to mirror the
existing single vector string handling for cgroup and
cmdline.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-29 17:34:54 +10:00