void dispatchLoop(void)
{        
    SaAisErrorT         rc = SA_AIS_OK;
    SaSelectionObjectT amf_dispatch_fd;
    int maxFd;
    fd_set read_fds;

    /*
      * Get the AMF dispatch FD for the callbacks
    */
    if ( (rc = saAmfSelectionObjectGet(amfHandle, &amf_dispatch_fd)) != SA_AIS_OK)
         errorExit(rc);

    maxFd = amf_dispatch_fd;  /* maxFd = max(amf_dispatch_fd,ckpt_dispatch_fd); */
    do
    {
       FD_ZERO(&read_fds);
       FD_SET(amf_dispatch_fd, &read_fds);
         
       if( select(maxFd + 1, &read_fds, NULL, NULL, NULL) < 0)
       {
          char errorStr[80];
          int err = errno;
          if (EINTR == err) continue;

          errorStr[0] = 0; /* just in case strerror does not fill it in */
          strerror_r(err, errorStr, 79);
          //clprintf (CL_LOG_SEV_ERROR, "Error [%d] during dispatch loop select() call: [%s]",err,errorStr);
          break;
       }
       if (FD_ISSET(amf_dispatch_fd,&read_fds)) saAmfDispatch(amfHandle, SA_DISPATCH_ALL);
      
    }while(!unblockNow);      
}
void dispatchLoop(void)
{        
  SaAisErrorT         rc = SA_AIS_OK;
  SaSelectionObjectT amf_dispatch_fd;
  int maxFd;
  fd_set read_fds;

  
  if ( (rc = saAmfSelectionObjectGet(amfHandle, &amf_dispatch_fd)) != SA_AIS_OK)
    errorExit(rc);
    
  maxFd = amf_dispatch_fd;  /* maxFd = max(amf_dispatch_fd,ckpt_dispatch_fd); */
  do
    {
      FD_ZERO(&read_fds);
      FD_SET(amf_dispatch_fd, &read_fds);
      /* FD_SET(ckpt_dispatch_fd, &read_fds); */
        
      if( select(maxFd + 1, &read_fds, NULL, NULL, NULL) < 0)
        {
          char errorStr[80];
          int err = errno;
          if (EINTR == err) continue;

          errorStr[0] = 0; /* just in case strerror does not fill it in */
          strerror_r(err, errorStr, 79);
          break;
        }
      if (FD_ISSET(amf_dispatch_fd,&read_fds)) saAmfDispatch(amfHandle, SA_DISPATCH_ALL);
      /* if (FD_ISSET(ckpt_dispatch_fd,&read_fds)) saCkptDispatch(ckptLibraryHandle, SA_DISPATCH_ALL); */
    }while(!unblockNow);      
}
Пример #3
0
/**
 * Forever wait on events and process them.
 */
static void main_process(void)
{
	NCS_SEL_OBJ mbx_fd;
	SaAisErrorT error = SA_AIS_OK;

	TRACE_ENTER();

	mbx_fd = ncs_ipc_get_sel_obj(&smfnd_cb->mbx);

	/* Set up all file descriptors to listen to */
	if (smfnd_cb->nid_started)
		fds[SMFND_AMF_FD].fd = smfnd_cb->usr1_sel_obj.rmv_obj;
	else
		fds[SMFND_AMF_FD].fd = smfnd_cb->amfSelectionObject;

	fds[SMFND_AMF_FD].events = POLLIN;
	fds[SMFND_MBX_FD].fd = mbx_fd.rmv_obj;
	fds[SMFND_MBX_FD].events = POLLIN;

	while (1) {
		int ret = poll(fds, SMFND_MAX_FD, -1);

		if (ret == -1) {
			if (errno == EINTR)
				continue;

			LOG_ER("poll failed - %s", strerror(errno));
			break;
		}

		/* Process all the AMF messages */
		if (fds[SMFND_AMF_FD].revents & POLLIN) {
			if (smfnd_cb->amf_hdl != 0) {
				/* dispatch all the AMF pending function */
				if ((error = saAmfDispatch(smfnd_cb->amf_hdl, SA_DISPATCH_ALL)) != SA_AIS_OK) {
					LOG_ER("saAmfDispatch failed: %u", error);
					break;
				}
			} else {
				TRACE("SIGUSR1 event rec");

				if (smfnd_amf_init(smfnd_cb) != NCSCC_RC_SUCCESS) {
					LOG_ER("amf init failed");
					break;
				}

				TRACE("AMF Initialization SUCCESS......");
				fds[SMFND_AMF_FD].fd = smfnd_cb->amfSelectionObject;
			}
		}

		/* Process all the Mail box events */
		if (fds[SMFND_MBX_FD].revents & POLLIN) {
			/* dispatch all the MBX events */
			smfnd_process_mbx(&smfnd_cb->mbx);
		}
	}
}
void *th_dispatch (void *arg)
{
	SaErrorT result;
	SaAmfHandleT *handle = (SaAmfHandleT *)arg;

	printf ("THREAD DISPATCH starting.\n");
	result = saAmfDispatch (handle, SA_DISPATCH_BLOCKING);
	printf ("THREAD DISPATCH return result is %d\n", result);
	return (0);
}
void dispatchLoop(void)
{        
  SaAisErrorT         rc = SA_AIS_OK;
  SaSelectionObjectT amf_dispatch_fd;
  int maxFd;
  fd_set read_fds;

  /* This boilerplate code includes an example of how to simultaneously
     dispatch for 2 services (in this case AMF and CKPT).  But since checkpoint
     is not initialized or used, it is commented out */
  /* SaSelectionObjectT ckpt_dispatch_fd; */

  /*
   * Get the AMF dispatch FD for the callbacks
   */
  if ( (rc = saAmfSelectionObjectGet(amfHandle, &amf_dispatch_fd)) != SA_AIS_OK)
    errorExit(rc);
  /* if ( (rc = saCkptSelectionObjectGet(ckptLibraryHandle, &ckpt_dispatch_fd)) != SA_AIS_OK)
       errorExit(rc); */
    
  maxFd = amf_dispatch_fd;  /* maxFd = max(amf_dispatch_fd,ckpt_dispatch_fd); */
  do
    {
      FD_ZERO(&read_fds);
      FD_SET(amf_dispatch_fd, &read_fds);
      /* FD_SET(ckpt_dispatch_fd, &read_fds); */
        
      if( select(maxFd + 1, &read_fds, NULL, NULL, NULL) < 0)
        {
          char errorStr[80];
          int err = errno;
          if (EINTR == err) continue;

          errorStr[0] = 0; /* just in case strerror does not fill it in */
          strerror_r(err, errorStr, 79);
          //clprintf (CL_LOG_SEV_ERROR, "Error [%d] during dispatch loop select() call: [%s]",err,errorStr);
          break;
        }
      if (FD_ISSET(amf_dispatch_fd,&read_fds)) saAmfDispatch(amfHandle, SA_DISPATCH_ALL);
      /* if (FD_ISSET(ckpt_dispatch_fd,&read_fds)) saCkptDispatch(ckptLibraryHandle, SA_DISPATCH_ALL); */
    }while(!unblockNow);      
}
static void* amfDispatcher(void *param)
{
    SaSelectionObjectT dispatch_fd;
    fd_set read_fds;
    ClRcT rc;

    FD_ZERO(&read_fds);

    /*
     * Get the AMF dispatch FD for the callbacks
     */
    if ( (rc = saAmfSelectionObjectGet(amfHandle, &dispatch_fd)) != SA_AIS_OK)
    {
        clprintf (CL_LOG_SEV_ERROR, "Error getting selection object -- unable to dispatch AMF events");
        return NULL;        
    }
    
    
    FD_SET(dispatch_fd, &read_fds);

    /*
     * Block on AMF dispatch file descriptor for callbacks
     */
    do
    {
        if( select(dispatch_fd + 1, &read_fds, NULL, NULL, NULL) < 0)
        {
		    clprintf (CL_LOG_SEV_ERROR, "Error in select() -- unable to dispatch AMF events");
			perror("");
            break;
        }
        saAmfDispatch(amfHandle, SA_DISPATCH_ALL);
    }while(!unblockNow);      

    return NULL;
}
int main (int argc, char **argv) {
	int result;
	SaSelectionObjectT select_fd;
	fd_set read_fds;
	extern char *optarg;
	extern int optind;
	int c;

	memset (&compNameGlobal, 0, sizeof (SaNameT));
	signal (SIGINT, sigintr_handler);
#if ! defined(TS_CLASS) && (defined(OPENAIS_BSD) || defined(OPENAIS_LINUX) || defined(OPENAIS_SOLARIS))
	result = sched_setscheduler (0, SCHED_RR, &sched_param);
	if (result == -1) {
		printf ("couldn't set sched priority\n");
 	}
#endif

	for (;;){
		c = getopt(argc,argv,"h:n:");
		if (c==-1) {
			break;
		}
		switch (c) {
		case 0 :
			break;
		case 'h':
			health_flag = 0;
			sscanf (optarg,"%ud" ,&healthcheck_count);
			break;
		case 'n':
	  		setSanameT (&compNameGlobal, optarg);
			break;
                default :
			break;
                }
	}

	result = saAmfInitialize (&handle, &amfCallbacks, &version);
	if (result != SA_OK) {
		printf ("initialize result is %d\n", result);
		exit (1);
	}

	FD_ZERO (&read_fds);
	saAmfSelectionObjectGet (handle, &select_fd);
	FD_SET (select_fd, &read_fds);
	if (compNameGlobal.length <= 0) {
		setSanameT (&compNameGlobal, "comp_b_in_su_2");
	}

	result = saAmfHealthcheckStart (handle,
		&compNameGlobal,
		&key0,
		SA_AMF_HEALTHCHECK_AMF_INVOKED,
		SA_AMF_COMPONENT_FAILOVER);
	printf ("start %d\n", result);

	result = saAmfHealthcheckStart (handle,
		&compNameGlobal,
		&key0,
		SA_AMF_HEALTHCHECK_AMF_INVOKED,
		SA_AMF_COMPONENT_FAILOVER);
	printf ("start %d\n", result);
	result = saAmfComponentRegister (handle, &compNameGlobal, NULL);
	printf ("register result is %d (should be 1)\n", result);

	do {
		select (select_fd + 1, &read_fds, 0, 0, 0);
		saAmfDispatch (handle, SA_DISPATCH_ALL);
	} while (result && stop == 0);

	sleep (5);
	result = saAmfHealthcheckStart (handle,
		&compNameGlobal,
		&key0,
		SA_AMF_HEALTHCHECK_AMF_INVOKED,
		SA_AMF_COMPONENT_FAILOVER);

	do {
		select (select_fd + 1, &read_fds, 0, 0, 0);
		saAmfDispatch (handle, SA_DISPATCH_ALL);
	} while (result);

	saAmfFinalize (handle);

	exit (0);
}
Пример #8
0
/****************************************************************************
 * Name          : gld_main_process
 *
 * Description   : This is the function which is given as a input to the 
 *                 GLD task.
 *                 This function will be select of both the FD's (AMF FD and
 *                 Mail Box FD), depending on which FD has been selected, it
 *                 will call the corresponding routines.
 *
 * Arguments     : mbx  - This is the mail box pointer on which GLD is 
 *                        going to block.  
 *
 * Return Values : None.
 *
 * Notes         : None.
 *****************************************************************************/
