Guardian Programmer's Guide

Table Of Contents
Fault-Tolerant Programming in C
Guardian Programmer’s Guide 421922-014
27 - 64
Primary and Backup Processing
Function main
Execution begins with the main function. Function main does the following:
Calls is_backup_process to determine whether it is running as the primary
process or the backup process. Function is_backup_process is described
under Active Backup Example 1.
If it is the backup process, calls backup_processing to perform the backup
activities.
If it is the primary process, does the following:
Opens the input and output files. The __ns_fopen_special function is used
to open the files with a sync depth of 1.
Calls initialize_backup to initialize a backup process. Function
initialize_backup is as described under Active Backup Example 1.
Calls primary_processing to perform the primary process activities.
Function main is as follows:
/*The main function determines whether it is executing as the
primary or backup process and takes appropriate action*/
main (int argc, char *argv[])
{
if (is_backup_process ())
backup_processing();
else
{
/*Verify at least two run-time arguments provided*/
if (argc < 3)
{
(void) printf ("Error: Need to provide input and "
"output file names.\n");
exit(1);
}
/*Open files with sync depth 1*/
infile = __ns_fopen_special (argv[1], "r", 1);
outfile = __ns_fopen_special (argv[2], "ab+", 1);
initialize_backup ();
primary_processing ();
}
}