From fe0f9fff2cfe83e90b8ef663c11a31fbde4d3a8e Mon Sep 17 00:00:00 2001 From: Nick Briggs Date: Wed, 16 Dec 2020 22:09:18 -0800 Subject: [PATCH] FD_ISSET requires that the fd being tested is >= 0 (#78) * FD_ISSET requires that the fd being tested is >= 0, so unset fd -1 causes trouble. * Remove code to enable X I/O signal generation from xinit.c If the I/O signals are enabled before the signal handler has been set up, the default action on receipt of a SIGPOLL or SIGIO will be that the program exits. For now, turn the signals off, as they aren't necessary and may not even be an improvement. * Ensure fds are declared as signed and initialized (to -1) The global fds may be accessed from the signal handler before any particular device has been opened. Ensure that the fds are initialized statically and that the value is distinguishable from all valid descriptors. modified: initdsp.c modified: initkbd.c modified: keyevent.c modified: osmsg.c modified: rs232c.c modified: timer.c modified: tty.c --- src/initdsp.c | 4 ++-- src/initkbd.c | 2 +- src/keyevent.c | 12 ++++++------ src/osmsg.c | 2 +- src/rs232c.c | 2 +- src/timer.c | 2 +- src/tty.c | 2 +- src/xinit.c | 3 --- 8 files changed, 13 insertions(+), 16 deletions(-) diff --git a/src/initdsp.c b/src/initdsp.c index 41bc8dc..4e2ed04 100644 --- a/src/initdsp.c +++ b/src/initdsp.c @@ -108,8 +108,8 @@ int oldred[2], oldgreen[2], oldblue[2]; #endif /* DISPLAYBUFFER */ #endif /* NOPIXRECT */ -int LispWindowFd; -int FrameBufferFd; +int LispWindowFd = -1; +int FrameBufferFd = -1; int displaywidth, displayheight, DisplayRasterWidth, DisplayType; int DisplayByteSize; diff --git a/src/initkbd.c b/src/initkbd.c index 07c960e..ce9da16 100644 --- a/src/initkbd.c +++ b/src/initkbd.c @@ -123,7 +123,7 @@ extern struct screen LispScreen; #endif /* SUNDISPLAY */ extern int LispWindowFd; -int LispKbdFd; +int LispKbdFd = -1; extern int errno; /* for debug */ diff --git a/src/keyevent.c b/src/keyevent.c index 3d03610..35fda58 100644 --- a/src/keyevent.c +++ b/src/keyevent.c @@ -124,11 +124,11 @@ extern fd_set LispIOFds; fd_set LispReadFds; int XNeedSignal = 0; /* T if an X interrupt happened while XLOCK asserted */ +extern int LogFileFd; + #ifdef NOETHER -extern u_int LogFileFd; #else extern int ether_fd; -extern u_int LogFileFd; #endif /* NOETHER */ extern DLword *DisplayRegion68k; @@ -316,7 +316,7 @@ getmore: */ #ifdef SUNDISPLAY - if (FD_ISSET(LispWindowFd, &rfds)) { + if (LispWindowFd >= 0 && FD_ISSET(LispWindowFd, &rfds)) { /* #endif */ while (input_readevent(LispWindowFd, &event) >= 0) { /*if(!kb_event( &event )) {goto getmore;};*/ @@ -341,19 +341,19 @@ getmore: #ifdef NOETHER #else - if (FD_ISSET(ether_fd, &rfds)) { /* Raw ethernet (NIT) I/O happened, so handle it. */ + if (ether_fd >= 0 && FD_ISSET(ether_fd, &rfds)) { /* Raw ethernet (NIT) I/O happened, so handle it. */ DBPRINT(("Handling enet interrupt.\n\n")); check_ether(); } #endif /* NOETHER */ #ifdef RS232 - if (FD_ISSET(RS232C_Fd, &rfds) || (RS232C_remain_data && rs232c_lisp_is_ready())) + if (RS232C_Fd >= 0 && (FD_ISSET(RS232C_Fd, &rfds) || (RS232C_remain_data && rs232c_lisp_is_ready()))) rs232c_read(); #endif /* RS232 */ #ifdef LOGINT - if (FD_ISSET(LogFileFd, &rfds)) { /* There's info in the log file. Tell Lisp to print it. */ + if (LogFileFd >= 0 && FD_ISSET(LogFileFd, &rfds)) { /* There's info in the log file. Tell Lisp to print it. */ flush_pty(); /* move the msg(s) to the log file */ ((INTSTAT *)Addr68k_from_LADDR(*INTERRUPTSTATE_word))->LogFileIO = 1; diff --git a/src/osmsg.c b/src/osmsg.c index bf7f015..3166202 100644 --- a/src/osmsg.c +++ b/src/osmsg.c @@ -64,7 +64,7 @@ int log_id; int previous_size; int logChanged; /* T if log file has changed since last READ */ /* Set by flush_pty, to avoid the stat call */ -u_int LogFileFd; +int LogFileFd = -1; extern fd_set LispReadFds; /************************************************************************/ diff --git a/src/rs232c.c b/src/rs232c.c index 8790f2e..6f136af 100644 --- a/src/rs232c.c +++ b/src/rs232c.c @@ -29,7 +29,7 @@ static DLword *RS232CGetCSB, *RS232CPutCSB; * File descriptor */ extern fd_set LispReadFds; -int RS232C_Fd; +int RS232C_Fd = -1; int RS232C_remain_data; static char *RS232C_Dev; diff --git a/src/timer.c b/src/timer.c index b50ba46..dba2307 100644 --- a/src/timer.c +++ b/src/timer.c @@ -460,7 +460,7 @@ int TIMER_INTERVAL = 25000; int FileIOFlag = 0; int TimerFlag = 0; -extern u_int LispWindowFd; +extern int LispWindowFd; /************************************************************************/ /* */ diff --git a/src/tty.c b/src/tty.c index 3be69b7..a0cc488 100644 --- a/src/tty.c +++ b/src/tty.c @@ -18,7 +18,7 @@ DLTTY_IN_CSB *DLTTYIn; DLTTY_OUT_CSB *DLTTYOut; char *TTY_Dev; -int TTY_Fd; +int TTY_Fd = -1; extern fd_set LispReadFds; struct sgttyb TTY_Mode; diff --git a/src/xinit.c b/src/xinit.c index 7ed4d18..0177882 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -99,9 +99,6 @@ void init_Xevent(DspInterface dsp) XSelectInput(dsp->display_id, dsp->SWGrav, GravMask); XSelectInput(dsp->display_id, dsp->NWGrav, GravMask); -#if defined(OS5) && defined(I_SETSIG) - ioctl(ConnectionNumber(dsp->display_id), I_SETSIG, S_INPUT); /* so we see X events fast */ -#endif } /*end init_Xevent */ /************************************************************************/