Initializing and terminating the program

The main function of the sample program uses the three subroutines as shown in the following code segment. The lines 12 through 15 use any command line argument to override the default host name obtained by the uname function. Then lines 17 through 28 initialize the RSI interface using the RSiInitx and RSiOpenx subroutines. The program exits if the initialization fails.
[01] extern char   RSiEMsg[];
[02] extern int   RSiErrno;
[03] char   host[64], apath[256], head1[24][10], head2[24][10];
[04] char   *nptr, **navn = &nptr, *dptr, **desc = &dptr;
[05] struct utsname  uname_struct;
[07]  RsiHandlex rsh;
[08]   struct SpmiStatVals *svp[24];
[09]   int     lct = 99, tix = 0;
[10]   [11] main(int argc, char **argv)
[12]  { 
[13]   uname(&uname_struct);
[14]   strcpy(host, uname_struct.nodename);
[15]     if (argc > 1) 
[16]        strcpy(host, argv[1]); 
[17]     if (!(rsh = RsiInitx(1))) 
[18]     { 
[19]        fprintf(stderr, “Unable to initialize RSI interface\n”); 
[20]        exit(98); 
[21]     } 
[22]     if (RSiOpenx(rsh, 100, 2048, host, feeding, resync, NULL)) 
[23]     { 
[24]        if (strlen(RSiEMsg)) 
[25]           fprintf(stderr, “%s”, RSiEMsg); 
[26]        fprintf(stderr, “Error contacting host\”%s\“\n”, host); 
[27]        exit(-99); 
[28]     } 
[29]     signal(SIGINT, must_exit); 
[30]     signal(SIGTERM, must_exit); 
[31]     signal(SIGSEGV, must_exit); 
[32]     signal(SIGQUIT, must_exit); 
[33] 
[34]     strcpy(apath, “hosts/”); 
[35]     strcat(apath, host); 
[36]     strcat(apath, “/”); 
[37]     lststats(apath); 
[38]     RSiClosex(rsh); 
[39]     exit(0); 
[40] } The following lines (29-32) make sure that the program detects any attempt to kill or terminate it. 
If this happens, the function must_exit is invoked. This function has the sole purpose of making sure the 
association with the xmtopas daemon is terminated. It does this as shown in the following piece of code:  
void must_exit() {    RSiClosex(rsh);    exit(-9); }

Finally, lines 34 through 36 prepare an initial value path name for the main processing loop of the data-consumer program. This is the method followed to create the value path names. Then, the main processing loop in the internal lststats function is called. If this function returns, issue an RSiClosex call and exit the program.