When top originally responded to the potential libnuma
stderr write, the library was consistently called with
each refresh cycle. That, in turn, guaranteed that any
warning message would be seen at program end by virtue
of: 1) having been issued before the 2nd refresh cycle
and; 2) benefiting from inherited /dev/null buffering.
A later efficiency refactor meant the numa library may
not always be called with every refresh cycle. Rather,
it was only called if top was in one of two numa views
(the '2' or '3' toggles). That, in turn, resulted in a
loss of any warning message at program end unless numa
mode had been preserved in the rcfile. In other words,
if top was started normally then a single cycle stderr
redirect would have long passed by the time the '2' or
'3' toggle was activated. The warning message actually
was spewed but quickly lost to the full screen refresh
which follows all keyboard interactions with the user.
This commit simply moves the restoration of our stderr
redirect to program end (instead of that first display
refresh). Now, any libnuma stderr warning message will
appear as the concluding output line upon quitting top
without regard to when any numa mode view was invoked.
And since this technique might be useful in some other
context (as an example of how to 'buffer' stderr) it's
been generalized with its own #define. But to maximize
its usefulness, the original redirect should be issued
much earlier in pgm startup than top has chosen to do.
Reference(s):
. original libnuma stderr response (msg seen)
commit
35dc6dcc49cc9cf8cff4300cb03a38dbe44c05db
. numa refractoring for efficiency (msg lost)
commit
f12c0d5c6e84f9409ac3a73c066841a8ff5aab0b
Signed-off-by: Jim Warner <james.warner@comcast.net>
/* Support for NUMA Node display, node expansion/targeting and
run-time dynamic linking with libnuma.so treated as a plugin */
+#ifndef OFF_STDERROR
+static int Stderr_save = -1;
+#endif
static int Numa_node_tot;
static int Numa_node_sel = -1;
#ifndef NUMA_DISABLE
static void *Libnuma_handle;
-static int Stderr_save = -1;
#if defined(PRETEND_NUMA) || defined(PRETEND8CPUS)
static int Numa_max_node(void) { return 3; }
#ifndef OFF_NUMASKIP
#endif
}
fflush(stdout);
+#ifndef OFF_STDERROR
+ /* we gotta reverse the stderr redirect which was employed during start up
+ and needed because the two libnuma 'weak' functions were useless to us! */
+ if (-1 < Stderr_save) {
+ dup2(Stderr_save, fileno(stderr));
+ close(Stderr_save);
+ Stderr_save = -1; // we'll be ending soon anyway but what the heck
+ }
+#endif
} // end: at_eoj
// fill in missing Fieldstab members and build each window's columnhdr
zap_fieldstab();
-#ifndef NUMA_DISABLE
+#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
the normal non-interactive output optimization... */
if (!Cap_can_goto) PSU_CLREOS(0);
-#ifndef NUMA_DISABLE
- /* we gotta reverse the stderr redirect which was employed in wins_stage_2
- and needed because the two libnuma 'weak' functions were useless to us! */
- if (-1 < Stderr_save) {
- dup2(Stderr_save, fileno(stderr));
- close(Stderr_save);
- Stderr_save = -1;
- }
-#endif
-
/* lastly, check auto-sized width needs for the next iteration */
if (AUTOX_MODE && Autox_found)
widths_resize();
//#define OFF_HST_HASH /* use BOTH qsort+bsrch vs. hashing scheme */
//#define OFF_NUMASKIP /* do NOT skip numa nodes if discontinuous */
//#define OFF_SCROLLBK /* disable tty emulators scrollback buffer */
+//#define OFF_STDERROR /* disable our stderr buffering (redirect) */
//#define OFF_STDIOLBF /* disable our own stdout _IOFBF override */
//#define PRETEND2_5_X /* pretend we're linux 2.5.x (for IO-wait) */
//#define PRETEND8CPUS /* pretend we're smp with 8 ticsers (sic) */