static void gld_main_process(SYSF_MBX *mbx)
{
	NCS_SEL_OBJ mbx_fd;
	SaAisErrorT error = SA_AIS_OK;
	GLSV_GLD_CB *gld_cb = NULL;
	NCS_MBCSV_ARG mbcsv_arg;
	SaSelectionObjectT amf_sel_obj;

	if ((gld_cb = (GLSV_GLD_CB *)ncshm_take_hdl(NCS_SERVICE_ID_GLD, gl_gld_hdl))
	    == NULL) {
		m_LOG_GLD_HEADLINE(GLD_TAKE_HANDLE_FAILED, NCSFL_SEV_ERROR, __FILE__, __LINE__, 0);
		return;
	}
	mbx_fd = ncs_ipc_get_sel_obj(&gld_cb->mbx);
	error = saAmfSelectionObjectGet(gld_cb->amf_hdl, &amf_sel_obj);

	if (error != SA_AIS_OK) {
		m_LOG_GLD_SVC_PRVDR(GLD_AMF_SEL_OBJ_GET_ERROR, NCSFL_SEV_ERROR, __FILE__, __LINE__);
		return;
	}

	/* Set up all file descriptors to listen to */
	fds[FD_AMF].fd = amf_sel_obj;
	fds[FD_AMF].events = POLLIN;
	fds[FD_MBCSV].fd = gld_cb->mbcsv_sel_obj;
	fds[FD_MBCSV].events = POLLIN;
	fds[FD_MBX].fd = mbx_fd.rmv_obj;
	fds[FD_MBX].events = POLLIN;
	fds[FD_IMM].fd = gld_cb->imm_sel_obj;
	fds[FD_IMM].events = POLLIN;

	while (1) {
		if (gld_cb->immOiHandle != 0) {
			fds[FD_IMM].fd = gld_cb->imm_sel_obj;
			fds[FD_IMM].events = POLLIN;
			nfds = FD_IMM + 1;
		} else {
			nfds = FD_IMM;
		}

		int ret = poll(fds, nfds, -1);

		if (ret == -1) {
			if (errno == EINTR)
				continue;

			gld_log(NCSFL_SEV_ERROR, "poll failed - %s", strerror(errno));
			break;
		}

		if (fds[FD_AMF].revents & POLLIN) {
			if (gld_cb->amf_hdl != 0) {
				/* dispatch all the AMF pending function */
				error = saAmfDispatch(gld_cb->amf_hdl, SA_DISPATCH_ALL);
				if (error != SA_AIS_OK) {
					m_LOG_GLD_SVC_PRVDR(GLD_AMF_DISPATCH_ERROR, NCSFL_SEV_ERROR, __FILE__,
							    __LINE__);
				}
			} else
				gld_log(NCSFL_SEV_ERROR, "gld_cb->amf_hdl == 0");
		}

		if (fds[FD_MBCSV].revents & POLLIN) {
			/* dispatch all the MBCSV pending callbacks */
			mbcsv_arg.i_op = NCS_MBCSV_OP_DISPATCH;
			mbcsv_arg.i_mbcsv_hdl = gld_cb->mbcsv_handle;
			mbcsv_arg.info.dispatch.i_disp_flags = SA_DISPATCH_ALL;
			if (ncs_mbcsv_svc(&mbcsv_arg) != SA_AIS_OK) {
				m_LOG_GLD_HEADLINE(GLD_MBCSV_DISPATCH_FAILURE, NCSFL_SEV_ERROR, __FILE__, __LINE__, 0);
			}
		}

		if (fds[FD_MBX].revents & POLLIN)
			gld_process_mbx(mbx);

		/* process the IMM messages */
		if (gld_cb->immOiHandle && fds[FD_IMM].revents & POLLIN) {
			/* dispatch all the IMM pending function */
			error = saImmOiDispatch(gld_cb->immOiHandle, SA_DISPATCH_ONE);

			/*
			 ** BAD_HANDLE is interpreted as an IMM service restart. Try 
			 ** reinitialize the IMM OI API in a background thread and let 
			 ** this thread do business as usual especially handling write 
			 ** requests.
			 **
			 ** All other errors are treated as non-recoverable (fatal) and will
			 ** cause an exit of the process.
			 */
			if (error == SA_AIS_ERR_BAD_HANDLE) {
				gld_log(NCSFL_SEV_ERROR, "saImmOiDispatch returned BAD_HANDLE %u", error);

				/* 
				 ** Invalidate the IMM OI handle, this info is used in other
				 ** locations. E.g. giving TRY_AGAIN responses to a create and
				 ** close resource requests. That is needed since the IMM OI
				 ** is used in context of these functions.
				 */
				gld_cb->immOiHandle = 0;
				gld_imm_reinit_bg(gld_cb);
			} else if (error != SA_AIS_OK) {
				gld_log(NCSFL_SEV_ERROR, "saImmOiDispatch FAILED: %u", error);
				break;
			}
		}

	}
	return;
}
static void *saAmfDispatchThread(void *arg)
{
    saAmfDispatch (amfHandle, SA_DISPATCH_BLOCKING);
    return NULL;
}
Пример #10
0
/**
 * The main routine for the clms daemon.
 * @param argc
 * @param argv
 * 
 * @return int
 */
