Commit Graph

444 Commits

Author SHA1 Message Date
Jim Warner
90753e2d5b library: remove the ull_int result type, <MEMINFO> api
Because of the vast quantities of virtual memory which
may be allocated, it initially seemed like a good idea
to provide for a widest possible range through the use
of a 'ull_int' result type. However, on second thought
the implementation was a bit flawed for these reasons:

. that underlying meminfo_data variable 'VmallocTotal'
is 'unsigned long' not a required 'unsigned long long'

. there wasn't a convenient way to value it since each
variable was set with a strtoul() call, not strtoull()

So this patch will standardize on the 'ul_int' results
type (and reduce the associated delta to 's_int' too).
For now, we'll rely on protections under a 64-bit arch
where a 'ull_int' & 'ul_int' yield identical capacity.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-05-12 21:15:01 +10:00
Jim Warner
fac5e6fea0 library: allow negative delta values for 2, <STAT> api
A recent buglet in the <meminfo> interface, where many
delta values could legitimately be negative, suggested
a review of this module where a minus was forced to 0.

As it turns out, there are two delta items that indeed
could be negative. They involve the current processes.

So henceforth, DELTA_PROC_BLOCKED & DELTA_PROC_RUNNING
will now be allowed to go negative. I believe that all
other items can only grow. But, if we find more later,
at least the adaptation approach has been established.

