srv_signal (UNIX only)

Description

Install a signal handler.

Syntax

SRV_SIGNAL_FUNC srv_signal(sig, handler)
CS_INT                       sig;
SRV_SIGNAL_FUNC handler;

Parameters

sig

The number of the UNIX signal for which a handler is installed. This is defined in sgs/signal.h.

handler

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

Table 3-129:  Return values (srv_signal)

Returns

To indicate

A pointer to the previously installed handler function.

The location of the function.

A null pointer

The routine failed.

Examples

Example 1

#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++;
      }
}

Usage