int main(int argc, char *argv[])
{
	NCS_SEL_OBJ mbx_fd;
	SaAisErrorT error = SA_AIS_OK;
	uint32_t rc;
	osaf_cluster = NULL;
	int term_fd;
	int timeout = -1;

	daemonize(argc, argv);

	if (clms_init() != NCSCC_RC_SUCCESS) {
		LOG_ER("clms_init failed");
		goto done;
	}

	mbx_fd = ncs_ipc_get_sel_obj(&clms_cb->mbx);
	daemon_sigterm_install(&term_fd);

	/* Set up all file descriptors to listen to */
	fds[FD_TERM].fd = term_fd;
	fds[FD_TERM].events = POLLIN;
	fds[FD_AMF].fd = clms_cb->nid_started ?
		usr1_sel_obj.rmv_obj : clms_cb->amf_sel_obj;
	fds[FD_AMF].events = POLLIN;
	fds[FD_MBCSV].fd = clms_cb->mbcsv_sel_obj;
	fds[FD_MBCSV].events = POLLIN;
	fds[FD_MBX].fd = mbx_fd.rmv_obj;
	fds[FD_MBX].events = POLLIN;
	fds[FD_IMM].fd = clms_cb->imm_sel_obj;
	fds[FD_IMM].events = POLLIN;

#ifdef ENABLE_AIS_PLM
	fds[FD_PLM].fd = clms_cb->plm_sel_obj;
	fds[FD_PLM].events = POLLIN;
#endif

	while (1) {

		if (clms_cb->rtu_pending == true) {
			TRACE("There is an IMM task to be tried again. setting poll time out to 500");
			timeout = 500;
		} else {
			timeout = -1;
		}

		if ((clms_cb->immOiHandle != 0) && (clms_cb->is_impl_set == true)) {
			fds[FD_IMM].fd = clms_cb->imm_sel_obj;
			fds[FD_IMM].events = POLLIN;
			nfds = NUM_FD;
		} else {
			nfds = NUM_FD - 1;
		}
		int ret = poll(fds, nfds, timeout);

		if (ret == -1) {
			if (errno == EINTR)
				continue;

			LOG_ER("poll failed - %s", strerror(errno));
			break;
		}

		if (ret == 0) {
			/* Process any/all pending RTAttribute updates to IMM */
			TRACE("poll time out processing pending updates");
			clms_retry_pending_rtupdates();
			continue;
		}
 
		if (fds[FD_TERM].revents & POLLIN) {
			daemon_exit();
		}

		if (fds[FD_AMF].revents & POLLIN) {
			if (clms_cb->amf_hdl != 0) {
				if ((error = saAmfDispatch(clms_cb->amf_hdl, SA_DISPATCH_ALL)) != SA_AIS_OK) {
					LOG_ER("saAmfDispatch failed: %u", error);
					break;
				}
			} else {
				TRACE("SIGUSR1 event rec");
				ncs_sel_obj_rmv_ind(usr1_sel_obj, true, true);
				ncs_sel_obj_destroy(usr1_sel_obj);

				if (clms_amf_init(clms_cb) != NCSCC_RC_SUCCESS) {
					LOG_ER("AMF Initialization failed");
					break;
				}

				TRACE("AMF Initialization SUCCESS......");
				fds[FD_AMF].fd = clms_cb->amf_sel_obj;
			}

		}

		if (fds[FD_MBCSV].revents & POLLIN) {
			if ((rc = clms_mbcsv_dispatch(clms_cb->mbcsv_hdl)) != NCSCC_RC_SUCCESS) {
				LOG_ER("MBCSv Dispatch Failed");
				break;
			}
		}

		if (fds[FD_MBX].revents & POLLIN) {
			clms_process_mbx(&clms_cb->mbx);
		}
#ifdef ENABLE_AIS_PLM
		/*Incase the Immnd restart is not supported fully,have to reint imm - TO Be Done */
		if (clms_cb->reg_with_plm == SA_TRUE){
			if (fds[FD_PLM].revents & POLLIN) {
				if ((error = saPlmDispatch(clms_cb->plm_hdl, SA_DISPATCH_ALL)) != SA_AIS_OK) {
					LOG_ER("saPlmDispatch FAILED: %u", error);
					break;
				}
			}
		}
#endif

		if (clms_cb->immOiHandle && fds[FD_IMM].revents & POLLIN) {
			if ((error = saImmOiDispatch(clms_cb->immOiHandle, SA_DISPATCH_ALL)) != SA_AIS_OK) {
				if (error == SA_AIS_ERR_BAD_HANDLE) {
					TRACE("main :saImmOiDispatch returned BAD_HANDLE");

					/* 
					 * Invalidate the IMM OI handle, this info is used in other
					 * locations. E.g. giving TRY_AGAIN responses to a create and
					 * close app stream requests. That is needed since the IMM OI
					 * is used in context of these functions.
					 * 
					 * Also closing the handle. Finalize is ok with a bad handle
					 * that is bad because it is stale and this actually clears
					 * the handle from internal agent structures.  In any case
					 * we ignore the return value from Finalize here.
					 */
					saImmOiFinalize(clms_cb->immOiHandle);
					clms_cb->immOiHandle = 0;
					clms_cb->is_impl_set = false;

					/* Initiate IMM reinitializtion in the background */
					clm_imm_reinit_bg(clms_cb);


				} else if (error != SA_AIS_OK) {
					LOG_ER("saImmOiDispatch FAILED: %u", error);
					break;
				}
			}
		}
		/* Retry any pending updates */
		if (clms_cb->rtu_pending == true)
			clms_retry_pending_rtupdates();
	} /* End while (1) */

 done:
	LOG_ER("Failed, exiting...");
	TRACE_LEAVE();
	exit(1);
}
Пример #11
0
/****************************************************************************
  Name          : avsv_amf_process

  Description   : This routine is an entry point for the AMF interface task.
		  It demonstrates the use of following AMF APIs
		  a) saAmfInitialize
		  b) saAmfSelectionObjectGet
		  c) saAmfCompNameGet
		  d) saAmfComponentRegister
		  e) saAmfDispatch

  Arguments     : None.

  Return Values : None.

  Notes         : None
******************************************************************************/
void *avsv_amf_process (void* dummy)
{
    SaAmfCallbacksT    reg_callback_set;
    SaVersionT         ver;
    SaAisErrorT        rc;
    SaSelectionObjectT amf_sel_obj;
    struct pollfd fds[1];

    syslog(LOG_INFO, " AMF thread entered");

    /*#########################################################################
    		  Demonstrating the use of saAmfInitialize()
    #########################################################################*/

    /* Fill the callbacks that are to be registered with AMF */
    memset(&reg_callback_set, 0, sizeof(SaAmfCallbacksT));
    reg_callback_set.saAmfCSISetCallback = avsv_amf_csi_set_callback;
    reg_callback_set.saAmfCSIRemoveCallback = avsv_amf_csi_remove_callback;
    reg_callback_set.saAmfHealthcheckCallback = avsv_amf_healthcheck_callback;
    reg_callback_set.saAmfComponentTerminateCallback = avsv_amf_comp_terminate_callback;
    reg_callback_set.saAmfProtectionGroupTrackCallback = avsv_amf_protection_group_callback;

    /* Fill the AMF version */
    m_AMF_VER_GET(ver);

    /* Initialize AMF */
    rc = saAmfInitialize(&gl_amf_hdl, &reg_callback_set, &ver);
    if (SA_AIS_OK != rc) {
        syslog(LOG_ERR, " saAmfInitialize FAILED %u", rc);
        goto done;
    }

    syslog(LOG_INFO, "AMF Initialization Done !!!");
    syslog(LOG_INFO, "\tAmfHandle: %llx ", gl_amf_hdl);

    /*#########################################################################
    	       Demonstrating the use of saAmfSelectionObjectGet()
    #########################################################################*/

    /* Get the selection object corresponding to this AMF handle */
    rc = saAmfSelectionObjectGet(gl_amf_hdl, &amf_sel_obj);
    if (SA_AIS_OK != rc) {
        syslog(LOG_ERR, "saAmfSelectionObjectGet FAILED %u", rc);
        saAmfFinalize(gl_amf_hdl);
        goto done;
    }

    syslog(LOG_INFO, "AMF Selection Object Get Successful !!!");

    /*#########################################################################
    		Demonstrating the use of saAmfCompNameGet()
    #########################################################################*/

    rc = saAmfComponentNameGet(gl_amf_hdl, &gl_comp_name);
    if (SA_AIS_OK != rc) {
        syslog(LOG_ERR, "saAmfComponentNameGet FAILED %u", rc);
        saAmfFinalize(gl_amf_hdl);
        goto done;
    }

    syslog(LOG_INFO, "Component Name Get Successful !!!");
    syslog(LOG_INFO, "\tCompName: %s", gl_comp_name.value);

    /*#########################################################################
    	      Demonstrating the use of saAmfComponentRegister()
    #########################################################################*/

    rc = saAmfComponentRegister(gl_amf_hdl, &gl_comp_name, 0);
    if (SA_AIS_OK != rc) {
        syslog(LOG_ERR, "saAmfComponentRegister FAILED %u", rc);
        saAmfFinalize(gl_amf_hdl);
        goto done;
    }

    syslog(LOG_INFO, "Component Registered !!!");

    fds[0].fd = amf_sel_obj;
    fds[0].events = POLLIN;

    /***** Now wait on the AMF selection object *****/
    while (1) {
        int res = poll(fds, 1, -1);

        if (res == -1) {
            if (errno == EINTR)
                continue;
            else {
                syslog(LOG_ERR, "poll FAILED - %s", strerror(errno));
                exit(1);
            }
        }

        /*######################################################################
        		Demonstrating the use of saAmfDispatch()
        ######################################################################*/

        if (fds[0].revents & POLLIN) {
            /* There is an AMF callback waiting to be be processed. Process it */
            rc = saAmfDispatch(gl_amf_hdl, SA_DISPATCH_ONE);
            if (SA_AIS_OK != rc) {
                syslog(LOG_ERR, "saAmfDispatch FAILED %u", rc);
                saAmfComponentUnregister(gl_amf_hdl, &gl_comp_name, 0);
                saAmfFinalize(gl_amf_hdl);
                break;
            }
        }
    }

    syslog(LOG_INFO, "DEMO OVER !!!");
done:
    return NULL;
}
Пример #12
0
/****************************************************************************
 * Name          : eds_main_process
 *
 * Description   : This is the function which is given as a input to the 
 *                 EDS task.
 *                 This function will be select of both the FD's (AMF FD and
 *                 Mail Box FD), depending on which FD has been selected, it
 *                 will call the corresponding routines.
 *
 * Arguments     : mbx  - This is the mail box pointer on which EDS is 
 *                        going to block.  
 *
 * Return Values : None.
 *
 * Notes         : None.
 *****************************************************************************/
