Custom signal processing

The D3 libraries make extensive use of signal processing. Because of this, the practice of reprogramming signals within a C application using D3 C routines is strongly discouraged. However, if it is absolutely necessary, there are several rules which must be followed.

When calling _CP_logon, all signals are rerouted to D3 signal handlers. When calling _CP_logoff, all signals are rerouted to UNIX defaults. Note that they are not necessarily reset to the values they held before the _CP_logon call.

The signal SIGUSR2 must never be reprogrammed as it is used by D3 for logging off and sending messages. Because interrupts may occur within critical code, the user may not make calls to _CP_ functions within signal handlers.

Example(s)

/* Prints the name of all users in the users file. */
#include "CPuser.h"
main()
{
CPSTR * machine = _CP_mkstrl("pick0",5); /* default */
CPSTR * user = _CP_mkstrl("dm",2);
CPSTR * md = _CP_mkstrl("dm",2);
CPSTR * filename = _CP_mkstrl("users",5);
int fd = -1;
int sl = -1; /* initialize select list */
CPSTR * item_id = _CP_str_null;
/* Logon onto "pick0" as "dm" in the "dm" md */
if (_CP_logon(machine, user, _CP_str_null,
md, _CP_str_null, -1, 0) < 0)
{
printf("Logon error %d\n", _CP_errno);
exit(1);
}
/* done with machine, user, and md */
_CP_str_free(machine);
_CP_str_free(user);
_CP_str_free(md);
/* Make the break key terminate the program */
_CP_unix_break();
/* Open the users file into the file descriptor fd */
if (_CP_open(&fd, _CP_str_null, filename) < 0)
{
_CP_logoff();
printf("Could not open users file \n");
exit(2);
}
/* done with filename */
_CP_str_free(filename);
/* Do a raw select of "users" and store that select
list in the select list descriptor sl */
_CP_select(fd, &sl, 0);
/* Switch to Unix-type I/O so we can use printf */
_CP_unix_env();
/* repeatedly read item-IDs and print them as a list */
/* Note how item_id is repeatedly passed to _CP_readnext.
Each time, _CP_readnext will resize it if necessary,
and write the next item-ID into that CPSTR */
while (_CP_readnext(&item_id, &sl, 0, 0) >= 0)
{
_CP_TERM(item_id); /* terminate for printf */
printf("%s\n", _CP_SADDR(item_id));
}
/* done with item_id - Not absolutely necessary since */
/* it will be cleaned up when we exit */
_CP_str_free(item_id);
/* logoff and return */
_CP_logoff();
return 0;
}