Guardian Programmer's Guide

Table Of Contents
Fault-Tolerant Programming in C
Guardian Programmer’s Guide 421922-014
27 - 59
Primary and Backup Processing
/*This function is called by the primary process to update the
state of the backup process. It creates and sends a message to
the backup process.*/
void update_backup (void)
{
short cond_code;
short error;
message_format message;
/*Create update message*/
message.msgnumber = UPDATE_MESSAGE;
error = __ns_fget_file_state (infile,
&message.msg_variants.update_info.infile_state);
error = __ns_fget_file_state (outfile,
&message.msg_variants.update_info.outfile_state);
error = __ns_fget_file_state (stdout,
&message.msg_variants.update_info.stdout_state);
/*Check for existence of backup; attempt to recreate if
necessary*/
if (!backup_exists())
initialize_backup();
/*Send update message to backup*/
cond_code = WRITEX (backup_filenum,
(char*) &message,
(short) sizeof message);
/*Check condition code and include check for existence of
backup*/
}
Primary and Backup Processing
At this stage of the example, functions have been written to perform the following
active backup tasks:
Create and start the backup process (function initialize_backup).
Update state information (functions update_backup and backup_exists).
The next step is to restructure the application into separate functions for primary
pr
ocessing and backup processing, and a main function where execution will begin.
The following new functions are created:
Function primary_processing, which does the work of the application and
updates state information in the backup process.
Function backup_processing, which receives state information from the primary
process, checks for failure of the primary process or CPU, and takes over
execution if the primary process or CPU fails.
Function main, which tests whether it is running as the primary process or the
backup process. If it is the primary process, it creates and starts the backup