void eds_main_process(SYSF_MBX *mbx)
{

	NCS_SEL_OBJ mbx_fd;
	SaAisErrorT error = SA_AIS_OK;
	EDS_CB *eds_cb = NULL;
	int term_fd;
	TRACE_ENTER();

	if (NULL == (eds_cb = (EDS_CB *)ncshm_take_hdl(NCS_SERVICE_ID_EDS, gl_eds_hdl))) {
		LOG_ER("Global take handle failed");
		return;
	}

	mbx_fd = m_NCS_IPC_GET_SEL_OBJ(&eds_cb->mbx);

	/* Give back the handle */
	ncshm_give_hdl(gl_eds_hdl);

	/* Initialize with IMM */
	if (eds_imm_init(eds_cb) != SA_AIS_OK) {
		LOG_ER("Imm Init Failed. Exiting");
		exit(EXIT_FAILURE);
	}

	daemon_sigterm_install(&term_fd);

	/* Set up all file descriptors to listen to */
	fds[FD_TERM].fd = term_fd;
	fds[FD_TERM].events = POLLIN;
	fds[FD_AMF].fd = eds_cb->amfSelectionObject;
	fds[FD_AMF].events = POLLIN;
	fds[FD_CLM].fd = eds_cb->clm_sel_obj;
	fds[FD_CLM].events = POLLIN;
	fds[FD_MBCSV].fd = eds_cb->mbcsv_sel_obj;
	fds[FD_MBCSV].events = POLLIN;
	fds[FD_MBX].fd = mbx_fd.rmv_obj;
	fds[FD_MBX].events = POLLIN;
	fds[FD_IMM].fd = eds_cb->imm_sel_obj;
	fds[FD_IMM].events = POLLIN;

	TRACE("Entering the forever loop");

	while (1) {

		if ((eds_cb->immOiHandle != 0) && (eds_cb->is_impl_set == true)){
			fds[FD_IMM].fd = eds_cb->imm_sel_obj;
			fds[FD_IMM].events = POLLIN;
			nfds = NUM_FD;
		} else {
			nfds = NUM_FD - 1;
		}
		
		int ret = poll(fds, nfds, -1);

		if (ret == -1) {
			if (errno == EINTR)
				continue;

			TRACE("poll failed - %s", strerror(errno));
			break;
		}

		/* process the sigterm */
		if (fds[FD_TERM].revents & POLLIN) {
			daemon_exit();
		}

		/* process all the AMF messages */
		if (fds[FD_AMF].revents & POLLIN) {
			/* dispatch all the AMF pending callbacks */
			error = saAmfDispatch(eds_cb->amf_hdl, SA_DISPATCH_ALL);
			if (error != SA_AIS_OK)
				LOG_ER("AMF Dispatch failed with rc = %d",error);
		}

		/* process all mbcsv messages */
		if (fds[FD_MBCSV].revents & POLLIN) {
			error = eds_mbcsv_dispatch(eds_cb->mbcsv_hdl);
			if (NCSCC_RC_SUCCESS != error)
				LOG_ER("MBCSv Dispatch failed with rc = %d",error);
		}

		/* Process the EDS Mail box, if eds is ACTIVE. */
		if (fds[FD_MBX].revents & POLLIN) {
			/* now got the IPC mail box event */
			eds_process_mbx(mbx);
		}

		/* process the CLM messages */
		if (fds[FD_CLM].revents & POLLIN) {
			/* dispatch all the AMF pending callbacks */
			error = saClmDispatch(eds_cb->clm_hdl, SA_DISPATCH_ALL);
			if (error != SA_AIS_OK)
				LOG_ER("CLM Dispatch failed with rc = %d",error);
		}

		/* process the IMM messages */
		if (eds_cb->immOiHandle && fds[FD_IMM].revents & POLLIN) {

			/* dispatch the IMM event */
			error = saImmOiDispatch(eds_cb->immOiHandle, SA_DISPATCH_ONE);

			/*
			 ** BAD_HANDLE is interpreted as an IMM service restart. Try 
			 ** reinitialize the IMM OI API in a background thread and let 
			 ** this thread do business as usual especially handling write 
			 ** requests.
			 **
			 ** All other errors are treated as non-recoverable (fatal) and will
			 ** cause an exit of the process.
			 */

			if (error == SA_AIS_ERR_BAD_HANDLE) {
				TRACE("saImmOiDispatch returned BAD_HANDLE");

				/* Invalidate the IMM OI handle. */
				saImmOiFinalize(eds_cb->immOiHandle);
				eds_cb->immOiHandle = 0;
				eds_cb->is_impl_set = false;
				eds_imm_reinit_bg(eds_cb);
				
			} else if (error != SA_AIS_OK) {
				LOG_ER("saImmOiDispatch FAILED with rc = %d", error);
				break;
			}

		}
	}

	TRACE_LEAVE();
	return;
}	/* End eds_main_process() */
Пример #13
0
/****************************************************************************
  Name          : pxy_pxd_amf_process
 
  Description   : This routine is an entry point for the AMF interface task.
                  It demonstrates the use of following AMF APIs
                  a) saAmfInitialize
                  b) saAmfSelectionObjectGet
                  c) saAmfCompNameGet
                  d) saAmfComponentRegister
                  e) saAmfDispatch
 
  Arguments     : None.
 
  Return Values : None.
 
  Notes         : None
******************************************************************************/
void pxy_pxd_amf_process (void)
{
   SaAisErrorT        rc;
   NCS_SEL_OBJ_SET    wait_sel_objs, all_sel_objs;
   SaSelectionObjectT pxy_amf_sel_obj,pxd_amf_sel_obj[PXY_PXD_NUM_OF_PROXIED_COMP];
   NCS_SEL_OBJ        pxy_amf_ncs_sel_obj,pxd_amf_ncs_sel_obj[PXY_PXD_NUM_OF_PROXIED_COMP];
   NCS_SEL_OBJ        highest_sel_obj,wait_sel_fd;
   int ret = 0;
   uns32 comp_inv_hc_time_out = 500;
   uns32 index = 0;

   /* this is to allow to establish MDS session with AvSv */
   m_NCS_TASK_SLEEP(3000);

   pxy_pxd_proxy_initialize();   

   rc = pxy_pxd_proxy_amf_init();

   if (SA_AIS_OK != rc)
      return;
   for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
     rc = pxy_pxd_proxied_amf_init(index);

   if (SA_AIS_OK != rc)
      return;

   /* Get the selection object corresponding to this AMF handle */
   rc = saAmfSelectionObjectGet(pxy_pxd_cb.pxy_info.amfHandle, &pxy_amf_sel_obj);
   if (SA_AIS_OK != rc)
   {
      saAmfFinalize(pxy_pxd_cb.pxy_info.amfHandle);
      return;
   }
   
   for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
   {
     /* Get the selection object corresponding to this AMF handle */
     rc = saAmfSelectionObjectGet(pxy_pxd_cb.pxd_info[index].amfHandle, 
                                  &pxd_amf_sel_obj[index]);
     if (SA_AIS_OK != rc)
     {
       saAmfFinalize(pxy_pxd_cb.pxy_info.amfHandle);
       printf("\n AMF Selection Object Get Failed for index %d !!!\n",index);
       return;
     }
   }

   printf("\n AMF Selection Object Get Successful !!! \n");

   rc = saAmfComponentNameGet(pxy_pxd_cb.pxy_info.amfHandle, 
                                 &pxy_pxd_cb.pxy_info.compName);
   if (SA_AIS_OK != rc)
   {
      saAmfFinalize(pxy_pxd_cb.pxy_info.amfHandle);
      return;
   }

   printf("\n Component Name Get Successful !!! \n CompName: %s \n",
                      pxy_pxd_cb.pxy_info.compName.value);


   rc = saAmfComponentRegister(pxy_pxd_cb.pxy_info.amfHandle, 
                               &pxy_pxd_cb.pxy_info.compName, 0);
   if (SA_AIS_OK != rc)
   {
      saAmfFinalize(pxy_pxd_cb.pxy_info.amfHandle);
      return;
   }

   printf("\n Proxy Component Registered !!! \n");

   /* Reset the wait select objects */
   m_NCS_SEL_OBJ_ZERO(&all_sel_objs);

   m_SET_FD_IN_SEL_OBJ((uns32)pxy_amf_sel_obj, pxy_amf_ncs_sel_obj);
   m_NCS_SEL_OBJ_SET(pxy_amf_ncs_sel_obj, &all_sel_objs);
   highest_sel_obj = pxy_amf_ncs_sel_obj;

   for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
   {
    m_SET_FD_IN_SEL_OBJ((uns32)pxd_amf_sel_obj[index], pxd_amf_ncs_sel_obj[index]);
    m_NCS_SEL_OBJ_SET(pxd_amf_ncs_sel_obj[index], &all_sel_objs);
    highest_sel_obj = m_GET_HIGHER_SEL_OBJ(highest_sel_obj, pxd_amf_ncs_sel_obj[index]);
   }

   wait_sel_objs = all_sel_objs;
   wait_sel_fd  = highest_sel_obj;

   /* Now wait forever */
   while ((ret = m_NCS_SEL_OBJ_SELECT(wait_sel_fd, &wait_sel_objs, NULL, NULL,
           &comp_inv_hc_time_out)) != -1)
   {
    comp_inv_hc_time_out = 500;
    /* Check if it's an event from AMF */
    if(m_NCS_SEL_OBJ_ISSET(pxy_amf_ncs_sel_obj, &wait_sel_objs))
    {
      printf("\n Got Proxy AMF event!!! \n");
      /* There is an AMF callback waiting to be be processed. Process it */
      rc = saAmfDispatch(pxy_pxd_cb.pxy_info.amfHandle, SA_DISPATCH_ALL);
      if (SA_AIS_OK != rc)
      {
         printf("\n Proxy saAmfDispatch failed !!! \n");
         break;
      }
    }
   for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
   {
    if(TRUE == pxy_pxd_cb.pxd_info[index].reg_pxied_comp)
    {
      printf("\n Before registering pxd[%d]!!!\n",index);
      /* Need to register proxied component */
      rc = saAmfComponentRegister(pxy_pxd_cb.pxd_info[index].amfHandle,
                                   &pxy_pxd_cb.pxd_info[index].compName,
                                   &pxy_pxd_cb.pxy_info.compName);
      if (SA_AIS_OK == rc)
      {
        printf("\n Proxied[%d] Component Registeration Successful. "
                              "Comp %s. rc is %d\n",index,
                              pxy_pxd_cb.pxd_info[index].compName.value,rc);
        pxy_pxd_cb.pxd_info[index].health_start = TRUE;
        pxy_pxd_cb.pxd_info[index].reg_pxied_comp = FALSE;
      }
      else if (SA_AIS_ERR_TRY_AGAIN == rc)
      {
        printf("\n Proxied[%d] Component Registeration failed. TRY_AGAIN"
                              " Comp %s. rc is %d\n",index,
                              pxy_pxd_cb.pxd_info[index].compName.value,rc);
      }
      else
      {
        printf("\n Proxied[%d] Component Registeration failed."
                              " Comp %s. rc is %d\n",index,
                              pxy_pxd_cb.pxd_info[index].compName.value,rc);
        pxy_pxd_cb.pxd_info[index].reg_pxied_comp = FALSE;
      }
     }
    } /* if(TRUE == pxy_pxd_cb.reg_pxied_comp) */

   /* Section 1 Starts : Health Check : SA_AMF_HEALTHCHECK_AMF_INVOKED */
   {
    SaAmfHealthcheckInvocationT    hc_inv;
    SaAmfRecommendedRecoveryT      rec_rcvr;

     for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
     {
       if(TRUE == pxy_pxd_cb.pxd_info[index].health_start)
       { 
        printf("\n Before registering hc [%d]!!!\n",index);
        hc_inv = SA_AMF_HEALTHCHECK_AMF_INVOKED;
        rec_rcvr = SA_AMF_COMPONENT_FAILOVER;

        rc = saAmfHealthcheckStart(pxy_pxd_cb.pxd_info[index].amfHandle, 
                                   &pxy_pxd_cb.pxd_info[index].compName, 
                                   &pxy_pxd_cb.pxd_info[index].healthcheck_key,
                                   hc_inv, rec_rcvr);
        if (SA_AIS_OK == rc )
        {
          printf("Started AMF-Initiated HealthCheck (with Component "
                          "Failover Recommended Recovery) \n Comp: %s \n" 
                          "HealthCheckKey: %s \n",
                          pxy_pxd_cb.pxd_info[index].compName.value, 
                          pxy_pxd_cb.pxd_info[index].healthcheck_key.key);
          pxy_pxd_cb.pxd_info[index].health_start = FALSE;   
          pxy_pxd_cb.pxd_info[index].health_start_comp_inv = TRUE;   
        }
        else if(SA_AIS_ERR_TRY_AGAIN == rc)
        {
          printf(" AMF-Initiated HealthCheck TRY_AGAIN (with Component"
                            " Failover Recommended Recovery) \n Comp: %s \n" 
                            "HealthCheckKey: %s. Res %d \n",
                            pxy_pxd_cb.pxd_info[index].compName.value, 
                            pxy_pxd_cb.pxd_info[index].healthcheck_key.key, rc);
        }
        else
        {
          printf(" AMF-Initiated HealthCheck failed (with Component "
                            "Failover Recommended Recovery) \n Comp: %s \n" 
                            "HealthCheckKey: %s. Res %d \n",
                            pxy_pxd_cb.pxd_info[index].compName.value, 
                            pxy_pxd_cb.pxd_info[index].healthcheck_key.key, rc);
          pxy_pxd_cb.pxd_info[index].health_start = FALSE;   
        }
       } /* if(TRUE == pxy_pxd_cb.pxd_info[index].health_start)*/ 
     }
   }
   /* Section 1 Ends : Health Check : SA_AMF_HEALTHCHECK_AMF_INVOKED */

  if(TRUE == pxy_pxd_cb.unreg_pxied_comp)
  {
   for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
   {
      printf("\n Before unregistering PXD[%d]!!! \n",index);
      /* Need to unregister proxied component */
       rc = saAmfComponentUnregister(pxy_pxd_cb.pxd_info[index].amfHandle,
                                     &pxy_pxd_cb.pxd_info[index].compName,
                                     &pxy_pxd_cb.pxy_info.compName);
       if (SA_AIS_OK != rc)
       {
          printf("\n Proxied Component unreg failed. Comp %s, Pxy Comp %s, Res %d\n",
                                pxy_pxd_cb.pxd_info[index].compName.value,
                                pxy_pxd_cb.pxy_info.compName.value,rc);
       }
       else
          printf("\n Proxied Component unreg Succ. Comp %s, Pxy Comp %s\n",
                                pxy_pxd_cb.pxd_info[index].compName.value,
                                pxy_pxd_cb.pxy_info.compName.value);
       pxy_pxd_cb.unreg_pxied_comp = FALSE;
       pxy_pxd_cb.pxd_info[index].health_start_comp_inv = FALSE;
   }
  }

   for(index = 0; index < PXY_PXD_NUM_OF_PROXIED_COMP; index++)
   {
    /* Check if it's an event from AMF */
    if(m_NCS_SEL_OBJ_ISSET(pxd_amf_ncs_sel_obj[index], &wait_sel_objs))
    {
      printf("\n Before Pxd dispatch PXD[%d] !!!\n",index);
      /* There is an AMF callback waiting to be be processed. Process it */
      rc = saAmfDispatch(pxy_pxd_cb.pxd_info[index].amfHandle, SA_DISPATCH_ONE);
      if (SA_AIS_OK != rc)
      {
         printf("\n PXD[%d] saAmfDispatch failed !!! \n",index);
         break;
      }
    }
   }
      /* Again set AMF select object to wait for another callback */
      wait_sel_objs = all_sel_objs;
      wait_sel_fd  = highest_sel_obj;
   }/* While loop */

   printf("\n\n Proxy Exited, ret %d!!!\n\n",ret);

   return;
}
Пример #14
0
int main(int argc, char *argv[])
{
	uint32_t rc;
	nfds_t nfds = 4;
	struct pollfd fds[nfds + RDA_MAX_CLIENTS];
	int i, ret;
	NCS_SEL_OBJ mbx_sel_obj;
	RDE_RDA_CB *rde_rda_cb = &rde_cb->rde_rda_cb;
	int term_fd;

	daemonize(argc, argv);

	if (initialize_rde() != NCSCC_RC_SUCCESS)
		goto init_failed;

	mbx_sel_obj = ncs_ipc_get_sel_obj(&rde_cb->mbx);

	if ((rc = discover_peer(mbx_sel_obj.rmv_obj)) == NCSCC_RC_FAILURE)
		goto init_failed;

	if ((rc = determine_role(mbx_sel_obj.rmv_obj)) == NCSCC_RC_FAILURE)
		goto init_failed;

	/* If AMF started register immediately */
	if (!rde_cb->rde_amf_cb.nid_started &&
		(rc = rde_amf_init(&rde_cb->rde_amf_cb)) != NCSCC_RC_SUCCESS) {
		goto init_failed;
	}

	if (rde_cb->rde_amf_cb.nid_started &&
		nid_notify("RDE", rc, NULL) != NCSCC_RC_SUCCESS) {
		LOG_ER("nid_notify failed");
		goto done;
	}

	daemon_sigterm_install(&term_fd);

	fds[FD_TERM].fd = term_fd;
	fds[FD_TERM].events = POLLIN;

	/* USR1/AMF fd */
	fds[FD_AMF].fd = rde_cb->rde_amf_cb.nid_started ?
		usr1_sel_obj.rmv_obj : rde_cb->rde_amf_cb.amf_fd;
	fds[FD_AMF].events = POLLIN;

	/* Mailbox */
	fds[FD_MBX].fd = mbx_sel_obj.rmv_obj;
	fds[FD_MBX].events = POLLIN;

	/* RDA server socket */
	fds[FD_RDA_SERVER].fd = rde_cb->rde_rda_cb.fd;
	fds[FD_RDA_SERVER].events = POLLIN;

	while (1) {
		ret = poll(fds, nfds, -1);

		if (ret == -1) {
			if (errno == EINTR)
				continue;
			
			LOG_ER("poll failed - %s", strerror(errno));
			break;
		}

		if (fds[FD_TERM].revents & POLLIN) {
			daemon_exit();
		}

		if (fds[FD_AMF].revents & POLLIN) {
			if (rde_cb->rde_amf_cb.amf_hdl != 0) {
				SaAisErrorT error;
				TRACE("AMF event rec");
				if ((error = saAmfDispatch(rde_cb->rde_amf_cb.amf_hdl, SA_DISPATCH_ALL)) != SA_AIS_OK) {
					LOG_ER("saAmfDispatch failed: %u", error);
					goto done;
				}
			} else {
				TRACE("SIGUSR1 event rec");
				ncs_sel_obj_destroy(&usr1_sel_obj);
				
				if (rde_amf_init(&rde_cb->rde_amf_cb) != NCSCC_RC_SUCCESS)
					goto done;
				
				fds[FD_AMF].fd = rde_cb->rde_amf_cb.amf_fd;
			}
		}

		if (fds[FD_MBX].revents & POLLIN)
			handle_mbx_event();

		if (fds[FD_RDA_SERVER].revents & POLLIN) {
			int newsockfd;

			newsockfd = accept(rde_rda_cb->fd, (struct sockaddr *)NULL, NULL);
			if (newsockfd < 0) {
				LOG_ER("accept FAILED %s", strerror(errno));
				goto done;
			}

			/* Add the new client fd to client-list	*/
			rde_rda_cb->clients[rde_rda_cb->client_count].is_async = false;
			rde_rda_cb->clients[rde_rda_cb->client_count].fd = newsockfd;
			rde_rda_cb->client_count++;

			/* Update poll fd selection */
			fds[nfds].fd = newsockfd;
			fds[nfds].events = POLLIN;
			nfds++;

			TRACE("accepted new client, fd=%d, idx=%d, nfds=%lu", newsockfd, rde_rda_cb->client_count, nfds);
		}

		for (i = FD_CLIENT_START; i < nfds; i++) {
			if (fds[i].revents & POLLIN) {
				int client_disconnected = 0;
				TRACE("received msg on fd %u", fds[i].fd);
				rde_rda_client_process_msg(rde_rda_cb, fd_to_client_ixd(fds[i].fd), &client_disconnected);
				if (client_disconnected) {
					/* reinitialize the fd array & nfds */
					nfds = FD_CLIENT_START;
					for (i = 0; i < rde_rda_cb->client_count; i++, nfds++) {
						fds[i + FD_CLIENT_START].fd = rde_rda_cb->clients[i].fd;
						fds[i + FD_CLIENT_START].events = POLLIN;
					}
					TRACE("client disconnected, fd array reinitialized, nfds=%lu", nfds);
					break;
				}
			}
		}
	}

 init_failed:
	if (rde_cb->rde_amf_cb.nid_started &&
		nid_notify("RDE", NCSCC_RC_FAILURE, NULL) != NCSCC_RC_SUCCESS) {
		LOG_ER("nid_notify failed");
		rc = NCSCC_RC_FAILURE;
	}

 done:
	syslog(LOG_ERR, "Exiting...");
	exit(1);
}
int main(int argc, char *argv[])
{
    SaNameT             appName = {0};
    SaAmfCallbacksT     callbacks;
    SaVersionT          version;
    ClIocPortT          iocPort;
    SaAisErrorT         rc = SA_AIS_OK;

    SaSelectionObjectT dispatch_fd = 0;
    fd_set read_fds;
    
    /*
     * Declare other local variables here.
     */

    /*
     * Get the pid for the process and store it in global variable.
     */

    mypid = getpid();

    /*
     * Initialize and register with CPM. 'version' specifies the
     * version of AMF with which this application would like to
     * interface. 'callbacks' is used to register the callbacks this
     * component expects to receive.
     */

    version.releaseCode  = 'B';
    version.majorVersion = 01;
    version.minorVersion = 01;
    
    callbacks.saAmfHealthcheckCallback          = NULL;
    callbacks.saAmfComponentTerminateCallback   = clCompAppTerminate;
    callbacks.saAmfCSISetCallback               = clCompAppAMFCSISet;
    callbacks.saAmfCSIRemoveCallback            = clCompAppAMFCSIRemove;
    callbacks.saAmfProtectionGroupTrackCallback = NULL;
        
    /*
     * Initialize AMF client library.
     */

    if ( (rc = saAmfInitialize(&amfHandle, &callbacks, &version)) != SA_AIS_OK) 
        goto errorexit;


    /*
     * Do the application specific initialization here.
     */
    
    /*
     * Now register the component with AMF. At this point it is
     * ready to provide service, i.e. take work assignments.
     */

    if ( (rc = saAmfComponentNameGet(amfHandle, &appName)) != SA_AIS_OK) 
        goto errorexit;
    if ( (rc = saAmfComponentRegister(amfHandle, &appName, NULL)) != SA_AIS_OK) 
        goto errorexit;

    /*
     * Initialize the log stream
     */
    clEvalAppLogStreamOpen((ClCharT*)appName.value, &gEvalLogStream);

    /*
     * Print out standard information for this component.
     */

    clEoMyEoIocPortGet(&iocPort);
    
    clprintf (CL_LOG_SEV_INFO, "Component [%.*s] : PID [%d]. Initializing\n", appName.length, appName.value, mypid);
    clprintf (CL_LOG_SEV_INFO, "   IOC Address             : 0x%x\n", clIocLocalAddressGet());
    clprintf (CL_LOG_SEV_INFO, "   IOC Port                : 0x%x\n", iocPort);


    /*
     * Block on AMF dispatch file descriptor for callbacks
     */
    do
    {
        struct timeval timeout;
        timeout.tv_sec = 2; timeout.tv_usec = 0;

        FD_ZERO(&read_fds);
        FD_SET(dispatch_fd, &read_fds);

        if( select(dispatch_fd + 1, &read_fds, NULL, NULL, &timeout) < 0)
        {
            if (EINTR == errno)
            {
                continue;
            }
		    clprintf (CL_LOG_SEV_ERROR, "Error in select()");
			perror("");
            break;
        }
        if (FD_ISSET(dispatch_fd,&read_fds)) saAmfDispatch(amfHandle, SA_DISPATCH_ALL);
        
        if (running) clprintf(CL_LOG_SEV_INFO,"csa102: Unthreaded Hello World! %s", show_progress());
        else clprintf(CL_LOG_SEV_INFO,"csa102: idle");        
    }while(!unblockNow);      

    /*
     * Do the application specific finalization here.
     */


    if((rc = saAmfFinalize(amfHandle)) != SA_AIS_OK)
	{
        clprintf (CL_LOG_SEV_ERROR, "AMF finalization error[0x%X]", rc);
	}

    clprintf (CL_LOG_SEV_INFO, "AMF Finalized");
    
    return 0;

errorexit:

    clprintf (CL_LOG_SEV_ERROR, "Component [%.*s] : PID [%d]. Initialization error [0x%x]\n",
              appName.length, appName.value, mypid, rc);

    return -1;
}
Пример #16
0
static SaAisErrorT amf_initialize(SaSelectionObjectT *amf_sel_obj)
{
	SaAisErrorT rc;
	SaAmfCallbacksT amf_callbacks = {0};
	SaVersionT api_ver =
		{.releaseCode = 'B', api_ver.majorVersion = 0x01, api_ver.minorVersion = 0x01};

	amf_callbacks.saAmfCSISetCallback = csi_set_callback;
	amf_callbacks.saAmfCSIRemoveCallback = csi_remove_callback;
	amf_callbacks.saAmfHealthcheckCallback = healthcheck_callback;
	amf_callbacks.saAmfComponentTerminateCallback = terminate_callback;

	rc = saAmfInitialize(&my_amf_hdl, &amf_callbacks, &api_ver);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, " saAmfInitialize FAILED (%u)", rc);
		goto done;
	}

	rc = saAmfSelectionObjectGet(my_amf_hdl, amf_sel_obj);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, "saAmfSelectionObjectGet FAILED (%u)", rc);
		goto done;
	}

	rc = saAmfComponentNameGet(my_amf_hdl, &my_comp_name);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, "saAmfComponentNameGet FAILED (%u)", rc);
		goto done;
	}

	rc = saAmfComponentRegister(my_amf_hdl, &my_comp_name, 0);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, "saAmfComponentRegister FAILED (%u)", rc);
		goto done;
	}
	
