[procps] Re: request to remove perror in get_proc_stats

  • From: Sami Kerola <kerolasa@xxxxxx>
  • To: procps@xxxxxxxxxxxxx
  • Date: Tue, 24 Apr 2012 14:43:18 +0200

On Tue, Apr 24, 2012 at 13:41, Dirk Moermans <dirkmoermans@xxxxxxxxx> wrote:
> in the file "proc/readproc.c",  get_proc_stats calls perror, when the
> pid is not found.
>
> I would request to remove this perror. It is often not what the caller
> wants in this situation.
> It would be cleaner if get_proc_stats returned NULL and leaves it to
> the caller to write an error-message.
>
> It is possible that the process ceased to exist, and that this is
> perfectly acceptable to the caller.
>
> (This is my first mail to this list, it is simply a little thing that
> has been bugging me for some time).

Hi Dirk,

You are right. The library should not unnecessarily help programmer by
printing errors, but signal by using return values something went
wrong. It is up to library user what to do when things fail; print
error && exit || retry || something_else(). The change you need is
more or less below.

diff --git a/proc/readproc.c b/proc/readproc.c
index 36658d9..7d179e3 100644
--- a/proc/readproc.c
+++ b/proc/readproc.c
@@ -1373,7 +1373,6 @@ proc_t * get_proc_stats(pid_t pid, proc_t *p) {

        sprintf(path, "/proc/%d", pid);
        if (stat(path, &statbuf)) {
-               perror("stat");
                return NULL;
        }

Please notice that release v3.3.3 is expected soon, and this change is
very likely not to enter to that. Not only because the v3.3.4 is
planned to be The Big Library fix release.

-- 
   Sami Kerola
   http://www.iki.fi/kerolasa/

Other related posts: