/*	    OS-9 Specific Code for the CERN/DD/OC RPC System	       rpc_os9.c
**	    ================================================
**
**  This file contains code which is specific to OS9 but not specific to
**  a particular transport service used by RPC.
**
**  HISTORY:
**
**	30 Oct 89   Written J. Raab, CERN/EP
**
*/
#include <types.h>
#include <errno.h>

#define ERR          -1
#define OK            1
#define READY         1
#define NOT_READY     0
#define SIG_V24     417
#define SIG_ETH     418

extern rpc_eth_close();

int dataready;


/*	Intercept Routine					        got_it()
**	-----------------
**
**  On entry,
**
**	sig_num	is the number of the signal which has been received.
**
**  On exit,
**	rpc signals cause the ready flag to be set.
**	^E signal causes a clean image exit
**	^C causes an immediate image exit.
**	Other signals are ignored
*/
static got_it(sig_num)
int sig_num;
{
    switch(sig_num) {
       case 228:           /* abrt from signal */
          rpc_eth_close(1);
          exit(sig_num);
          break;
       case 2:             /* ctrl-e */
          rpc_eth_close(1);
          exit(sig_num);
          break;
       case 3:             /* ctrl-c */
/*          exit(); */
          break;
       case SIG_V24:
          dataready = READY;
          break;
       case SIG_ETH:
          dataready = READY;
          break;
       default:
          break;
       }
}

/*	Set Up Intercept Routine				  rpc_os9_init()
**	------------------------
**
**  On exit,
**	No preconditions.
**
**  On exit,
**	The intercept routine has been declared.
*/
static int initialised = 0;
void rpc_os9_init()
{
    if (!initialised) {
	intercept(got_it);  /* Special OS9 C runtime library feature */
	initialised = 1;
    }
}