done:
	return rc;
}

int main(int argc, char **argv)
{
	SaAisErrorT rc;
	SaSelectionObjectT amf_sel_obj;
	struct pollfd fds[1];
	int logmask;

	if (daemon(0, 0) == -1) {
		syslog(LOG_ERR, "daemon failed: %s", strerror(errno));
		goto done;
	}

	create_pid_file();

	/* Cancel certain signals that would kill us */
	signal(SIGTERM, SIG_IGN);
	signal(SIGHUP, SIG_IGN);
	signal(SIGUSR1, SIG_IGN);
	signal(SIGUSR2, SIG_IGN);

	openlog(basename(argv[0]), LOG_PID, LOG_USER);

	// TBD: Configure logmask from args/vars
	logmask = LOG_UPTO(LOG_INFO);
//	setlogmask(logmask);

	start_script = getenv("STARTSCRIPT");
	if (start_script == NULL) {
		syslog(LOG_ERR, "Variable STARTCRIPT missing");
		goto done;
	}

	stop_script = getenv("STOPSCRIPT");
	if (stop_script == NULL) {
		syslog(LOG_ERR, "Variable STOPSCRIPT missing");
		goto done;
	}

	health_script = getenv("HEALTHCHECKSCRIPT");
	if (health_script == NULL) {
		syslog(LOG_ERR, "Variable HEALTHCHECKSCRIPT missing");
		goto done;
	}

	pidfile = getenv("PIDFILE");

	if (amf_initialize(&amf_sel_obj) != SA_AIS_OK)
		goto done;


	fds[0].fd = amf_sel_obj;
	fds[0].events = POLLIN;

	syslog(LOG_INFO, "'%s' started", getenv("SA_AMF_COMPONENT_NAME"));

	while (1) {
		int res = poll(fds, 1, -1);

		if (res == -1) {
			if (errno == EINTR)
				continue;
			else {
				syslog(LOG_ERR, "poll FAILED - %s", strerror(errno));
				goto done;
			}
		}

		if (fds[0].revents & POLLIN) {
			rc = saAmfDispatch(my_amf_hdl, SA_DISPATCH_ONE);
			if (rc != SA_AIS_OK) {
				syslog(LOG_ERR, "saAmfDispatch FAILED %u", rc);
				goto done;
			}
		}
	}

done:
	return EXIT_FAILURE;
}
Пример #17
0
/**
 * The main routine for the IMM director daemon.
 * @param argc
 * @param argv
 * 
 * @return int
 */
