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 commit7126cc4491
. top exploit library memory provisions commit88087ec5a5
. library xalloc type functions made private commit2865ded64e
. restored prior top memory logic commit05f5deb97c
Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
0a91e21d3a
commit
18e5aecd2b
@ -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:
|
||||
*;
|
||||
};
|
||||
|
18
top/top.c
18
top/top.c
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user