Right now, "we _exit() anyway" is not always true: for example, the
default action for SIGURG is to ignore the signal, which means that
"kill(getpid(), signo);" does not terminate the process. Call _exit()
explicitly, in this case (rather than exit(), because the terminating
kill() calls do not call the functions registered with atexit() either).
1/ Do not go deeper than the size of forest_prefix[], to prevent a
buffer overflow (sizeof(forest_prefix) is roughly 128K, but the maximum
/proc/sys/kernel/pid_max is 4M). (actually, we go deeper, but we stop
adding bytes to forest_prefix[])
2/ Always null-terminate forest_prefix[] at the current level.
---------------------------- adapted for newlib branch
. logic is quite different with 'stacks' vs. 'proc_t'
. a commented out 'debug' line was no longer present
Signed-off-by: Jim Warner <james.warner@comcast.net>
This patch is a response to errors found in those type
references now that our library allows for validation.
In two cases, former assignments to a result structure
could no longer employ that VAL macro if validation is
active. Thus, direct reference to some stack was used.
For the record, those instances were to be found here:
. ps - uses PIDS_extra to store the cooked pcpu values
. top - uses PIDS_extra to store the forest view level
Signed-off-by: Jim Warner <james.warner@comcast.net>
With this patch we've completed a progression toward a
standard approach to naming conventions which follows:
* Only functions will begin with that 'procps_' prefix
. ........................................... examples
. procps_vmstat_get ()
. procps_diskstats_select ()
- ----------------------------------------------------
* Exposed structures begin with the module/header name
. ........................................... examples
. struct pids_info
. struct stat_reaped
- ----------------------------------------------------
* Item enumerators begin like structs, but capitalized
. ........................................... examples
. VMSTAT_COMPACT_FAIL
. MEMINFO_DELTA_ACTIVE
[ slabinfo varies slightly due to some item variants ]
. SLABINFO_extra
. SLABS_SIZE_ACTIVE
. SLABNODE_OBJS_PER_SLAB
[ could cure with a prefix of SLABINFO, but too long ]
- ----------------------------------------------------
* Other enumerators work exactly like item enumerators
. ........................................... examples
. PIDS_SORT_ASCEND
. STAT_REAP_CPUS_AND_NODES
- ----------------------------------------------------
* Macros and constants begin just like the enumerators
. ........................................... examples
. #define SLABINFO_GET
. #define DISKSTATS_TYPE_DISK
- ----------------------------------------------------
Signed-off-by: Jim Warner <james.warner@comcast.net>
With the change to struct pids_fetch, we'll just trade
some dot ('.') code for some pointer to ('->') syntax.
Signed-off-by: Jim Warner <james.warner@comcast.net>
I've got nothing to add to the commit message but that
doesn't mean I won't produce perfectly justified text.
Signed-off-by: Jim Warner <james.warner@comcast.net>
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
This commit represents the ps transition to the <pids>
'stacks' interface. While an effort to minimize impact
on existing code was made (as with a disguised proc_t)
the changes were still extensive. Along the way, a few
modifications beyond simply conversion were also made.
------------------------------------------------------
Here's a brief overview the design of this conversion:
. The need to satisfy relative enum requirements could
not easily have been made table driven since any entry
in the format_array might require several <pids> items
in support. So I decided to allow every print function
to contribute its own relative enums once the decision
as to exactly what will be printed had been finalized.
. A similar approach was taken for sorting, since it's
possible to have sort keys that will not be displayed.
Here, I relied on the existing print extensions above.
. In summary, just prior to printing ps walks thru two
lists one time (the format_list & sort_list) and calls
each print function. That function does not print, but
sets its required enum if necessary. Later, when those
same functions are called repeatedly for every printed
line, the only overhead will be an if test and branch.
------------------------------------------------------
Below is a summary of major changes beyond conversion:
. Sorts are now the responsibility of the library. And
therefore the total # of sortable fields substantially
increased without effort. Additionally, several quirky
fields remain as sortable, even though they can't ever
be printed(?). Surely that must make sense to someone.
[ while on this subject of sort, please do *not* try ]
[ to sort old ps on 'args'. or better yet, if you do ]
[ try that sort, see if you can determine his order, ]
[ without peeking at the source. that one hurts yet! ]
. All logic dealing with the old openproc flags and ps
struct members known as 'need' have been whacked since
that entire area was solely the new library's concern.
. Remaining malloc/calloc calls to stdlib were changed
to xmalloc/xcalloc from our own include/xalloc.h file.
None of the replaced calls ever checked return values.
[ be aware that 2 minor potential memory leaks exist ]
[ depending on command line arguments. no attempt is ]
[ made to free dynamically acquired format/sort node ]
[ structures upon return; a conscious design choice. ]
Signed-off-by: Jim Warner <james.warner@comcast.net>
Procps library previously held functions that were about either
listing or finding signal names. These are not really the right
location for a library about reading procfs.
This patch handles signal related functions in two ways:
For functions purely found in skill, these have been moved back
into this binary as they are used nowhere else.
For functions used across the binaries, these have been moved
into include/signals.h and lib/signals.c. Besides formatting,
these functions are largely the same.
To assist the skill functions, two functions to access the
signal map array have been added to lib/signals.c
This patch was made necessary by those library changes
in support of recently revised/simplified wchan logic.
In addition, this commit eliminates a broken alternate
'namelist' provision which was intended to allow users
to specify a System.map file to be used in translating
addresses into function names. But, the real effect of
the now defunct 'N' and '-n' options was to indirectly
force addresses (not names) to be displayed since such
user named map files could not be successfully parsed.
Besides when the required FRAME_POINTER kconfig option
is absent there is no address to translate and when it
is present /proc/PID/wchan is already translated. Thus
an alternate mapping is unnecessary and inappropriate.
[ we'll forgive POSIX for documenting '-n namelist' ]
Reference(s):
http://www.freelists.org/post/procps/WCHAN,11
Signed-off-by: Jim Warner <james.warner@comcast.net>
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
This commit introduces a new option q/-q/--quick-pid
to the 'ps' command. The option does a similar job
to the p/-p/--pid option (i.e. selection of PIDs
listed in the comma separated list that follows
the option), but the new option is optimized
for speed.
In cases where users only need to specify a list
of PIDs to be shown and don't need other selection
options, forest type output and sorting options,
the new option is recommended as it decreases
the initial processing delay by avoiding reading
the necessary information from all the processes
running on the system and by simplifying
the internal filtering logic.
SIGCONT is a continue signal. It seems that some zsh setups can send
this signal, causing ps to abort. This is not what "continue" means.
This change just uses the default handler which will continue a stopped
process.
References:
http://bugs.debian.org/732410http://www.zsh.org/cgi-bin/mla/redirect?WORKERNUMBER=32251
Signed-off-by: Craig Small <csmall@enc.com.au>
Since the ps command handles signals with it's own handler, it doesn't create
core files when something wrong happens. The attached patch restores the ps
command ability to create core files by calling the default handler once we
print our custom message. The original RH's workaround masked SIGABRT and
SIGSEGV signals and that would conflict with the original intention of the
custom signal handler and also with the filtering patch I sent in my previous
email. Moreover, this solution generates core for all relevant signals (SIGFPE,
etc.).
Bug-Redhat: http://bugzilla.redhat.com/871825
Bug-Redhat: http://bugzilla.redhat.com/512857
Reference: http://www.freelists.org/post/procps/PATCH-Allow-core-file-generation-by-ps-command-rhbz871825-rhbz512857
Signed-off-by: Craig Small <csmall@enc.com.au>
The sniplet below resulted not to be sorted correctly.
for i in $(seq 1 50); do ls -R /usr &>/dev/null 2>&1 & done
sleep 1; ps -e --sort=pcpu -o pcpu,comm=; pkill ls
Issue is present since older versions of procps (3.2.7/3.2.8).
Reference: http://www.freelists.org/post/procps/top-incorrect-sort,2
Reported-by: Jaromir Capik <jcapik@redhat.com>
Backported-by: Sami Kerola <kerolasa@iki.fi>
If stream status is not checked at the end of execution below problem
would not report error, or non-zero exit code. The uptime is just an
example same was true with all commands of the project.
$ uptime >&- ; echo $?
uptime: write error: Bad file descriptor
1
$ uptime >/dev/full ; echo $?
uptime: write error: No space left on device
1
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
Strings with lower caps & no trailing dots have greater change to
have multiple occurences, meaning less effort for translators, than
strings with them.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
The catastrophic_failure function tries to make bug reporting useful
by telling in which line error occured, and drops core.
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
This commit represents an experiment in nls help text support.
The word --help itself been made translatable along with the
help section names and their abbreviations. Thus, the work of
the translators will ultimately alter program run-time behavior.
Perhaps someday all "long" options can behave in a similar way
which could offer a considerable benefit to other languages.
Instead of translationg just option descriptions, the long
forms of those options could also be transalated.
This commit also:
. includes the section abbreviations in --help output
. isolates all --help support in the ps/help.c module
. provides (hopefully) meaningful Translator guidance
. removes --help support from the ps/common.h header
. removes --help support from the ps/parser.c module
. eliminates tabs in line with the style of other ps modules
. eliminates the need for the include/c.h header file
This commit is prmarily concerned with elimnating deugging only
code from the nls template file.
It also eliminates any remaing useless trailing whitespace.
This patch mostly reorganizes include files and eliminates
some useless trailing whitespace.
It also adopts the standard procps-ng unconditional approach
to nls initialization.
Add the following three functions to most of the commands.
setlocale (LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
Reference: http://www.freelists.org/post/procps/backporting,1
Reported-by: Jim Warner <james.warner@comcast.net>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
These xalloc functions are a private function for the library. If using
programs need them, then they should make their own error reporting or
use a common file.
There were numerous ps memory allocation inconsistencies.
Some were checked for failure and others were not.
The program was modified to utilize the library memory
rouines which are consistent in dealing with errors.
(a few changes simply removed trailing whitespace)
ps program
. etimes added for ELAPSED expressed in seconds
. time_t used in place of former unsigned long
top program
. corrected scroll message bug when 'x' toggle on
. fixed forest view potential missing libflags bug
. improved 'k' default signal invocation logic
. enhanced logic for %CPU maximums displayed
. made signal handling more robust and efficient
Library changes
readproc
. added readeither to more efficiently
fill both process and thread proc_t
. added readproctab3, uses readeither
. included task path support in:
fill_cgroup_cvt, fill_cmdline_cvt,
read_unvectored
. QUICK_THREADS #define allows copying
process info vs. repeatedly reading
. simple_nexttid no longer values ppid
. path var made non-static in readtask
. documented 'proc_data_t' in .h file
. tweaked some c comments & formatting
library.map
. added new readeither, readproctab3
Program changes
ps
. exploits readproctab3 where possible
. improved args/comm compliance
top
. exploits readeither
Library changes
readproc
. added support for supplementary groups
. eliminated 2 potential mem leak sources
. shortcut used for multi-threaded str
vectors & ptrs was obsoleted
. freeing of proc_t related dynamic
memory now rests with the library
. standardized/normalized many c comments
sysinfo
. corrected note regarding glibc & cpuinfo
library.map
. made the visible freeproc accessable
Program changes
pmap
. initialized buffer for new readproc i/f
. eliminated now obsolete free() call
ps
. added width aware supgrp support
. initialized buffers for new readproc i/f
. eliminated now obsolete free() calls
top
. added supgrp support as variable width
. eliminated now obsolete free() calls
. expoilted library freeproc function
. corrected -h|v args text & spacing
. updated some c comments
Documentation changes
ps.1
. added supgid and supgrp
top.1
. added supgid and supgrp
. addition of above required renumbering
many fields in section 3a. DESCRIPTIONS
Library Changes
. added PROC_EDITCMDLCVT flag
. added an internal (static) fill_cmdline_cvt function:
- reads and "escapes" /proc/#/cmdline
- returns result as a single string in a single vector
- callers are guaranteed a cmdline (no more NULL)
. added vectorize_this_str function, exploited by
fill_cgroup_cvt, fill_cmdline_cvt
. generalized read_cmdline function as read_unvectored, now
exploited by fill_cgroup_cvt, fill_cmdline_cvt, read_cmdline
( cgroup and cmdline no longer need be converted to string )
( vectors before being transformed to final representation )
. fixed bug regarding skipped group numbers (when enabled)
. escape_str made responsible for all single byte translation
with distinction between control chars + other unprintable
. added escaped_copy function for already escaped strings
. reorganized parts of proc_t to restore formatting standards
( displacement changes shouldn't matter with new version # )
. former ZAP_SUSEONLY #define now OOMEM_ENABLE
. added to library.map: escaped_copy; read_cmdline
Top Program Changes
. exploited the new PROC_EDITCMDLCVT provision
. eliminated now obsolete #include "proc/escape.h"
. changed the P_WCH display format if no kernel symbol table
. fixed very old bug in lflgs for out-of-view sort fields
. former ZAP_SUSEONLY #define now OOMEM_ENABLE
Ps Program Changes
. exploited the new PROC_EDITCMDLCVT provision
. exploited the new escaped_copy function
. consolidated pr_args and pr_comm into pr_argcom
Signed-off-by: Jan Görig <jgorig@redhat.com>