int main(int argc, char *argv[])
{
	SaAisErrorT error;
	NCS_SEL_OBJ mbx_fd;
	struct pollfd fds[3];

	daemonize(argc, argv);

	if (immd_initialize() != NCSCC_RC_SUCCESS) {
		TRACE("initialize_immd failed");
		goto done;
	}

	/* Get file descriptor for mailbox */
	mbx_fd = ncs_ipc_get_sel_obj(&immd_cb->mbx);

	/* Set up all file descriptors to listen to */
	fds[FD_USR1].fd = immd_cb->usr1_sel_obj.rmv_obj;
	fds[FD_USR1].events = POLLIN;
	fds[FD_MBCSV].fd = immd_cb->mbcsv_sel_obj;
	fds[FD_MBCSV].events = POLLIN;
	fds[FD_MBX].fd = mbx_fd.rmv_obj;
	fds[FD_MBX].events = POLLIN;

	while (1) {
		int ret = poll(fds, 3, -1);

		if (ret == -1) {
			if (errno == EINTR)
				continue;

			LOG_ER("poll failed - %s", strerror(errno));
			break;
		}

		if (fds[FD_MBCSV].revents & POLLIN) {
			if (immd_mbcsv_dispatch(immd_cb) != NCSCC_RC_SUCCESS) {
				LOG_ER("MBCSv Dispatch Failed");
				break;
			}
		}

		if (fds[FD_MBX].revents & POLLIN)
			immd_process_evt();

		if (fds[FD_AMF].revents & POLLIN) {
			if (immd_cb->amf_hdl != 0) {
				error = saAmfDispatch(immd_cb->amf_hdl, SA_DISPATCH_ALL);
				if (error != SA_AIS_OK) {
					LOG_ER("saAmfDispatch failed: %u", error);
					break;
				}
			} else {
				TRACE("SIGUSR1 event rec");
				ncs_sel_obj_rmv_ind(immd_cb->usr1_sel_obj, TRUE, TRUE);
				ncs_sel_obj_destroy(immd_cb->usr1_sel_obj);

				if (immd_amf_init(immd_cb) != NCSCC_RC_SUCCESS)
					break;

				TRACE("AMF Initialization SUCCESS......");
				fds[FD_AMF].fd = immd_cb->amf_sel_obj;
			}
		}
	}

done:
	LOG_ER("Failed, exiting...");
	TRACE_LEAVE();
	exit(1);
}
Пример #18
0
/****************************************************************************
 * Name          : glnd_main_process
 *
 * Description   : This is the function which is given as a input to the 
 *                 GLND task.
 *
 * Arguments     : mbx  - This is the mail box pointer on which GLND is 
 *                        going to block.  
 *
 * Return Values : None.
 *
 * Notes         : None.
 *****************************************************************************/
