- This implements a solution that lets any GUI take over handling of any

signal.  First, selection of the GUI should cause BX_GUI_SIGHANDLER to
  be defined in config.h.in.  Then, the GUI should define member functions
    Bit32u get_sighandler_mask ();
    void sighandler (int sig);
  The mask function returns a bitfield where one bit corresponds to each
  signal.  For any signal whose bit is set to 1 in the return value of
  get_sighandler_mask, the gui will control that signal.  When the signal
  arrives, bx_gui.sighandler(sig) will be called by bx_signal_handler,
  instead of the default behavior of that signal.
This commit is contained in:
Bryce Denney 2001-05-08 20:18:04 +00:00
parent 545355f9b4
commit e363f402ca
7 changed files with 49 additions and 20 deletions

View File

@ -260,6 +260,7 @@ typedef struct {
void* record_io;
} bx_debug_t;
void bx_signal_handler (int signum);
void bx_printf(char *fmt, ...);
void bx_panic(char *fmt, ...);
void bx_atexit(void);

View File

@ -404,6 +404,9 @@ typedef unsigned int Boolean;
#endif
#endif // BX_WITH_WIN32
// for now only term.cc requires a GUI sighandler.
#define BX_GUI_SIGHANDLER (BX_WITH_TERM)
#define HAVE_SIGACTION 1
// configure will change the definition of "inline" to the value

View File

@ -353,6 +353,7 @@ process_sim2:
// (mch) Moved from main.cc
bx_devices.init();
bx_gui.init_signal_handlers ();
bx_pc_system.start_timers();
// setup Ctrl-C handler

View File

@ -21,7 +21,7 @@
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#include <signal.h>
#include "bochs.h"
#include "gui/bitmaps/floppya.h"
#include "gui/bitmaps/floppyb.h"
@ -190,3 +190,16 @@ bx_gui_c::gui_set_mouse_enable(Boolean val)
{
bx_options.mouse_enabled = val;
}
void
bx_gui_c::init_signal_handlers ()
{
#if BX_GUI_SIGHANDLER
Bit32u mask = get_sighandler_mask ();
for (Bit32u sig=0; sig<32; sig++)
{
if (mask & (1<<sig))
signal (sig, bx_signal_handler);
}
#endif
}

View File

@ -51,6 +51,14 @@ public:
static Boolean gui_get_mouse_enable(void);
static void gui_set_mouse_enable(Boolean val);
static void exit(void);
static void init_signal_handlers ();
#if BX_GUI_SIGHANDLER
// returns 32-bit bitmask in which 1 means the GUI should handle that signal
static Bit32u get_sighandler_mask ();
// called when registered signal arrives
static void sighandler (int sig);
#endif
private:
// And these are defined and used privately in gui.cc

View File

@ -79,8 +79,20 @@ do_scan(int key_event, int shift, int ctrl, int alt)
// always assumes the width of the current VGA mode width, but
// it's height is defined by this parameter.
static void
guisig(int signo)
Bit32u
bx_gui_c::get_sighandler_mask ()
{
return
(1<<SIGHUP)
| (1<<SIGINT)
| (1<<SIGQUIT)
| (1<<SIGSTOP)
| (1<<SIGTSTP)
| (1<<SIGTERM);
}
void
bx_gui_c::sighandler(int signo)
{
switch(signo) {
case SIGINT:
@ -124,14 +136,6 @@ bx_gui_c::specific_init(bx_gui_c *th, int argc, char **argv, unsigned tilewidth,
nodelay(stdscr, TRUE);
noecho();
bx_printf ("bx_gui_c::specific_init is defining signal handlers now");
(void)signal(SIGHUP, guisig);
(void)signal(SIGINT, guisig);
(void)signal(SIGQUIT, guisig);
(void)signal(SIGSTOP, guisig);
(void)signal(SIGTSTP, guisig);
(void)signal(SIGTERM, guisig);
if (bx_options.private_colormap)
if(bx_dbg.video)
bx_printf("#TERM] WARNING: private_colormap option ignored.\n");

View File

@ -22,14 +22,6 @@
void bx_signal_handler(int signum);
#include "bochs.h"
#include "state_file.h"
@ -188,7 +180,7 @@ bx_bochs_init(int argc, char *argv[])
#if BX_DEBUGGER == 0
bx_devices.init();
bx_gui.init_signal_handlers ();
bx_pc_system.start_timers();
#endif
@ -928,5 +920,12 @@ bx_signal_handler( int signum)
}
#endif
#if BX_GUI_SIGHANDLER
if ((1<<signum) & bx_gui.get_sighandler_mask ()) {
bx_gui.sighandler (signum);
return;
}
#endif
bx_panic("SIGNAL %u caught\n", signum);
}