The termination user function

You can define your own termination function to perform program termination tasks such as closing databases and disconnecting communication links in case of terminal processing errors. When you define a custom server, you can specify the name of a termination user function. This function is linked with your other user functions and the main() function in the build process. You can use a termination user function with a main() function you have written, or a system-generated one.

The termination user function is called automatically when the system is shut down by the system administrator.

The SIGINT signal is used to request a custom server to terminate gracefully. When a custom server calls the CA_Init() subroutine, a signal handler for the SIGINT signal is provided that calls the specified termination user function.

When you terminate a custom server, a SIGINT signal is sent to the custom server, which, in turn, sets a terminate flag. Every time the custom server invokes one of the custom server subroutines, this flag is examined and, if it has been set, the termination user function is invoked and the custom server exits. If a user function includes a program loop that does not have any exit criteria, the loop must contain at least one custom server subroutine, otherwise the custom server will not terminate successfully.

Note:
  1. If you provide another signal handler for the SIGINT signal and activate it, it will override the one provided by Blueworx Voice Response, and graceful termination is your responsibility.
  2. You cannot use CA calls in a signal handler as they are not reentrant with respect to signals. For more information on which functions can be used in a signal handler, see the description of the sigaction() function in the AIX Base Operating System and Extensions Technical Reference book.

An example of a termination user function:

extern FILE *file1_fp;
extern FILE *file2_fp;
void close_files(void)
{
   fclose(file1_fp);
   fclose(file2_fp);
   return;
}

Notes:

  1. The termination function must return to the main() function which ends the custom server process after it has done its own clean up. Do not invoke the exit() subroutine from the termination function.
  2. Also, don’t call a custom server subroutine from the custom server termination function. If you do, you will get error code 161, CA_TERMINATING.
  3. The termination function must return void, and have void parameters.

To define a termination user function, see Defining the main() function.