top: let's exploit the new standardized errno handling

With the library having now normalized errno handling,
perhaps it is time at least one program took advantage
of it. So, instead of printing just a message with the
programs's line number, top will now also provide that
associated errno string text, compliments of strerror.

[ with those newlib functions returning NULL, we can ]
[ use errno directly in strerror. for the ones which ]
[ yield an int, all we need do is invert such return ]
[ values before passing it to the strerror function. ]

Reference(s):

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2017-12-16 00:00:00 -06:00 committed by Craig Small
parent 71b3de01f2
commit 0a502adfd0
2 changed files with 20 additions and 19 deletions

View File

@ -1895,7 +1895,7 @@ static void calibrate_fields (void) {
char *s; char *s;
const char *h; const char *h;
WIN_t *w = Curwin; WIN_t *w = Curwin;
int i, varcolcnt, len; int i, varcolcnt, len, rc;
adj_geometry(); adj_geometry();
@ -1974,8 +1974,8 @@ static void calibrate_fields (void) {
build_headers(); build_headers();
if (procps_pids_reset(Pids_ctx, Pids_itms, Pids_itms_cur)) if ((rc = procps_pids_reset(Pids_ctx, Pids_itms, Pids_itms_cur)))
error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__)); error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__, strerror(-rc)));
if (CHKw(Curwin, View_SCROLL)) if (CHKw(Curwin, View_SCROLL))
updt_scroll_msg(); updt_scroll_msg();
@ -2293,7 +2293,7 @@ static void cpus_refresh (void) {
Stat_reap = procps_stat_reap(Stat_ctx, which, Stat_items, MAXTBL(Stat_items)); Stat_reap = procps_stat_reap(Stat_ctx, which, Stat_items, MAXTBL(Stat_items));
if (!Stat_reap) if (!Stat_reap)
error_exit(fmtmk(N_fmt(LIB_errorcpu_fmt),__LINE__)); error_exit(fmtmk(N_fmt(LIB_errorcpu_fmt),__LINE__, strerror(errno)));
// adapt to changes in total numa nodes (assuming it's even possible) // adapt to changes in total numa nodes (assuming it's even possible)
if (Stat_reap->nodes->total && Stat_reap->nodes->total != Numa_node_tot) { if (Stat_reap->nodes->total && Stat_reap->nodes->total != Numa_node_tot) {
Numa_node_tot = Stat_reap->nodes->total; Numa_node_tot = Stat_reap->nodes->total;
@ -2328,7 +2328,7 @@ static void procs_refresh (void) {
if (Monpidsidx) Pids_reap = procps_pids_select(Pids_ctx, Monpids, Monpidsidx, PIDS_SELECT_PID); if (Monpidsidx) Pids_reap = procps_pids_select(Pids_ctx, Monpids, Monpidsidx, PIDS_SELECT_PID);
else Pids_reap = procps_pids_reap(Pids_ctx, Thread_mode ? PIDS_FETCH_THREADS_TOO : PIDS_FETCH_TASKS_ONLY); else Pids_reap = procps_pids_reap(Pids_ctx, Thread_mode ? PIDS_FETCH_THREADS_TOO : PIDS_FETCH_TASKS_ONLY);
if (!Pids_reap) if (!Pids_reap)
error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__)); error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__, strerror(errno)));
// now refresh each window's stacks pointer array... // now refresh each window's stacks pointer array...
if (n_alloc < n_reap) { if (n_alloc < n_reap) {
@ -2361,7 +2361,7 @@ static void sysinfo_refresh (int forced) {
if (3 <= cur_secs - sav_secs) { if (3 <= cur_secs - sav_secs) {
if (!(Mem_stack = procps_meminfo_select(Mem_ctx, Mem_items, MAXTBL(Mem_items)))) if (!(Mem_stack = procps_meminfo_select(Mem_ctx, Mem_items, MAXTBL(Mem_items))))
error_exit(fmtmk(N_fmt(LIB_errormem_fmt),__LINE__)); error_exit(fmtmk(N_fmt(LIB_errormem_fmt),__LINE__, strerror(errno)));
sav_secs = cur_secs; sav_secs = cur_secs;
} }
} // end: sysinfo_refresh } // end: sysinfo_refresh
@ -2995,7 +2995,7 @@ signify_that:
* IMPORTANT stuff upon which all those lessor functions depend! */ * IMPORTANT stuff upon which all those lessor functions depend! */
static void before (char *me) { static void before (char *me) {
struct sigaction sa; struct sigaction sa;
int i; int i, rc;
int linux_version_code = procps_linux_version(); int linux_version_code = procps_linux_version();
enum stat_reap_type which = STAT_REAP_CPUS_AND_NODES; enum stat_reap_type which = STAT_REAP_CPUS_AND_NODES;
@ -3029,15 +3029,16 @@ static void before (char *me) {
Cpu_States_fmts = N_unq(STATE_lin2x7_fmt); Cpu_States_fmts = N_unq(STATE_lin2x7_fmt);
// get the total cpus (and, if possible, numa node total) // get the total cpus (and, if possible, numa node total)
if (procps_stat_new(&Stat_ctx) < 0 if ((rc = procps_stat_new(&Stat_ctx)))
|| !(Stat_reap = procps_stat_reap(Stat_ctx, which, Stat_items, MAXTBL(Stat_items)))) error_exit(fmtmk(N_fmt(LIB_errorcpu_fmt),__LINE__, strerror(-rc)));
error_exit(fmtmk(N_fmt(LIB_errorcpu_fmt),__LINE__)); if (!(Stat_reap = procps_stat_reap(Stat_ctx, which, Stat_items, MAXTBL(Stat_items))))
error_exit(fmtmk(N_fmt(LIB_errorcpu_fmt),__LINE__, strerror(errno)));
Numa_node_tot = Stat_reap->nodes->total; Numa_node_tot = Stat_reap->nodes->total;
Cpu_cnt = Stat_reap->cpus->total; Cpu_cnt = Stat_reap->cpus->total;
// prepare for memory stats from new library API ... // prepare for memory stats from new library API ...
if (procps_meminfo_new(&Mem_ctx) < 0) if ((rc = procps_meminfo_new(&Mem_ctx)))
error_exit(fmtmk(N_fmt(LIB_errormem_fmt),__LINE__)); error_exit(fmtmk(N_fmt(LIB_errormem_fmt),__LINE__, strerror(-rc)));
// establish max depth for newlib pids stack (# of result structs) // establish max depth for newlib pids stack (# of result structs)
Pids_itms = alloc_c(sizeof(enum pids_item) * MAXTBL(Fieldstab)); Pids_itms = alloc_c(sizeof(enum pids_item) * MAXTBL(Fieldstab));
@ -3046,8 +3047,8 @@ static void before (char *me) {
Pids_itms[i] = PIDS_noop; Pids_itms[i] = PIDS_noop;
Pids_itms_cur = MAXTBL(Fieldstab); Pids_itms_cur = MAXTBL(Fieldstab);
// we will identify specific items in the build_headers() function // we will identify specific items in the build_headers() function
if (procps_pids_new(&Pids_ctx, Pids_itms, Pids_itms_cur)) if ((rc = procps_pids_new(&Pids_ctx, Pids_itms, Pids_itms_cur)))
error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__)); error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__, strerror(-rc)));
#ifndef SIGRTMAX // not available on hurd, maybe others too #ifndef SIGRTMAX // not available on hurd, maybe others too
#define SIGRTMAX 32 #define SIGRTMAX 32
@ -4721,7 +4722,7 @@ static void forest_begin (WIN_t *q) {
#ifndef TREE_SCANALL #ifndef TREE_SCANALL
if (!(procps_pids_sort(Pids_ctx, Seed_ppt, PIDSmaxt if (!(procps_pids_sort(Pids_ctx, Seed_ppt, PIDSmaxt
, PIDS_TIME_START, PIDS_SORT_ASCEND))) , PIDS_TIME_START, PIDS_SORT_ASCEND)))
error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__)); error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__, strerror(errno)));
#endif #endif
for (i = 0; i < PIDSmaxt; i++) // avoid any hidepid distortions for (i = 0; i < PIDSmaxt; i++) // avoid any hidepid distortions
if (!rLevel) // identify real or pretend trees if (!rLevel) // identify real or pretend trees
@ -5316,7 +5317,7 @@ static int window_show (WIN_t *q, int wmax) {
else if (item == PIDS_TICS_ALL && CHKw(q, Show_CTIMES)) else if (item == PIDS_TICS_ALL && CHKw(q, Show_CTIMES))
item = PIDS_TICS_ALL_C; item = PIDS_TICS_ALL_C;
if (!(procps_pids_sort(Pids_ctx, q->ppt , PIDSmaxt, item, sORDER))) if (!(procps_pids_sort(Pids_ctx, q->ppt , PIDSmaxt, item, sORDER)))
error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__)); error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__, strerror(errno)));
} }
i = q->begtask; i = q->begtask;

View File

@ -496,9 +496,9 @@ static void build_norm_nlstab (void) {
. padding with extra spaces as necessary */ . padding with extra spaces as necessary */
Norm_nlstab[WORD_abv_mem_txt] = _("Mem "); Norm_nlstab[WORD_abv_mem_txt] = _("Mem ");
Norm_nlstab[WORD_abv_swp_txt] = _("Swap"); Norm_nlstab[WORD_abv_swp_txt] = _("Swap");
Norm_nlstab[LIB_errormem_fmt] = _("library failed memory statistics, at %d"); Norm_nlstab[LIB_errormem_fmt] = _("library failed memory statistics, at %d: %s");
Norm_nlstab[LIB_errorcpu_fmt] = _("library failed cpu statistics, at %d"); Norm_nlstab[LIB_errorcpu_fmt] = _("library failed cpu statistics, at %d: %s");
Norm_nlstab[LIB_errorpid_fmt] = _("library failed pids statistics, at %d"); Norm_nlstab[LIB_errorpid_fmt] = _("library failed pids statistics, at %d: %s");
Norm_nlstab[BAD_memscale_fmt] = _("bad memory scaling arg '%c'"); Norm_nlstab[BAD_memscale_fmt] = _("bad memory scaling arg '%c'");
} }