[ this whole business of checking for less than zero ]
[ harks back to an old kernel anomaly where negative ]
[ tics were sometimes experienced. top was affected. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-05-12 21:13:47 +10:00
Jim Warner
93a60022dc library: ain't like your father's delta, <MEMINFO> api
When the code for DELTA values (among other stuff) was
stolen from the recently revised <stat> interface, the
concept of ever growing values was propagated too. But
here we must manage both growing and shrinking values.

Thus former protections against a negative delta don't
have any place in this module and are hereby banished.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-05-12 21:13:47 +10:00
Craig Small
b4beb162fd library: minor fix for procps_meminfo_select
Thus function returns a pointer, not an int, so if there is
an error return NULL and not -errno.

proc/meminfo.c: In function ‘procps_meminfo_select’:
proc/meminfo.c:994:20: warning: return makes pointer from integer
without a cast [-Wint-conversion]
             return -ENOMEM;

References:
 commit 407f1b71de
2016-05-12 07:52:36 +10:00
Jim Warner
407f1b71de library: improve/normalize an interface, <MEMINFO> api
This represents the refinement of this interface after
the <stat> API was redesigned. We now follow a pattern
of 'get' for single item retrieval & 'select' for when
multiple items are desired, with just 1 function call.

And again following the <stat> lead this interface now
provides for delta values encompassing most items. The
reason I went cuckoo nuts with those deltas is because
they are essentially free. At the cost of a little RAM
and just one memcpy there's no other price to be paid.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-05-12 07:51:10 +10:00
Jim Warner
5ec5002b0d library: lift item restrictions on 'get()', <STAT> api
In the commit referenced below it was acknowledged the
procps_stat_get() function will intentionally restrict
returned values by excluding DELTA items among others.

Upon reflection that decision seemed rather arbitrary,
and so has now been lifted. And, while the initial use
of a DELTA will return 0, subsequent calls to that get
function will now return the difference (providing one
second, at least, has elapsed between any such calls).

Reference(s):
. reference to design decisions
commit abc71a46ad

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-05-12 07:51:10 +10:00
Jim Warner
1417ba56b5 library; add more of my gratuitous changes, <STAT> api
This commit is just my usual tweaking after an initial
submission, once the dust has settled & some more desk
checking was performed. Here are the changes included:

. get function need not check the 'stat_was_read' flag
( first time in save_sec == 0 so branch always taken )

. some table logic appeared outside the proper section
. cleanup_stack's loop made to work like assign_result
. eliminated an include of procps.h from stat.h header
. removed 'ext_numitems' from the stacks_extent struct
. changed the alignment of three prototypes for stat.h
. reorganized the pointers for 'stacks_extents' struct
. improved types indentation in header for readability

. lastly, some really gratuitous changes made to align
- comments within that private 'stacks_alloc' function

Signed-off-by: Jim Warner <james.warner@comcast.net
2016-05-12 07:51:10 +10:00
Jim Warner
abc71a46ad library: improve/standardize one interface, <STAT> api
This commit represents a complete redesign of the stat
interface. Gone are the confusing 8 separate accessors
along with their 2 additional read functions. In their
place we have just 3 accessors, with no read required.

That old interface also suffered an inflexibility with
respect to structures.  Now we deal with an unchanging
standard 'result' struct enabling future changes where
the binary interface will no longer need to be broken.

And gone is that former unnecessary typedef, used when
dealing with jiffies. Now the standard C type is used.

Our new API also adds some brand new functionality. If
a caller plans to employ successive 'select' or 'reap'
invocations, then delta values are available (which is
actually only what that top program is interested in).

At some future point a 'sort' function could be easily
introduced to complement the 'reap' function. However,
I saw no need for it at present and so it was omitted.

There were several design decisions which everyone may
not agree with. In support I'll offer these rationals:

. The 'get' function returns a signed long long result
which means a potential loss of some significance. But
I felt the ability to distinguish actual errors (minus
values) from true zero results were worth such a risk.

. The DELTA item enumerators were also made signed and
smaller than their parents. And they are intentionally
grouped as last so as to emphasize those distinctions.

. The SYS type items were excluded from the new 'reap'
function. It would not make sense to duplicate them in
each results stack. They're limited to 'get'/'select'.

. By the same token, some items (DELTA, etc.) will not
be allowed under that 'get' routine. That function was
already open to significant internal overhead (through
subsequent calls like in vmstat.c). That is why it has
been limited via 1 second between reads of /proc/stat.

Lastly, when we finally get around to documenting this
interface there's a real potential toe stubber when it
comes to the numa node portion. The libnuma.so doesn't
really provide any means to retrieve the active nodes.
Thus, any total reported by <stat> is just the highest
node number plus one, as reported by the numa library.

Any unused/inactive nodes are identified through these
. PROCPS_STAT_TIC_ID shows as PROCPS_STAT_NODE_INVALID

By the same token after the STAT_REAP_CPUS_ONLY 'reap'
. PROCPS_STAT_TIC_NUMA_NODE = PROCPS_STAT_NODE_INVALID

Reference(s):
http://www.freelists.org/post/procps/newlib-stat-interface

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-05-08 21:12:22 +10:00
Jim Warner
5854f2d956 library: remove an obsolete 'jiffs' typedef in sysinfo
During work on the new <stat> interface the typedef of
jiffs was eliminated along with the clang warning. The
exact same warning in sysinfo.h now goes bye-bye also.

Reference(s):
./proc/sysinfo.h:16:28: warning: redefinition of typedef 'jiff' is a C11 feature [-Wtypedef-redefinition]
typedef unsigned long long jiff;

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-05-08 21:12:22 +10:00
Craig Small
d2df396ba9 misc: Few more resource leak fixes
free after malloc in signals.c
closedir after opendir in diskstat
2016-05-03 21:58:13 +10:00
Craig Small
19a515e314 library: Fix LINUX_VERSION macro
The previous commit did not take into account operator evaluation
order so always gave 0. Fixed the macro and added some checks for
the macro.

References:
 commit 9abf7d879d
2016-05-01 17:46:25 +10:00
Craig Small
9abf7d879d library: protect against large version numbers.
Linux release numbers are x.y.z we assumed but never protected
against x> 0x7fff and y,z > 0xff before.

Linux release in 1991, 1 major release per 6 years so we're fine
until 7452, unless they do way too many minor rels (max being 39)
2016-05-01 17:14:48 +10:00
Craig Small
6b5cb345c5 library: procps_uptime() return value is a status
procps_uptime, previously just plain uptime() used to put the
uptime (as a double) in the first argument and return uptime
(as an int).

It meant if you ran
 myuptime2 = procps_uptime(&myuptime1, NULL);
You might get different results for myuptime1 and myuptime2 because
they are different types.

Most library calls use the return value to return the status,
procps_uptime was in the middle.

Until now.

This function will return 0 on success. If you want (for whatever
reason) uptime as an int then cast it.

All of the procps binaries didn't use the return value for uptime
except ps which set a variable to it but never used it anywhere.
2016-05-01 16:50:25 +10:00
Craig Small
222945c672 library: provide ref and unref for diskstat
While procps_diskstat_ref and procps_diskstat_unref were declared
they actually weren't implemented in the library. Linking some
binary that used these functions gave the following errors:

  CCLD     vmstat
vmstat.o: In function `disksum_format':
vmstat.c:719: undefined reference to `procps_diskstat_unref'
vmstat.o: In function `diskformat':
vmstat.c:591: undefined reference to `procps_diskstat_unref'
2016-05-01 16:15:49 +10:00
Jim Warner
3a48427d5d library: rename those readstat.c & h sources to 'stat'
In an attempt to normalize the 'stat' interface, we'll
first shed any reminders of the old readproc interface
by changing file names to be more descriptive & brief.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-04-26 22:27:16 +10:00
Jim Warner
b778a267fe library: fix boo-boo left by earlier patch, <PIDS> api
After the commit referenced below the potential exists
for a SEGV (resulting from an out-of-bounds Item_table
reference if PROCPS_PIDS_physical_end is encountered).

So this patch eliminates that PROCPS_PIDS_physical_end
as no longer necessary and completes the task of using
PROCPS_PIDS_logical_end as a sole necessary fencepost.

Reference(s):
commit e7585992d9
2016-04-26 22:27:16 +10:00
Jim Warner
8c38a58d94 library: reorder (alphabetize) some things, <PIDS> api
Without breaking either ABI or API just rearrange some
stuff to provide a little more consistent source file.

[ these were prompted by some work on the <stat> API ]
[ in preparation for him borrowing some of our code. ]

Reference(s):

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-04-26 22:27:16 +10:00
Craig Small
40de1c9c7c library: 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.

Reported by Takayuki Nagata <tnagata@redhat.com> and adopted
his patch for new library (see reference)

References:
 commit 99d71ad581
 http://www.freelists.org/post/procps/PATCH-bprocps-fix-order-of-operations-for-use-of-slabinfo
2016-04-25 20:24:20 +10:00
Craig Small
aa16ab0dc1 tests: update template and add pids
Generalised the library API tests and created a common
test-runner. Instead of copy and pasting the same code in
each time.

First cut of pids API test, for _new so far.
2016-04-19 21:33:02 +10:00
Jim Warner
edb124ec86 library: changed use of 'fill' to 'select', <pids> API
Remove a remnant of this new API's evolution.  Here we
no longer fill stacks, rather we reap and select them.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-04-19 20:38:18 +10:00
Jim Warner
e7585992d9 library: protect against a future breakage, <pids> ABI
By co-mingling both external/internal identifiers with
actual implementation code, potential future additions
to our API would have been considerably more difficult.

So, this patch will now rely solely on internal/hidden
identifiers serving as fenceposts in validation logic.

And if the following convention is used for new fields
we will maintain that enumerator alphabetic ordering a
a little longer (even though 2 user fields now don't):

. PROCPS_PIDS_XTRA_FOO_A, PROCPS_PIDS_XTRA_FOO_B, etc.

Reference(s):
http://www.freelists.org/post/procps/me-too-newlib,7

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-04-19 20:38:18 +10:00
Jim Warner
b4d21c74ac library: correct the procps_pid_length() +1 distortion
Unfortunately, reading that '/proc/sys/kernel/pid_max'
file returns a newline, which we will now account for.

[ also, we should use the existing dedicated buffer ]

Reference(s):
. original 'procps_pid_length' introduction
commit ccb6ae8de1

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-04-18 19:29:41 +10:00
Jim Warner
81e0f15ac3 library: remove remaining 'likely' & 'unlikely' macros
Say goodbye to the 'makes it hard to read' macro shit.

Reference(s):
http://www.freelists.org/post/procps/me-too-newlib,4

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-04-18 19:29:41 +10:00
Craig Small
d916d5db86 library: re-arrange escape commands
escaped_copy(): only appears in ps, moved to ps/output.c
escape_strlist() only used in escape.c made static
escape_command() used in library, made internal
procps.h no longer includes escape.h

escape_str() used by library and ps so needs to be exported
definition put into procps.h including the odd define required.
Far from ideal to have it this way, will look at it another time
to have it all in, all out or split nicer so its not in the API;
perhaps a lib/ file?
2016-04-17 14:45:19 +10:00
Craig Small
887bb51016 library: cleanup of readproc functions
readproc still had some of the old API hanging around that
was good while we were trying it out, but its time to say
goodbye:

readproc.h removed from public procps.h header file
enum ns_type - not used - removed
get_ns_name() - not defined - removed
get_ns_id() - not defined - removed
PROCTAB proc_t only used internal to library
readproctab() and 2,3 friends not used - removed
proc_data_t was used by readproctab23() - removed
readtask() - not used - removed
read_cmdline() - copy,renamed and made generic - remove original
freeproc() - not used - removed
get_proc_status - not used - removed, however there should be
a new function created that does this. Given a PID return data
about it instead of scanning the entire procfs. Maybe it already does.

Left as internal-to-library only functions:
 readproc(), readeither(), look_up_our_self(), openproc(), closeproc()

Updated libprocps.sym to export only what we use.
2016-04-17 14:14:27 +10:00
Jim Warner
67bf272f5d library: trade a deprecated oomem field for proper one
Now that the conditional OOMEM_ENABLE has been removed
and, after reviewing current library support, it turns
out we've been using a deprecated /proc/<pid>/oom_adj.

What we should use instead is that more recent tunable
/proc/<pid>/oom_score_adj. This new field will provide
a range of -1000 thru +1000 (former was -17 thru +15).

Reference(s):
. removal of misguided OOMEM_ENABLE
commit 64238730fa
. linux, partial oom_adj revert (Nov, 2012)
commit fa0cbbf145aabbf29c6f28f8a11935c0b0fd86fc
. linux, removal oom_adj (Oct, 2012)
commit 01dc52ebdf472f77cca623ca693ca24cfc0f1bbe

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-04-17 09:12:02 +10:00
Craig Small
8e20fa7786 library: document and tests for uptime functions
man pages for the three procps_uptime* functions and simple
test scripts for same functions.
2016-04-16 22:02:10 +10:00
Craig Small
ccb6ae8de1 library: cleanup of library includes
The includes used to define a lot of things a library include
should not. It was also a bit messy what was exposed in the library
and what was not.

get_pid_digits -> procps_pid_length and exported correctly

MALLOC attribute move into relevant .c files
NORETURN attribute moved to relevant .c, not used in library
PURE attribute removed, it wasn't used
KLONG/KLF/STRTOUKL were fixed for long, so now just use long

HIDDEN attribute removed. It was for 3 functions. The PROCPS_EXPORT
seems to do the same (opposite) thing.

likely/unlikely removed from most places, its highly debateable
this does anything useful as CPUs have gotten smarter about branches.

Re-arranged the includes, ALL external programs should just #include
<proc/procps.h> then proc/procps.h includes headers for files that
have exported functions. procps.h and the headers it includes should
not use items that are not exportable (e.g. hidden functions or
macros) they go in procps-private.h
2016-04-16 17:03:57 +10:00
Craig Small
8639a97250 libprocps version test and documentation
test binary and man page for the version part of libprocps.
It's a simple start, but it's a start!
2016-04-14 22:28:38 +10:00
Craig Small
bf97da3059 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.

From master commit da715e3

References:
 http://pubs.opengroup.org/onlinepubs/009695399/functions/fscanf.html
2016-04-14 21:21:27 +10:00
Jim Warner
8dc378f6a8 library: exploit linux-4.5 resident memory enhancement
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

This patch just represents the initial library and top
support, sharing a commit message with 2 more patches.

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

Reference(s):
commit 1f8e41d019
Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-04-14 21:03:03 +10:00
Jim Warner
65000d7c64 library: miscellaneous tweaks for code and/or comments
Summarized below, miscellany addressed in this commit:

. deleted extraneous newline(s) for consistent spacing

Signed-off-by: Jim Warner <james.warner@comcast.net>
2016-03-12 14:52:56 +11:00
Jim Warner
2b0dd2d702 library: correct <pids> support of true string vectors
When reference counts were added to some string fields
the 3 true string vector fields were not duplicated as
were those other fields. Instead they were supposed to
disallow a duplicate stack reference beyond the first.
However, the actual implementation gave NULL for every
true vector field whenever such items were duplicated.

More importantly, such true string vector fields never
considered references to the shared proc_t source root
which would have forced the conversion of such vectors
into a single string form via the '_CVT' library flag.

So this commit restores the intended outcome with true
string vectors. There's only 1 valid reference allowed
and duplicates and converted fields will yield a NULL.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-28 20:58:28 +11:00
Jim Warner
9db796f8cb library: correct one <pids> reference from str to strv
While not changing generated code this commit corrects
one free reference from 'str' to a more proper 'strv'.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-28 20:58:12 +11:00
Craig Small
602b9a02ce 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:
 05d751c4f0
 6cb75efef8
2015-10-24 14:29:25 +11:00
Jim Warner
88489be542 library: allow duplicated results for <pids> interface
Ok, here is that rather major internal redesign hinted
at in the three previous commits. Its need was quickly
revealed after adapting top then attempting to display
newly added 'CGNAME' fields and an existing 'CGROUPS'.

That very quickly generated a SEGV. And the reason was
just as quickly recognized. Both fields relied on that
proc_t.cgroup member yet whichever result structure is
first in a stack is the one which assumes ownership of
of the vectored sting by resetting its cgroup to NULL.

So this commit introduces reference counting for a few
of the fields in the proc_t. Specifically there are 17
entries in the Item_table dealing with strings/vectors
where ownership is transferred to newlib. Now whenever
such fields are represented more than once in a stack,
the strings will be duplicated instead of transferred.
In this way we can generally remain optimized avoiding
string copies, yet still accommodate them when needed.

There's an exception to this scheme: those true string
vectors (CGROUP_V, CMDLINE_V and ENVIRON_V). When such
fields are duplicated in a stack the result structures
beyond the first will be set to NULL, which the caller
will (should) already be equipped to deal with anyway.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-14 21:50:31 +11:00
Jim Warner
a59a269661 library: added PROCPS_PIDS_CGNAME for <pids> interface
The ps program was modified to print the control group
names, based on the library provided list of all those
control groups to which a process belongs. But this is
probably something the newlib should be doing for all.

So this commit borrows the ps approach to cg names and
thus will make that available to all future consumers.

[ but stay tuned! there is a commit coming soon that ]
[ represents a rather major internal redesign, which ]
[ was prompted by the ps and top adaptation testing. ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-14 21:48:41 +11:00
Jim Warner
838e7852cb library: rename the 'procps_pids_stacks_sort' function
The above function was the sole public function in the
<pids> interface to use the word 'stacks' in its name.
All of the others dealt exclusively with their duties,

So this commit normalizes that outlier by renaming it.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-14 21:47:04 +11:00
Jim Warner
c9388ed512 library: re-enable <pids) dealloc_stacks, found a need
The above function had been disabled via '#if 0' so as
to prevent a compiler warning. But it really should be
called by that 'procps_pids_read_shut' function rather
than it duplicating/reinventing the same logic itself.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-14 21:35:53 +11:00
Jim Warner
bc616b3615 library: correct a flawed approach for PROCPS_FILL_UID
Gosh, just because nobody uses some newlib provision I
guess, since it is being offered, it ought to actually
be tested at some point. Well, that point just arrived
and guess what? A surprise: some bugs were discovered.

The procps_pids_select function established a for loop
wherein readproc is called until the passed 'maxthese'
limit. Unfortunately this was incorrect for 2 reasons:

1. For PROCPS_FILL_PID results are limited by what the
oldlib finds, having established the pid list at open.
Total found already cannot exceed a passed 'maxthese';

2. With PROCPS_FILL_UID, returned results could exceed
a 'maxthese' thus making the for loop incorrect again.

[ plus yours truly neglected to forward the required ]
[ UIDs total to our old library, another oops biggie ]

In summary: the loop should have been forever, exiting
only when all those identified procs had been located.

So, while addressing those bugs, I've consolidated all
the retrieval code (initialize, iterate, summarize) in
a single helper function which will now serve both the
procps_pids_reap and select functions. And as a result
those guys were reduced to quite trivial housekeeping.

This patch, hopefully, completes the normalization for
reap/select (fill), which began with references shown.

Reference(s):
commit 0c953eccc5
commit 747dfc5987

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-09 21:35:04 +11:00
Jim Warner
0354fc1c8f library: miscellaneous minor accumulated <pids> tweaks
This patch contains the following minor modifications:

. When assigning to boot_seconds from a double, a cast
to 'unsigned long' was employed that in reality should
have been 'unsigned long long'. But, on second thought
it's probably best if the compiler makes the decision.

. Results for ID_TGID do not require an 'f_status' flg
since both tid and tgid will be available by virtue of
the 'simple_nextpid' function normal operations. Thus,
that flag has been removed from the <pids> Item_table.

. When the pids_stacks structure was eliminated with a
change to the alloc/dealloc functions in the reference
below, several casts became redundant and are removed.

Reference(s):
commit 747dfc5987.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-09 21:33:14 +11:00
Jim Warner
747dfc5987 library: privatize two with <pids> select/fill changes
After simplifying that select/fill interface, there is
no longer a need for public 'alloc' & 'dealloc' stacks
functions. There is now only one instance of stacks as
an input parameter found in procps_pids_stacks_sort().
But sorting 'empty' stacks serves no possible purpose.

So this commit retains both functions, since they will
still be needed, but designates them private (static).

Additionally, with their demise we will eliminate that
pids_stacks structure from the header file, internally
using what always was the true 'stacks_extent' struct.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-05 21:48:45 +11:00
Jim Warner
0c953eccc5 library: normalize the <pids> fill/selection interface
After wrestling with the conversion of both top and ps
the differences between reap (all) & fill (select) has
become increasingly inconvenient. So this patch simply
normalizes that API making returned results identical.

The former procps_pids_stacks_fill identifier will now
be known as procps_pids_select which serves as logical
counterpart to the existing procps_pids_reap function.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-05 21:47:50 +11:00
Jim Warner
30997b967a library: add <pids> TIME_ALL/TIME_ELAPSED needed by ps
Shoot, here's yet another bow to ps needs. But it's ok
because it makes a lot of sense. Rather than force all
users into their own calculations do but it once here.

As an aside this need arose during ps testing when the
sorts were using TIME_START or TICS_ALL. That was just
fine for almost every need except 'etime' plus 'time'.

That 'etime' was sorting the opposite of what's wanted
when using TIME_START (of course) while 'time' yielded
some weird ordering because TICS_ALL was too granular.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-05 21:42:07 +11:00
Jim Warner
042cfa71e7 library: add abbreviated TTY_NUMBER to that <pids> API
While not documented in the man page, ps allows 'tty4'
as a valid output specifier complimenting 'tty8' & its
derivatives. So, in order to eliminate a dev_to_name()
call in the ps program the library will now offer this
abbreviated tty version (consisting of a number only).

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-05 21:39:37 +11:00
Jim Warner
d66000588a library: the <pids> API now supports 'extra' enum sort
The 'PROCPS_PIDS_extra' enumerator already enjoys some
special place wherein it's zeroed with each iteration.

This patch simply extends the special handling to also
include support for sorting. It will be treated as the
'ull_int' data type, since that encompasses the entire
scope of that union within all pids_result structures.

[ plus, we've also corrected the actual 'extra' name ]

This change was prompted by the conversion of ps which
needs that enumerator to store the former 'pcpu' data,
so it will be available for sorting (not for display).

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-05 21:37:08 +11:00
Jim Warner
27283bbc6f library: strengthen <pids> sort order parameter checks
The way that the passed sort order was validated would
allow the invalid 0 to fall between the sofa cushions.
So this patch will simply close that former oversight.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-10-05 21:32:54 +11:00
Craig Small
5321868929 library: Removed unused methods.
As part of the push to remove the old API, 3 more old calls were
deleted from the library. Now all someone needs to do is fix ps
and we're largely done.
2015-09-26 14:39:37 +10:00
Jim Warner
86b155b83f library: make the pids_sort_order enums more intuitive
The values of PROCPS_SORT_ASCEND & PROCPS_SORT_DESCEND
were a tad unintuitive. This patch will just make them
a more natural +1 for ascending and -1 for descending.

[ plus it still allows that fast path multiplication ]
[ instead of a comparison for signed numbers/strings ]

Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-09-21 22:39:40 +10:00
Jim Warner
007e032805 library: introduce a fatal 'proc not mounted' function
Signed-off-by: Jim Warner <james.warner@comcast.net>
2015-09-21 22:38:38 +10:00