Commit 18e5aecd authored by jim warner's avatar jim warner Committed by Craig Small

top: exploit msg handler override to avoid corrupt tty

Way back in November of 2011, the library was equipped
with an overridable error message handler function. It
was done expressly for a program like top which alters
the tty. But that support was withdrawn shortly after.

This was all done in the lead up to v3.3.2. That's the
release where NLS support was added and it represented
a hectic time. In hindsight, the changes went too far.

So this commit, in a minimal fashion, restores ability
to address a potential fatal library error. After all,
any properly behaving library would never unilaterally
subject a caller to a stderr message and then an exit.

[ when exposing 1 variable in libprocps.sym, 2 other ]
[ existing symbols were repositioned alphabetically. ]

Reference(s):
. generalized library memory provisions
commit 7126cc44
. top exploit library memory provisions
commit 88087ec5
. library xalloc type functions made private
commit 2865ded6
. restored prior top memory logic
commit 05f5deb9Signed-off-by: jim warner's avatarJim Warner <[email protected]>
parent 0a91e21d
......@@ -47,7 +47,9 @@ global:
page_bytes;
pretty_print_signals;
print_uptime;
procps_linux_version;
put_slabinfo;
pwcache_get_user;
readeither;
readproc;
readproctab2;
......@@ -62,8 +64,7 @@ global:
tty_to_dev;
unix_print_signals;
uptime;
pwcache_get_user;
procps_linux_version;
xalloc_err_handler;
local:
*;
};
......@@ -47,6 +47,7 @@
#include "../include/fileutils.h"
#include "../include/nls.h"
#include "../proc/alloc.h"
#include "../proc/devname.h"
#include "../proc/numa.h"
#include "../proc/procps.h"
......@@ -640,6 +641,20 @@ static void sig_resize (int dont_care_sig) {
Frames_signal = BREAK_sig;
(void)dont_care_sig;
} // end: sig_resize
/*
* Handles libproc memory errors, so our tty can be reset */
static void xalloc_our_handler (const char *fmts, ...) {
static char buf[MEDBUFSIZ];
va_list va;
va_start(va, fmts);
vsnprintf(buf, sizeof(buf), fmts, va);
va_end(va);
scat(buf, "\n");
bye_bye(buf);
} // end: xalloc_our_handler
/*###### Special UTF-8 Multi-Byte support ##############################*/
......@@ -3465,6 +3480,9 @@ static void before (char *me) {
// accommodate nls/gettext potential translations
initialize_nls();
// override default library memory alloc error handler
xalloc_err_handler = xalloc_our_handler;
// establish cpu particulars
#ifdef PRETEND8CPUS
smp_num_cpus = 8;
......
......@@ -681,6 +681,7 @@ typedef struct WIN_t {
//atic void sig_endpgm (int dont_care_sig);
//atic void sig_paused (int dont_care_sig);
//atic void sig_resize (int dont_care_sig);
//atic void xalloc_our_handler (const char *fmts, ...);
/*------ Special UTF-8 Multi-Byte support ------------------------------*/
/*atic char UTF8_tab[] = { ... } */
//atic int utf8_delta (const char *str);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment