Commit Graph

91 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Jim Warner
f4666e1743 library: lift 1024 byte restriction on control groups
The control group hierarchies for any particular task
could conceivably grow quite large.  However, the
library might impose an arbitrary limit of 1024 bytes
via fill_cgroup_cvt.

Two utility buffers of 128 KiB each were already
available for command line use.  This commit simply
trades the smaller 1024 byte stack based buffers for
those much larger existing ones.  Thus, truncation
can be avoided with no additional run-time costs.

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-29 17:27:50 +10:00
Jim Warner
8b64b36bbf library: standardize handling of cgroup, supgid
Some inconsistencies have emerged during development
of support for these relatively new proc_t fields.

For example, a PROC_FILLCGROUP flag (via file2strvec)
could return NULL in cgroup whereas PROC_EDITCGRPCVT
(via fill_cgroup_cvt) *almost* guaranteed a return
address (as is true for PROC_EDITCMDLCVT and cmdline).
But even PROC_EDITCGRPCVT could return NULL if the
kernel version was less than 2.6.24.  Then with NULL
ps would display a "-" while top would show "n/a".

And while unlikely, with the PROC_FILLSTATUS flag (via
status2proc) a NULL supgid address was theoretically
possible and both ps and top would then show "n/a".

This commit standardizes the following usage:
  . PROC_FILLSTATUS         (via status2proc)
      guarantees a valid supgid address
      representing either a true comma
      delimited list or "-"
  . PROC_FILLCGROUP  plus
    PROC_EDITCGRPCVT        (via fill_cgroup_cvt)
      guarantees a cgroup single vector
      representing either a true control
      group hierarchy or "-"

And as was true before, the following remains true:
    PROC_FILLCOM     or
    PROC_FILLARG            (via file2strvec)
      may return a NULL cmdline pointer
  . PROC_FILLCGROUP         (via file2strvec)
      may return a NULL cgroup pointer
  . PROC_FILLCOM     or
    PROC_FILLARG     plus
    PROC_EDITCMDLCVT        (via fill_cmdline_cvt)
      guarantees a cmdline single vector
      representing either a true command
      line or a bracketed program name
  . PROC_FILLSTATUS  plus
    PROC_FILLSUPGRP         (via supgrps_from_supgids)
      guarantees a valid supgrp address
      representing either a true comma
      delimited list or "-"

Signed-off-by: Jim Warner <james.warner@comcast.net>
2012-08-29 17:26:13 +10:00
Sami Kerola
ce61089059 docs: clarification to license headers in files
Add license header to all files.  The summary of licensing is below,
taken from Craig Small's email which is referred in commit message
tail.

sysctl and pgrep are GPL 2+
The rest is LGPL 2.1+

Reference: http://www.freelists.org/post/procps/Incorrect-FSF-address-in-the-license-files,8
Bug-Redhat: https://bugzilla.redhat.com/show_bug.cgi?id=797962
CC: Craig Small <csmall@enc.com.au>
CC: Jaromir Capik <jcapik@redhat.com>
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-03-03 18:41:11 +11:00
Craig Small
16329a7c3c libprocps-ng: readproc.c: some type conversion help
Return if unable to open /proc

A patch from Debian.

Backported-by: Sami Kerola <kerolasa@iki.fi>
2011-12-18 22:50:40 +11:00
Daniel Novotny
5d29bfedc8 pwdx & libprocps-ng: Hurd does not have MAX_PATH defined
A patch from Debian.

Bug-Redhat: https://bugzilla.redhat.com/show_bug.cgi?id=485243
Bug-Debian: http://bugs.debian.org/588677
Backported-by: Sami Kerola <kerolasa@iki.fi>
2011-12-18 22:30:00 +11:00
Armin van Buuren
90b201f1f4 libproc-ng: prettyfy proc mount messages
A patch from Gentoo.