void glnd_main_process(SYSF_MBX *mbx)
{
	NCS_SEL_OBJ mbx_fd = m_NCS_IPC_GET_SEL_OBJ(mbx);
	GLND_CB *glnd_cb = NULL;
	TRACE_ENTER();	
	
	SaAmfHandleT amf_hdl;

	SaSelectionObjectT amf_sel_obj;
	SaAisErrorT amf_error;

	struct pollfd sel[NUM_FD];
	int term_fd;

	/* take the handle */
	glnd_cb = (GLND_CB *)m_GLND_TAKE_GLND_CB;
	if (!glnd_cb) {
		LOG_ER("GLND cb take handle failed");
		goto end;
	}

	amf_hdl = glnd_cb->amf_hdl;

	/*giveup the handle */
	m_GLND_GIVEUP_GLND_CB;

	amf_error = saAmfSelectionObjectGet(amf_hdl, &amf_sel_obj);
	if (amf_error != SA_AIS_OK) {
		LOG_ER("GLND amf get sel obj error");
		goto end;
	}

	daemon_sigterm_install(&term_fd);

	sel[FD_TERM].fd = term_fd;
	sel[FD_TERM].events = POLLIN;
	sel[FD_AMF].fd = amf_sel_obj;
	sel[FD_AMF].events = POLLIN;
	sel[FD_MBX].fd = m_GET_FD_FROM_SEL_OBJ(mbx_fd);
	sel[FD_MBX].events = POLLIN;

	while (osaf_poll(&sel[0], NUM_FD, -1) > 0) {

		if (sel[FD_TERM].revents & POLLIN) {
			daemon_exit();
		}

		if (((sel[FD_AMF].revents | sel[FD_MBX].revents) &
			(POLLERR | POLLHUP | POLLNVAL)) != 0) {
			LOG_ER("GLND poll() failure: %hd %hd",
				sel[FD_AMF].revents, sel[FD_MBX].revents);
			TRACE_LEAVE();
			return;
		}
		/* process all the AMF messages */
		if (sel[FD_AMF].revents & POLLIN) {
			/* dispatch all the AMF pending function */
			amf_error = saAmfDispatch(amf_hdl, SA_DISPATCH_ALL);
			if (amf_error != SA_AIS_OK) {
				TRACE_2("GLND amf dispatch failure");
			}
		}
		/* process the GLND Mail box */
		if (sel[FD_MBX].revents & POLLIN) {
			glnd_cb = (GLND_CB *)m_GLND_TAKE_GLND_CB;
			if (glnd_cb) {
				/* now got the IPC mail box event */
				glnd_process_mbx(glnd_cb, mbx);
				m_GLND_GIVEUP_GLND_CB;	/* giveup the handle */
			} else
				break;
		}
	}

	TRACE("DANGER: Exiting the Select loop of GLND");
end:
	TRACE_LEAVE();
	return;
}
Пример #19
0
/**
 * Forever wait on events and process them.
 */
static void main_process(void)
{
	NCS_SEL_OBJ mbx_fd;
	SaAisErrorT error = SA_AIS_OK;

	TRACE_ENTER();

	/*
	  The initialization of the IMM OM handle below is done to use a feature in the
	  IMM implementation. As long as one handle is initialized, IMM will not release the 
	  MDS subscription just reused it for new handles.
	  When SMF uses SmfImmUtils new handles are created and released during the execution.
	  If the campaign is big the MDS system limit of max number of subscriptions may be exceeded
	  i.e. "ERR    |MDTM: SYSTEM has crossed the max =500 subscriptions"
	  The code below will ensure there is always one IMM OM handle initialized.
	*/
	SaImmHandleT omHandle;
	SaVersionT immVersion = { 'A', 2, 1 };
	SaAisErrorT rc = immutil_saImmOmInitialize(&omHandle, NULL, &immVersion);
	if (rc != SA_AIS_OK) {
		LOG_ER("immutil_saImmOmInitialize faild, rc = %d", rc);
		return;
	}
	/* end of IMM featue code */

	mbx_fd = ncs_ipc_get_sel_obj(&smfd_cb->mbx);

	/* Set up all file descriptors to listen to */
	if (smfd_cb->nid_started)
		fds[SMFD_AMF_FD].fd = smfd_cb->usr1_sel_obj.rmv_obj;
	else
		fds[SMFD_AMF_FD].fd = smfd_cb->amfSelectionObject;

	fds[SMFD_AMF_FD].events = POLLIN;
	fds[SMFD_MBX_FD].fd = mbx_fd.rmv_obj;
	fds[SMFD_MBX_FD].events = POLLIN;
	fds[SMFD_COI_FD].fd = smfd_cb->campaignSelectionObject;
	fds[SMFD_COI_FD].events = POLLIN;

	while (1) {

		if (smfd_cb->campaignOiHandle != 0) {
			fds[SMFD_COI_FD].fd = smfd_cb->campaignSelectionObject;
			fds[SMFD_COI_FD].events = POLLIN;
			nfds = SMFD_MAX_FD;
		} else {
			nfds = SMFD_MAX_FD -1 ;
		}
		
		int ret = poll(fds, nfds, -1);

		if (ret == -1) {
			if (errno == EINTR)
				continue;

			LOG_ER("poll failed - %s", strerror(errno));
			break;
		}

		/* Process all the AMF messages */
		if (fds[SMFD_AMF_FD].revents & POLLIN) {
			if (smfd_cb->amf_hdl != 0) {
				/* dispatch all the AMF pending function */
				if ((error =
				     saAmfDispatch(smfd_cb->amf_hdl,
						   SA_DISPATCH_ALL)) !=
				    SA_AIS_OK) {
					LOG_ER("saAmfDispatch failed: %u",
					       error);
					break;
				}
			} else {
				TRACE("SIGUSR1 event rec");

				if (smfd_amf_init(smfd_cb) != NCSCC_RC_SUCCESS) {
					LOG_ER("init amf failed");
					break;
				}

				TRACE("AMF Initialization SUCCESS......");
				fds[SMFD_AMF_FD].fd =
				    smfd_cb->amfSelectionObject;
			}
		}

		/* Process all the Mail box events */
		if (fds[SMFD_MBX_FD].revents & POLLIN) {
			/* dispatch all the MBX events */
			smfd_process_mbx(&smfd_cb->mbx);
		}

		/* Process all the Imm callback events */
		if (fds[SMFD_COI_FD].revents & POLLIN) {
			if ((error =
			     saImmOiDispatch(smfd_cb->campaignOiHandle,
					     SA_DISPATCH_ALL)) != SA_AIS_OK) {
				/*
				 ** BAD_HANDLE is interpreted as an IMM service restart. Try
				 ** reinitialize the IMM OI API in a background thread and let
				 ** this thread do business as usual especially handling write
				 ** requests.
				 **
				 ** All other errors are treated as non-recoverable (fatal) and will
				 ** cause an exit of the process.
				 */
				if (error == SA_AIS_ERR_BAD_HANDLE) {
					TRACE("main: saImmOiDispatch returned BAD_HANDLE");

					/*
					 ** Invalidate the IMM OI handle, this info is used in other
					 ** locations. E.g. giving TRY_AGAIN responses to a create and
					 ** close app stream requests. That is needed since the IMM OI
					 ** is used in context of these functions.
					 */
					saImmOiFinalize(smfd_cb->campaignOiHandle );
					smfd_cb->campaignOiHandle = 0;

					/* Initiate IMM reinitializtion in the background */
					smfd_coi_reinit_bg(smfd_cb);
					

				} else if (error != SA_AIS_OK) {
					LOG_ER("main: saImmOiDispatch FAILED %u", error);
					break;
				}
			}
		}
	}

	rc = immutil_saImmOmAdminOwnerFinalize(omHandle);
	if (rc != SA_AIS_OK) {
		LOG_ER("immutil_saImmOmAdminOwnerFinalize faild, rc = %d", rc);
	}
}
int main(int argc, char *argv[])
{
    SaNameT             appName = {0};
    SaAmfCallbacksT     callbacks;
    SaVersionT          version;
    ClIocPortT          iocPort;
    SaAisErrorT         rc = SA_AIS_OK;

    SaSelectionObjectT dispatch_fd;
    fd_set read_fds;

    /*
     * Declare other local variables here.
     */


    /*
     * Get the pid for the process and store it in global variable.
     */

    mypid = getpid();

    /*
     * Initialize and register with CPM. 'version' specifies the version of
     * AMF with which this application would like to interface. 'callbacks'
     * is used to register the callbacks this component expects to receive.
     */

    version.releaseCode                         = 'B';
    version.majorVersion                        = 01;
    version.minorVersion                        = 01;

    callbacks.saAmfHealthcheckCallback                    = NULL;
    callbacks.saAmfComponentTerminateCallback             = clCompAppTerminate;
    callbacks.saAmfCSISetCallback                         = clCompAppAMFCSISet;
    callbacks.saAmfCSIRemoveCallback                      = clCompAppAMFCSIRemove;
    callbacks.saAmfProtectionGroupTrackCallback           = NULL;
    callbacks.saAmfProxiedComponentInstantiateCallback    = clProxiedCompInstantiate;
    callbacks.saAmfProxiedComponentCleanupCallback        = clProxiedCompCleanup;

    /*
     * Get IOC Address, Port and Name. Register with AMF.
     */

    clEoMyEoIocPortGet(&iocPort);

    if ( (rc = saAmfInitialize(&amfHandle, &callbacks, &version)) != SA_AIS_OK)
        goto errorexit;

    FD_ZERO(&read_fds);

    /*
     * Get the AMF dispatch FD for the callbacks
     */
    if ( (rc = saAmfSelectionObjectGet(amfHandle, &dispatch_fd)) != SA_AIS_OK)
        goto errorexit;

    FD_SET(dispatch_fd, &read_fds);

    /*
     * Do the application specific initialization here.
     */


    /*
     * Now register the component with AMF. At this point it is
     * ready to provide service, i.e. take work assignments.
     */

    if ( (rc = saAmfComponentNameGet(amfHandle, &appName)) != SA_AIS_OK)
        goto errorexit;
    if ( (rc = saAmfComponentRegister(amfHandle, &appName, NULL)) != SA_AIS_OK)
        goto errorexit;

    /*
     * Print out standard information for this component.
     */

    clprintf (CL_LOG_SEV_INFO, "Component [%.*s] : PID [%d]. Initializing\n", appName.length, appName.value, mypid);
    clprintf (CL_LOG_SEV_INFO, "   IOC Address             : 0x%x\n", clIocLocalAddressGet());
    clprintf (CL_LOG_SEV_INFO, "   IOC Port                : 0x%x\n", iocPort);

    /*
     * Block on AMF dispatch file descriptor for callbacks
     */
    do
    {
        if( select(dispatch_fd + 1, &read_fds, NULL, NULL, NULL) < 0)
        {
            clprintf (CL_LOG_SEV_ERROR, "Error in select()");
            perror("");
            break;
        }
        saAmfDispatch(amfHandle, SA_DISPATCH_ALL);
    } while(!unblockNow);

    /*
     * Do the application specific finalization here.
     */


    if((rc = saAmfFinalize(amfHandle)) != SA_AIS_OK)
    {
        clprintf (CL_LOG_SEV_ERROR, "AMF finalization error[0x%X]", rc);
    }

    clprintf (CL_LOG_SEV_INFO, "AMF Finalized");

    return 0;

errorexit:

    clprintf (CL_LOG_SEV_ERROR, "Component [%.*s] : PID [%d]. Initialization error [0x%x]\n",
              appName.length, appName.value, mypid, rc);

    return -1;
}
Пример #21
0
/**
 * Initialize with AMF
 * @param amf_sel_obj [out]
 * 
 * @return SaAisErrorT
 */
static SaAisErrorT amf_initialize(SaSelectionObjectT *amf_sel_obj)
{
	SaAisErrorT rc;
	SaAmfCallbacksT amf_callbacks = {0};
	SaVersionT api_ver =
		{.releaseCode = 'B', api_ver.majorVersion = 0x01, api_ver.minorVersion = 0x01};

	/* Initialize our callbacks */
	amf_callbacks.saAmfCSISetCallback = amf_csi_set_callback;
	amf_callbacks.saAmfCSIRemoveCallback = amf_csi_remove_callback;
	amf_callbacks.saAmfHealthcheckCallback = amf_healthcheck_callback;
	amf_callbacks.saAmfComponentTerminateCallback = amf_comp_terminate_callback;

	rc = saAmfInitialize(&my_amf_hdl, &amf_callbacks, &api_ver);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, " saAmfInitialize FAILED %u", rc);
		goto done;
	}

	rc = saAmfSelectionObjectGet(my_amf_hdl, amf_sel_obj);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, "saAmfSelectionObjectGet FAILED %u", rc);
		goto done;
	}

	rc = saAmfComponentNameGet(my_amf_hdl, &my_comp_name);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, "saAmfComponentNameGet FAILED %u", rc);
		goto done;
	}

	rc = saAmfComponentRegister(my_amf_hdl, &my_comp_name, 0);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, "saAmfComponentRegister FAILED %u", rc);
		goto done;
	}
	
	rc = saAmfHealthcheckStart(my_amf_hdl, &my_comp_name, &my_healthcheck_key,
		SA_AMF_HEALTHCHECK_AMF_INVOKED, SA_AMF_COMPONENT_RESTART);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, "saAmfHealthcheckStart FAILED - %u", rc);
		goto done;
	}
done:
	return rc;
}

int main(int argc, char **argv)
{
	SaAisErrorT rc;
	SaSelectionObjectT amf_sel_obj;
	struct pollfd fds[1];
	char *env_comp_name;

	/* Environment variable "SA_AMF_COMPONENT_NAME" exist when started by AMF */
	if ((env_comp_name = getenv("SA_AMF_COMPONENT_NAME")) == NULL) {
		fprintf(stderr, "not started by AMF exiting...\n");
		exit(EXIT_FAILURE);
	}

	/* Daemonize ourselves and detach from terminal.
	** This important since our start script will hang forever otherwise.
	** Note daemon() is not LSB but impl by libc so fairly portable...
	*/
	if (daemon(0, 0) == -1) {
		syslog(LOG_ERR, "daemon failed: %s", strerror(errno));
		goto done;
	}

	/* Install a TERM handler just to log and visualize when cleanup is called */
	if ((signal(SIGTERM, sigterm_handler)) == SIG_ERR) {
		syslog(LOG_ERR, "signal TERM failed: %s", strerror(errno));
		goto done;
	}

	/* Create a PID file which is needed by our CLC-CLI script.
	** Use AMF component name as file name so multiple instances of this
	** component can be managed by the same script.
	*/
	create_pid_file("/tmp", env_comp_name);

	/* Use syslog for logging */
	openlog(basename(argv[0]), LOG_PID, LOG_USER);

	/* Make a log to associate component name with PID */
	syslog(LOG_INFO, "'%s' started", env_comp_name);

	if (amf_initialize(&amf_sel_obj) != SA_AIS_OK)
		goto done;

	syslog(LOG_INFO, "Registered with AMF and HC started");

	fds[0].fd = amf_sel_obj;
	fds[0].events = POLLIN;

	/* Loop forever waiting for events on watched file descriptors */
	while (1) {
		int res = poll(fds, 1, -1);

		if (res == -1) {
			if (errno == EINTR)
				continue;
			else {
				syslog(LOG_ERR, "poll FAILED - %s", strerror(errno));
				goto done;
			}
		}

		if (fds[0].revents & POLLIN) {
			/* An AMF event is received, call AMF dispatch which in turn will
			 * call our installed callbacks. In context of this main thread.
			 */
			rc = saAmfDispatch(my_amf_hdl, SA_DISPATCH_ONE);
			if (rc != SA_AIS_OK) {
				syslog(LOG_ERR, "saAmfDispatch FAILED %u", rc);
				goto done;
			}
		}
	}

done:
	return EXIT_FAILURE;
}