top: adapt for running with proc mounted as subset=pid

As the issue cited below illustrates, a pids namespace
with proc mounted as subset=pid denies our library any
access to non-task data. In top's case, the result was
a fatal error message which involved "cpu statistics".

With this patch top will now assume an error involving
global cpu (stat) or memory (meminfo) data means we're
running under a restricted pids namespace. As such, an
attempt will be made to still display task level data.

[ if our assumption is incorrect, it's of no matter. ]
[ instead of a fatal error, we'll still try to offer ]
[ a user some minimally useful bit of functionality. ]

Reference(s):
https://gitlab.com/procps-ng/procps/-/issues/227
https://www.freelists.org/post/procps/three-for-newlib,1
. 1st cut at subset=pid
commit bcb837b8c7

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner
2021-12-16 00:00:00 -06:00
committed by Craig Small
parent b2c4fcfddb
commit 16145af663
3 changed files with 51 additions and 12 deletions

View File

@@ -571,6 +571,7 @@ static void build_norm_nlstab (void) {
Norm_nlstab[XTRA_warnold_txt] = _("saving prevents older top from reading, save anyway?");
Norm_nlstab[X_SEMAPHORES_fmt] = _("failed sem_init() at %d: %s");
Norm_nlstab[X_THREADINGS_fmt] = _("failed pthread_create() at %d: %s");
Norm_nlstab[X_RESTRICTED_txt] = _("sorry, restricted namespace with reduced functionality");
}