Bug-Gentoo: https://bugs.gentoo.org/138029?id=138029
Bug-Gentoo: http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/sys-process/procps/files/procps-3.2.7-proc-mount.patch?revision=1.1&view=markup
Bug-Gentoo: http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/sys-process/procps/files/procps-3.2.7-proc-mount.patch?revision=1.1&view=markup
Backported-by: Sami Kerola <kerolasa@iki.fi>
2011-12-18 10:58:02 +11:00
Jim Warner
c3a1239efe library: once again properly ignore a final empty cgroup
Commit a5881b5a4e, addressing
command lines with a trailing space, produced an undesirable
side effect in the fill_cgroup_cvt() function.

This patch restores correct cgroup behavior while still
producing command lines with no trailing space.
2011-12-14 23:02:51 +11:00
Jim Warner
e048aa0e7e library: eliminate one redundant 'extern' qualifier 2011-12-11 22:27:19 +11:00
Jim Warner
a5881b5a4e library: create cmdlines consistently with no trailing space
When PROC_FILLARG was used (invoking file2strvec)
command lines contained no trailing space.

When PROC_EDITCMDLCVT was used (invoking read_unvectored)
command lines contained a trailing space.

Now both routes to a cmdline act the same -- no trailing space.
2011-12-11 22:27:12 +11:00
Jim Warner
ed59472307 library: provide for huge cmdlines, like old libproc
The CodingStyle document suggests programs should allow for
cmdlines of at least 128k.  Only the ps program can display
such a cmdline, and only with multiple -w switches.

The library function file2strvec can essentially return
a cmdline of unlimited length.  However, the library function
fill_cmdline_cvt used an arbitrary upper limit of 2048 for
buffers automatically allocated on the stack.

This patch raises the fill_cmdline_cvt upper limit to 128k via
dymaically acquired utility buffers ensured by the openproc
function.

It also makes indentation consistent in the openproc function.
2011-12-11 22:27:06 +11:00
Jim Warner
827334870d library: exploit enhanced library memory allocation provisions
There were numerous library memory allocation inconsistencies.
Some were checked for failure and others were not.

All library source modules were modified to utilize the alloc.h
memory rouines which are consistent in dealing with errors.
2011-12-11 22:26:55 +11:00
Jim Warner
4820619f15 redhat analysis: proc/readproc 2011-10-15 08:26:27 +02:00
Craig Small
b9a408372e Merge branch 'master', remote-tracking branch 'sami/ng' 2011-10-01 23:23:30 +10:00
Craig Small
f7fb8bddf4 miscellaneous top and library cleanup
top changes
 . refined column header width calculations
 . added error messages for:
     invalid signal ('k')
     invalad max tasks ('n')
 . corrected narrative for summary_show

library changes
 . corrected some comments (only)
2011-09-25 00:27:37 +10:00
Craig Small
0e6ac0db3e added tgid support plus miscellaneous cleanup
ps
   . added tgid support
   . made process/task naming consistent
 top
   . added tgid support
   . standardized pid related width logic
 documents
   . added tgid to ps & top man documents
 library
   . fixed OOMEM_ENABLE readtask bug
   . corrected header typo for tgid
2011-08-17 21:01:35 +10:00
Craig Small
bb4f08ba29 refined library i/f and improved performance
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
2011-08-11 07:42:14 +10:00
Craig Small
3ef4823f90 supgid/supgrp support, improved library interface
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
2011-08-01 21:28:46 +10:00
Sami Kerola
06d491f9e4 build-sys: take autotools in use again
This will revert change at Oct 2002 when autotools support was
removed.

Unlike before the package developers are expected to use
./autogen.sh to generate ./configure script, and run make after
that. The build system is also able to create, with make dist, a
tar ball release which compiles correctly, and has files which
seemed to be important to have.

The patch removes few unnecessary files, but no everything. Files
procps.lsm and procps.spec in git repository are useless as is,
but I left them lying around for someone who can make more
justified call about removal of them.

Last, but not least package version number is set 3.3.0 to
distinct this procps from the sourceforge's upstream procps.
Please notice that libproc relese is kept as 3.2.8.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2011-06-04 17:22:44 +02:00
Jan Görig
f43de0df19 Added 'vm_swap' variable nullifying.
Thanks to KOSAKI Motohiro.

Bug-Redhat: https://bugzilla.redhat.com/show_bug.cgi?id=532668
2011-06-02 12:22:31 +02:00
Jim Warner
7b0fc19e9d enhanced libproc cgroup/cmdline support, exploited by top
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>
2011-05-18 10:33:44 +02:00
Jim Warner
57031319d6 cgroup support migrated to libproc, plus miscellaneous re-formatting
This source patchset addresses the following:
Library Extension (readproc)
 . added PROC_EDITCGRPCVT flag
 . added an internal (static) fill_cgroup_cvt function:
   . reads AND parses /proc/#/cgroup
   . returns result as a single string in a single vector
   . thus no changes to proc_t structure or free memory logic
Program Enhancements (top)
 . removed parse_cgroup logic in favor of libproc
 . eliminated cgroup sort recurring overhead
 . converted WCHAN field to variable width
 . generalized variable width field logic in task_show
 . real-time notation under P col more distinctive as 'rt'
Program Cosmetic (top)
 . CGROUP now known as CGROUPS (plural)
 . moved jan's attribution from top.c to 'Notes' in top.h
 . numerous comments tweaked
Document Enhancements (top)
 . documented CGROUPS field (required renumbering all fields)
 . adapted narratives for the 3 current variable width fields
 . expanded real-time scheduling notes, 'RT' now shown as 'rt'

Signed-off-by: Jan Görig <jgorig@redhat.com>
2011-05-05 12:12:27 +02:00
Werner Fink
e646984924 Add missed oom support to libproc
Add missed oom support to libproc
Signed-off-by: Werner Fink <werner@suse.de>
2011-04-15 15:52:40 +02:00
Jan Görig
59679bc2a2 Rewritten cgroup support and suppressed root cgroup
Bug-Redhat: https://bugzilla.redhat.com/show_bug.cgi?id=593267
Signed-off-by: Jan Görig <jgorig@redhat.com>
2011-02-10 13:40:29 +01:00
Jan Görig
356a1f9a37 fix the problem with truncated output lines to 2048 characters
Author: Karel Zak <kzak@redhat.com> and Olivier Fourdan <ofourdan@redhat.com>
Bug-Redhat: https://bugzilla.redhat.com/show_bug.cgi?id=134516
Bug-Redhat: https://bugzilla.redhat.com/show_bug.cgi?id=487700
2010-12-16 10:24:44 +01:00
Jan Görig
af25453d9a ps displays cgroup
Author: Swann Perarnau <swann.perarnau@imag.fr>
Bug-Debian: http://bugs.debian.org/469669
Reviewed-by: Craig Small <csmall@debian.org>
2010-12-16 10:23:49 +01:00
albert
5f570a84f1 per-process swap info available on Linux 2.6.34 2010-05-18 07:02:03 +00:00
albert
5c591b836f fix "ps sm" bug involving 1-thread-proc optimization 2006-06-17 04:14:57 +00:00
albert
6a304370f8 ps: fix crash related to realloc -- thanks David Houlder 2005-09-12 03:25:01 +00:00
albert
37b9b9a235 valgrind freaked out on some weird old code 2005-01-24 03:37:41 +00:00
albert
c961f2604a leftovers in the 3.2.4 release 2004-11-04 20:50:59 +00:00
albert
266d5b708a wchan for multithreaded process is now ~0ull or "*" 2004-07-21 21:17:35 +00:00
albert
f1db79c042 better handling of long usernames 2004-07-20 23:31:12 +00:00
albert
3f603adbae remove some table inconsistencies and rename it_real_value 2004-04-17 03:13:56 +00:00
albert
d526282deb nswap data dead since 2.4.xx kernels 2004-04-13 03:56:52 +00:00
albert
1e1218cca8 pmap stack detection 2004-01-26 20:01:56 +00:00
albert
c36c11c6b2 NSA SELinux for Linux 2.6.xx 2003-12-24 04:18:24 +00:00
albert
7046b34f42 thread-related hacks 2003-12-13 16:51:40 +00:00
albert
e583724fff H m -m -L -T are all working 2003-10-21 00:51:36 +00:00
albert
7dfe80961a sorted threads might work 2003-10-19 23:37:47 +00:00
albert
e180e4875f more goodies 2003-10-16 03:30:41 +00:00
albert
71312f1516 more per-process stuff 2003-09-29 04:09:52 +00:00