From c767adf974c3a30fe5e1c0f76c446eaf0b898b16 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Tue, 12 Jul 2016 00:00:00 -0500 Subject: [PATCH] top: due to api, relocate that NUMA stderr hack So as to avoid that potential (and inappropriate) numa library spew to stderr, plus some resulting corruption of top's display, top buffered stderr output until the program ended. However, under our new library, timings have changed meaning the corruption could occur again. So this patch just relocates the stderr redirect to an earlier startup point ahead of the 1st call to . [ plus we also fiddle just a tad with a few comments ] Reference(s): . original libnuma fix commit 35dc6dcc49cc9cf8cff4300cb03a38dbe44c05db . original redhat discussion https://bugzilla.redhat.com/show_bug.cgi?id=998678 Signed-off-by: Jim Warner --- top/top.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) diff --git a/top/top.c b/top/top.c index 6932022f..da70ff0d 100644 --- a/top/top.c +++ b/top/top.c @@ -2184,9 +2184,8 @@ static void cpus_refresh (void) { /* - * This guy's responsible for interfacing with the library 'reap' pids - * and 'fill' stacks capabilities and refreshing the individual WIN_t - * head-of-stacks arrays, growing them as appropirate. */ + * This guy's responsible for interfacing with the library API + * then refreshing the WIN_t ptr arrays, growing them as appropirate. */ static void procs_refresh (void) { #define nALIGN(n,m) (((n + m - 1) / m) * m) // unconditionally align #define nALGN2(n,m) ((n + m - 1) & ~(m - 1)) // with power of 2 align @@ -2209,7 +2208,7 @@ static void procs_refresh (void) { if (!Pids_reap) error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__)); - // now refresh each window's stack heads pointers table... + // now refresh each window's stacks pointer array... if (n_alloc < n_reap) { // n_alloc = nALIGN(n_reap, 100); n_alloc = nALGN2(n_reap, 128); @@ -2807,6 +2806,17 @@ static void before (char *me) { // accommodate nls/gettext potential translations initialize_nls(); +#ifndef OFF_STDERROR + /* there's a chance that damn libnuma may spew to stderr so we gotta + make sure he does not corrupt poor ol' top's first output screen! + Yes, he provides some overridable 'weak' functions to change such + behavior but we can't exploit that since we don't follow a normal + ld route to symbol resolution (we use that dlopen() guy instead)! */ + Stderr_save = dup(fileno(stderr)); + if (-1 < Stderr_save && freopen("/dev/null", "w", stderr)) + ; // avoid -Wunused-result +#endif + // establish some cpu particulars Hertz = procps_hertz_get(); Cpu_States_fmts = N_unq(STATE_lin2x6_fmt); @@ -3629,17 +3639,6 @@ static void wins_stage_2 (void) { // fill in missing Fieldstab members and build each window's columnhdr zap_fieldstab(); -#ifndef OFF_STDERROR - /* there's a chance that damn libnuma may spew to stderr so we gotta - make sure he does not corrupt poor ol' top's first output screen! - Yes, he provides some overridable 'weak' functions to change such - behavior but we can't exploit that since we don't follow a normal - ld route to symbol resolution (we use that dlopen() guy instead)! */ - Stderr_save = dup(fileno(stderr)); - if (-1 < Stderr_save && freopen("/dev/null", "w", stderr)) - ; // avoid -Wunused-result -#endif - // lastly, initialize a signal set used to throttle one troublesome signal sigemptyset(&Sigwinch_set); #ifdef SIGNALS_LESS @@ -4470,8 +4469,8 @@ static void forest_adds (const int self, int level) { /* - * This routine is responsible for preparing the stacks array for - * a forest display in the designated window. Upon completion, + * This routine is responsible for preparing the stacks ptr array + * for forest display in the designated window. Upon completion, * he'll replace the original window ppt with our specially * ordered forest version. */ static void forest_begin (WIN_t *q) {