From a37526260917bac624ae6b75fd9f4ea7287d81ad Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Sat, 7 Aug 2021 00:00:00 -0500 Subject: [PATCH] library: ensure thread group leader retrieval accuracy With that recent addition of the autogroup provisions, it became apparent that '/proc//task' information is sometimes incomplete. In fact, there's no autogroup file at all in any '/proc//task/' directory! As a result, when the top -H mode was invoked, all the processes showed a -1 for AGID, even the group leader. So, this commit will ensure that for every TGID leader its basic '/proc/' directory will always be used. The 'task' subdirectory is now only used for siblings. [ and it's time that readeither prologue was updated ] Signed-off-by: Jim Warner --- proc/readproc.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/proc/readproc.c b/proc/readproc.c index 03971c2f..e52b6a22 100644 --- a/proc/readproc.c +++ b/proc/readproc.c @@ -1452,12 +1452,11 @@ out: ////////////////////////////////////////////////////////////////////////////////// // readeither: return a pointer to a proc_t filled with requested info about // the next unique process or task available. If no more are available, -// return a null pointer (boolean false). Use the passed buffer instead -// of allocating space if it is non-NULL. +// return a null pointer (boolean false). proc_t *readeither (PROCTAB *restrict const PT, proc_t *restrict x) { static proc_t skel_p; // skeleton proc_t, only uses tid + tgid static proc_t *new_p; // for process/task transitions - static int canary; + static int canary, leader; char path[PROCPATHLEN]; proc_t *ret; @@ -1474,16 +1473,20 @@ next_proc: if (errno == ENOMEM) goto end_procs; // fills in the PT->path, plus skel_p.tid and skel_p.tgid if (!PT->finder(PT,&skel_p)) goto end_procs; // simple_nextpid + leader = skel_p.tid; if (!task_dir_missing) break; if ((ret = PT->reader(PT,x))) return ret; // simple_readproc } next_task: // fills in our path, plus x->tid and x->tgid - if ((!(PT->taskfinder(PT,&skel_p,x,path))) // simple_nexttid - || (!(ret = PT->taskreader(PT,x,path)))) { // simple_readtask + if (!(PT->taskfinder(PT,&skel_p,x,path))) // simple_nexttid goto next_proc; - } + /* to avoid loss of some thread group leader data, + we must check its base dir, not its 'task' dir! */ + if (x->tid == leader) ret = PT->reader(PT,x); // simple_readproc + else ret = PT->taskreader(PT,x,path); // simple_readtask + if (!ret) goto next_proc; if (!new_p) { new_p = ret; canary = new_p->tid;