Guardian Programmer's Guide

Table Of Contents
Fault-Tolerant Programming in C
Guardian Programmer’s Guide 421922-014
27 - 42
Updating State Information
error = PROCESS_GETPAIRINFO_ (/*current process*/,
/*pair:maxlen*/,,
/*pairlen*/,
/*primary_phandle*/,
backup_phandle);
return (short) memcmp (backup_phandle, null_phandle,
PHANDLESIZE * 2);
}
Function update_backup
Function update_backup is called by the primary process to update state information
in the backup process. To update the state information, the primary process must send
a message to the backup process that contains the value of the loop counter.
Function update_backup does the following:
Checks for the existence of the backup process. If the backup process does not
exist, an attempt is made to recreate it by calling initialize_backup. The
code to check for the existence of the backup process is written as a separate
function, named backup_exists.
Creates the update message and sends it to the backup process through
interprocess communication (WRITEX).
Function update_backup is as follows:
/*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. Parameter i is the counter
value.*/
void update_backup (short i)
{
_cc_status_short cond_code; /*value not used in this
example*/
message_format message;
/*Check for existence of backup, attempt to recreate
if necessary*/
if (!backup_exists())
initialize_backup();
/*Create the update message*/
message.msgnumber = UPDATE_MESSAGE;
message.msg_variants.counter_value = i;
/*Send the update message to the backup*/
cond_code = WRITEX (backup_filenum,
(char *) &message,
(short) sizeof message);
/*When checking the condition code, include a check for
the existence of the backup process*/
}