SNMP Subagent Programmer's Guide
Fault-Tolerant Hello World Program
2-32 119728—SNMP Subagent Programmer’s Guide
Programming Tutorials
    } /* end if */
   } /* end for */
   goto wait;
  } /* end if timeout */
  } /* end if status != CCE */
 /* figure out which mgmt_env is associated with this file number */
 for (i=1; i<argc; i++) {                 <-- 
13
  if (event_fileno == agent_info[i].agent_filenumber) {
   fprintf(stderr, "SNMP buffer from %s\n", argv[i]);
 if (mgmt_poll((struct mgmt_env *) agent_info[i].mgmt_env,    <-- 
14
        (struct timeval *) NULL,
        &count_xferd) < 0)
   { /* some kind of error; mark agent as invalid and keep running */
    agent_info[i].agent_filenumber = -1;
   }
  /*   If the print frequency has been modified output the
  *   helloFreqChange trap.
  */
  if (last_freq != helloPrintFreq)             <-- 
15
   {
    last_freq = helloPrintFreq;
    (void) mgmt_trap(agent_info[i].mgmt_env, &TRAP_helloFreqChange);
   }
  /* print whatever the message currently is,
  *   keeping a count, of course. */
   helloText.val[helloText.len] = '\0';
   (void) fputs((char *) helloText.val, stderr);
   (void) fputs("\n", stderr);
   helloPrintCnt++;
  /* restart the READ */
   if (agent_info[i].agent_filenumber !=
   (event_fileno = mgmt_read_nowait( (struct mgmt_env *)    <-- 
16
       agent_info[i].mgmt_env, NULL)) )
    {
     (void) fprintf(stderr,
    "%s:different file number from restart read; old=%i,new=%i\n",
      argv[0], agent_info[i].agent_filenumber, event_fileno);
    agent_info[i].agent_filenumber = -1; /* forget about this one... */
    } /* end if restart the read */
  } /* end if agent filenumber */
  } /* end for 1 to argc */
 } /* end forever */
} /* end main */
Example 2-4. Fault-Tolerant Hello World Program (page 3 of 3)










