[procps] Re: newlib, ps fix

  • From: Craig Small <csmall-procps@xxxxxxxxxx>
  • To: procps@xxxxxxxxxxxxx
  • Date: Wed, 26 Aug 2015 22:50:29 +1000

On Mon, Aug 24, 2015 at 03:10:50AM -0500, Jim Warner wrote:

The attached will cure that ps aberration when run without arguments. The
problem was caused by changes I made to the look_up_our_self() function when
the 'cmd' array became a dynamically acquired string.
That seems to have worked, thanks.

But this raises the question of how newlib should handle a /proc not mounted
condition. Should I add a procps_pids_lookup_self function, with fatal
stderr exit? Or does that belong in some other place and perhaps be
automatic with library initialization?
stderr output from the library is always a bad idea. The library
initialisation stuff doesn't seem pleasent either.

Generally we would have:
procps_thing_new
procps_thing_read
procps_thing_get_item
procps_thing_unref

The procps_thing_read should return an error if proc isn't mounted.
There would be race conditions, for example.
Now, did we want the library to have a specific function to check for
this? Certainly if it does an output to stderr and an exit() is not
the right idea.

Both ps and pgrep currently use such an approach, but they could be altered
to use procps_pids_reap() instead. I think it’s inherently more accurate to
snapshot all of the /proc processes and then apply whatever selection
criteria is desired. But a procps_pids_read() could be added and serve as
the newlib equivalent of the old readproc function.
Grabbing them all at once, assuming there isn't any efficiences lost, is
preferred. It means all the start time calcs line up better.

- Craig
--
Craig Small (@smallsees) http://enc.com.au/ csmall at : enc.com.au
Debian GNU/Linux http://www.debian.org/ csmall at : debian.org
GPG fingerprint: 5D2F B320 B825 D939 04D2 0519 3938 F96B DF50 FEA5

Other related posts: