Install a signal handler.
SRV_SIGNAL_FUNC srv_signal(sig, handler)
CS_INT sig; SRV_SIGNAL_FUNC handler;
The number of the UNIX signal for which a handler is installed. This is defined in sgs/signal.h.
A pointer to a function that is called when sig is delivered to Open Server. Setting handler to SIG_DFL restores the default handler. Setting handler to SIG_IGN cause sig to be ignored.
Returns |
To indicate |
---|---|
A pointer to the previously installed handler function. |
The location of the function. |
A null pointer |
The routine failed. |
#include <errno.h>
#include <stdio.h>
#include <signal.h>
#include <ospublic.h>
/*
** Local Prototype.
*/
CS_STATIC CS_VOID ex_sigio_handler PROTOTYPE((
CS_INT sig
));
CS_RETCODE ex_srv_signal PROTOTYPE((
CS_INT *uerrno
));
/*
** Static storage.
*/
CS_STATIC CS_INT io_events = 0;
/*
** EX_SRV_SIGNAL
**
** Example routine to install a UNIX signal handler for SIGIO,
** using srv_signal.
**
** Arguments:
** uerrno A pointer to a user’s error number indicator.
**
** Returns:
**
** CS_SUCCEED Handler successfully installed.
** CS_FAIL Handler not installed, UNIX global errno set.
*/
CS_RETCODE ex_srv_signal(uerrno)
CS_INT *uerrno;
{
/*
** Install the handler.
*/
(CS_VOID)srv_signal((int)SIGIO,
(SRV_SIGNAL_FUNC)ex_sigio_handler);
/* Was there an error condition? */
if ((*uerrno = errno) != 0)
return(CS_FAIL);
return(CS_SUCCEED);
}
/*
** EX_SIGIO_HANDLER
**
** Example signal handler to count I/O events. It prints a
** message when the Open Server application has been up long
** enough to get 100,000 I/O events.
**
** Arguments:
** sig The signal number, always SIGIO.
**
** Returns:
** Nothing.
*/
CS_STATIC CS_VOID ex_sigio_handler(sig)
CS_INT sig;
{
if (io_events == 100000)
{
fprintf(stderr, “The server has been up a long
time!!\n”);
io_events = 0;
}
else
{
io_events++;
}
}
Open Server installs UNIX signal handlers for SIGIO and SIGURG. These handlers must always be active once an Open Server is started. If they are not active, the Server-Library I/O and attention handling routines will either fail to function or will be unreliable.
WARNING! Installing a UNIX signal handler using sigvec(2) or signal(2) can cause unpredictable results. Applications should use srv_signal.
Open Server guarantees that all other signals are blocked while the application is in the signal handler.
UNIX documentation on signal.