library: tweak 'other' user/group names for efficiency
This commit just ensures that the relatively expensive ID to name conversions aren't performed unless they're explicitly requested. It also internalizes those flags that required the PROC_FILLSTATUS flag to also be set. [ requiring a caller, in our case pids.c, to provide ] [ two flags when a single field was the objective is ] [ wrong & represents a future potential toe-stubber. ] [ moreover, what's worse is that those two flags are ] [ seemingly unrelated. but, without both, a SEGV can ] [ can be expected when a result.str pointer is NULL. ] [ by contrast, in the master branch those fields are ] [ arrays which, when set to zeroes, produce an empty ] [ string. So, there is no abend (but no name either) ] [ when one of those two required flags were omitted. ] [ and worth noting, in that branch it's not just one ] [ caller required to observe a two flag requirement. ] Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
@@ -1051,8 +1051,18 @@ static proc_t* simple_readproc(PROCTAB *restrict const PT, proc_t *restrict cons
|
||||
if (flags & PROC_FILLSTATUS) { // read /proc/#/status
|
||||
if (file2str(path, "status", &ub) != -1){
|
||||
rc += status2proc(ub.buf, p, 1);
|
||||
if (flags & PROC_FILLSUPGRP)
|
||||
if (flags & (PROC_FILL_SUPGRP & ~PROC_FILLSTATUS))
|
||||
rc += supgrps_from_supgids(p);
|
||||
if (flags & (PROC_FILL_OUSERS & ~PROC_FILLSTATUS)) {
|
||||
p->ruser = pwcache_get_user(p->ruid);
|
||||
p->suser = pwcache_get_user(p->suid);
|
||||
p->fuser = pwcache_get_user(p->fuid);
|
||||
}
|
||||
if (flags & (PROC_FILL_OGROUPS & ~PROC_FILLSTATUS)) {
|
||||
p->rgroup = pwcache_get_group(p->rgid);
|
||||
p->sgroup = pwcache_get_group(p->sgid);
|
||||
p->fgroup = pwcache_get_group(p->fgid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1063,25 +1073,10 @@ static proc_t* simple_readproc(PROCTAB *restrict const PT, proc_t *restrict cons
|
||||
|
||||
/* some number->text resolving which is time consuming */
|
||||
/* ( names are cached, so memcpy to arrays was silly ) */
|
||||
if (flags & PROC_FILLUSR){
|
||||
if (flags & PROC_FILLUSR)
|
||||
p->euser = pwcache_get_user(p->euid);
|
||||
if(flags & PROC_FILLSTATUS) {
|
||||
p->ruser = pwcache_get_user(p->ruid);
|
||||
p->suser = pwcache_get_user(p->suid);
|
||||
p->fuser = pwcache_get_user(p->fuid);
|
||||
}
|
||||
}
|
||||
|
||||
/* some number->text resolving which is time consuming */
|
||||
/* ( names are cached, so memcpy to arrays was silly ) */
|
||||
if (flags & PROC_FILLGRP){
|
||||
if (flags & PROC_FILLGRP)
|
||||
p->egroup = pwcache_get_group(p->egid);
|
||||
if(flags & PROC_FILLSTATUS) {
|
||||
p->rgroup = pwcache_get_group(p->rgid);
|
||||
p->sgroup = pwcache_get_group(p->sgid);
|
||||
p->fgroup = pwcache_get_group(p->fgid);
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & PROC_FILLENV) // read /proc/#/environ
|
||||
if (!(p->environ_v = file2strvec(path, "environ")))
|
||||
@@ -1165,32 +1160,27 @@ static proc_t* simple_readtask(PROCTAB *restrict const PT, proc_t *restrict cons
|
||||
if (flags & PROC_FILLSTATUS) { // read /proc/#/task/#/status
|
||||
if (file2str(path, "status", &ub) != -1) {
|
||||
rc += status2proc(ub.buf, t, 0);
|
||||
if (flags & PROC_FILLSUPGRP)
|
||||
if (flags & (PROC_FILL_SUPGRP & ~PROC_FILLSTATUS))
|
||||
rc += supgrps_from_supgids(t);
|
||||
if (flags & (PROC_FILL_OUSERS & ~PROC_FILLSTATUS)) {
|
||||
t->ruser = pwcache_get_user(t->ruid);
|
||||
t->suser = pwcache_get_user(t->suid);
|
||||
t->fuser = pwcache_get_user(t->fuid);
|
||||
}
|
||||
if (flags & (PROC_FILL_OGROUPS & ~PROC_FILLSTATUS)) {
|
||||
t->rgroup = pwcache_get_group(t->rgid);
|
||||
t->sgroup = pwcache_get_group(t->sgid);
|
||||
t->fgroup = pwcache_get_group(t->fgid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* some number->text resolving which is time consuming */
|
||||
/* ( names are cached, so memcpy to arrays was silly ) */
|
||||
if (flags & PROC_FILLUSR){
|
||||
if (flags & PROC_FILLUSR)
|
||||
t->euser = pwcache_get_user(t->euid);
|
||||
if(flags & PROC_FILLSTATUS) {
|
||||
t->ruser = pwcache_get_user(t->ruid);
|
||||
t->suser = pwcache_get_user(t->suid);
|
||||
t->fuser = pwcache_get_user(t->fuid);
|
||||
}
|
||||
}
|
||||
|
||||
/* some number->text resolving which is time consuming */
|
||||
/* ( names are cached, so memcpy to arrays was silly ) */
|
||||
if (flags & PROC_FILLGRP){
|
||||
if (flags & PROC_FILLGRP)
|
||||
t->egroup = pwcache_get_group(t->egid);
|
||||
if(flags & PROC_FILLSTATUS) {
|
||||
t->rgroup = pwcache_get_group(t->rgid);
|
||||
t->sgroup = pwcache_get_group(t->sgid);
|
||||
t->fgroup = pwcache_get_group(t->fgid);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef FALSE_THREADS
|
||||
if (!IS_THREAD(t)) {
|
||||
|
Reference in New Issue
Block a user