Hands-on Projects for the Linux Graphics Subsystem

Implementation of the SIGIO signal handler

As seen in section 5.1 function xf86AddEnabledDevice() is called from MouseProc() (generally speaking the pInfo->device_control routine) when called with a DEVICE_ON as the second argument. It is implemented as:

xf86InstallSIGIOHandler() installs xf86SigioReadInput() as the function that responds to a SIGIO signal. This signal is issued when input is available from a certain input device file descriptor (fd). Normally SIGIO can not be assigned to a specific fd however this is solved through an indirect way:

xf86InstallSIGIOHandler() calls sigaction() to install xf86SIGIO() as the signal handler for SIGIO and this function will do what its comment notes:

* SIGIO gives no way of discovering which fd signalled, select
* to discover

Therefore to install a signal handler, for instance function f, for a specific fd via xf86InstallSIGIOHandler() another function, xf86SIGIO(), is assigned as the signal handler and this function represents all others signal handlers set by different fds. It uses the array xf86SigIOFuncs[] to store at the next available element a Xf86SigIOFunc struct, which includes the fd of the device, the specific handler (f) and the pInfo (InputInfoPtr) of the device, referred here as 'closure'. Also the fd in included in the xf86SigIOMask fd set.

When xf86SIGIO() runs it uses the select() system call to find the ready fds from xf86SigIOMask and return its number to xf86SigIOMaxFd. Then it searches in xf86SigIOFuncs[] to locate the array's items with the fds that are included in xf86SigIOMask. For those items the specific handler routine is called as: