/**
 * The main routine for the smfd daemon.
 * @param argc
 * @param argv
 * 
 * @return int
 */
int main(int argc, char *argv[])
{
	/* Determine how this process was started, by NID or AMF */
	if (getenv("SA_AMF_COMPONENT_NAME") != NULL) {
		/* AMF start */
		smfd_cb->nid_started = 0;
	} else {
		/* NID start */
		smfd_cb->nid_started = 1;
	}

	daemonize(argc, argv);

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

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

	if (signal(SIGUSR1, usr1_sig_handler) == SIG_ERR) {
		LOG_ER("signal SIGUSR1 failed");
		goto done;
	}

	if (smfd_cb->nid_started == 1) {
		if (nid_notify("SMFD", NCSCC_RC_SUCCESS, NULL) !=
		    NCSCC_RC_SUCCESS)
			LOG_ER("nid_notify failed");
	}

	main_process();

	exit(EXIT_SUCCESS);

 done:
	if (smfd_cb->nid_started == 1) {
		if (nid_notify("SMFD", NCSCC_RC_FAILURE, NULL) !=
		    NCSCC_RC_SUCCESS)
			LOG_ER("nid_notify failed");
	}

	LOG_ER("SMFD failed, exiting...");
	exit(EXIT_FAILURE);
}
Beispiel #2
0
/****************************************************************************
* Name          : fm_nid_notify
*
* Description   : Sends notification to NID
*
* Arguments     :  Error Type
*
* Return Values : NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE.
* 
* Notes         : None. 
*****************************************************************************/
static uns32 fm_nid_notify(uns32 nid_err)
{
	uns32 error;
	uns32 nid_stat_code;

	if (nid_err > NCSCC_RC_SUCCESS)
		nid_err = NCSCC_RC_FAILURE;

	nid_stat_code = nid_err;
	return nid_notify("HLFM", nid_stat_code, &error);
}
Beispiel #3
0
int main(int argc, char *argv[])
{
	daemonize(argc, argv);

	if (__init_dts() != NCSCC_RC_SUCCESS) {
		syslog(LOG_ERR, "__init_dts() failed");
		exit(EXIT_FAILURE);
	}

	if (nid_notify("DTSV", NCSCC_RC_SUCCESS, NULL) != NCSCC_RC_SUCCESS) {
		LOG_ER("nid_notify failed");
		exit(EXIT_FAILURE);
	}

	while (1) {
		m_NCS_TASK_SLEEP(0xfffffff0);
	}

	exit(1);
}
/**
 * Initialize immd
 * 
 * @return uns32
 */
static uns32 immd_initialize(void)
{
	uns32 rc = NCSCC_RC_SUCCESS;

	TRACE_ENTER();

	if (ncs_agents_startup() != NCSCC_RC_SUCCESS) {
		LOG_ER("ncs_agents_startup FAILED");
		goto done;
	}

	if ((rc = rda_get_role(&immd_cb->ha_state)) != NCSCC_RC_SUCCESS) {
		LOG_ER("rda_get_role FAILED");
		goto done;
	}

	if ((rc = rda_register_callback(0, rda_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("rda_register_callback FAILED %u", rc);
		goto done;
	}

	/* Init the EDU Handle */
	m_NCS_EDU_HDL_INIT(&immd_cb->edu_hdl);

	if ((rc = immd_cb_db_init(immd_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("immd_cb_db_init FAILED");
		goto done;
	}

	/* Create a mail box */
	if ((rc = m_NCS_IPC_CREATE(&immd_cb->mbx)) != NCSCC_RC_SUCCESS) {
		LOG_ER("m_NCS_IPC_CREATE FAILED");
		goto done;
	}

	/* Attach the IPC to mail box */
	if ((rc = m_NCS_IPC_ATTACH(&immd_cb->mbx)) != NCSCC_RC_SUCCESS) {
		LOG_ER("m_NCS_IPC_ATTACH FAILED");
		goto done;
	}

	if ((rc = immd_mds_register(immd_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("immd_mds_register FAILED %d", rc);
		goto done;
	}

	/* Initialise with the MBCSV service  */
	if ((rc = immd_mbcsv_register(immd_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("immd_mbcsv_register FAILED %d", rc);
		goto done;
	}

	if ((rc = immd_mbcsv_chgrole(immd_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("immd_mbcsv_chgrole FAILED %d", rc);
		goto done;
	}

	/* Create a selection object */
	if ((rc = ncs_sel_obj_create(&immd_cb->usr1_sel_obj)) != NCSCC_RC_SUCCESS) {
		LOG_ER("ncs_sel_obj_create failed");
		goto done;
	}

	/*
	 * Initialize a signal handler that will use the selection object.
	 * The signal is sent from our script when AMF does instantiate.
	 */
	if ((signal(SIGUSR1, sigusr1_handler)) == SIG_ERR) {
		LOG_ER("signal USR1 failed: %s", strerror(errno));
		rc = NCSCC_RC_FAILURE;
		goto done;
	}

	syslog(LOG_INFO, "Initialization Success, role %s",
	       (immd_cb->ha_state == SA_AMF_HA_ACTIVE) ? "ACTIVE" : "STANDBY");

done:
	if (nid_notify("IMMD", rc, NULL) != NCSCC_RC_SUCCESS) {
		LOG_ER("nid_notify failed");
		rc = NCSCC_RC_FAILURE;
	}

	TRACE_LEAVE();
	return rc;
}
Beispiel #5
0
/**
 * Initialize clm
 * 
 * @return uns32
 */
static uint32_t clms_init(void)
{
	uint32_t rc = NCSCC_RC_FAILURE;

	TRACE_ENTER();

	/* Determine how this process was started, by NID or AMF */
	if (getenv("SA_AMF_COMPONENT_NAME") == NULL)
		clms_cb->nid_started = true;

	if (ncs_agents_startup() != NCSCC_RC_SUCCESS) {
		TRACE("ncs_core_agents_startup FAILED");
		goto done;
	}

	/* Initialize clms control block */
	if ((rc = clms_cb_init(clms_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("clms_cb_init FAILED");
		goto done;
	}

	if ((rc = rda_get_role(&clms_cb->ha_state)) != NCSCC_RC_SUCCESS) {
		LOG_ER("rda_get_role FAILED");
		goto done;
	}
	TRACE("Current RDA Role %d", clms_cb->ha_state);

	if ((rc = rda_register_callback(0, rda_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("rda_register_callback FAILED %u", rc);
		goto done;
	}

	/* Create the mailbox used for communication with CLMS */
	if ((rc = m_NCS_IPC_CREATE(&clms_cb->mbx)) != NCSCC_RC_SUCCESS) {
		LOG_ER("m_NCS_IPC_CREATE FAILED %d", rc);
		goto done;
	}

	/* Attach mailbox to this thread */
	if ((rc = m_NCS_IPC_ATTACH(&clms_cb->mbx) != NCSCC_RC_SUCCESS)) {
		LOG_ER("m_NCS_IPC_ATTACH FAILED %d", rc);
		goto done;
	}

	/*Initialize mds */
	if ((rc = clms_mds_init(clms_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("clms_mds_init FAILED %d", rc);
		goto done;
	}

	/* Initialize with MBCSV */
	if ((rc = clms_mbcsv_init(clms_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("clms_mbcsv_init FAILED");
		goto done;
	}

	/* Initialize with IMMSv */
	if ((rc = clms_imm_init(clms_cb)) != NCSCC_RC_SUCCESS) {
		LOG_ER("clms_imm_init FAILED");
		goto done;
	}

	/* Declare as implementer && Read configuration data from IMM */
	if ((rc = clms_imm_activate(clms_cb)) != SA_AIS_OK) {
		LOG_ER("clms_imm_activate FAILED");
		goto done;
	}

	if ((rc = clms_ntf_init(clms_cb)) != SA_AIS_OK) {
		LOG_ER("clms_ntf_init FAILED");
		goto done;
	}

#ifdef ENABLE_AIS_PLM
	if ((rc = clms_plm_init(clms_cb)) != SA_AIS_OK) {
		LOG_ER("clms_plm_init FAILED");
		goto done;
	}
#endif

	/*Self Node update */
	if ((rc = clms_self_node_info()) != NCSCC_RC_SUCCESS)
		goto done;

	/* Create a selection object */
	if (clms_cb->nid_started &&
		(rc = ncs_sel_obj_create(&usr1_sel_obj)) != NCSCC_RC_SUCCESS) {
		LOG_ER("ncs_sel_obj_create failed");
		goto done;
	}

	/*
	 ** Initialize a signal handler that will use the selection object.
	 ** The signal is sent from our script when AMF does instantiate.
	 */
	if (clms_cb->nid_started &&
		signal(SIGUSR1, sigusr1_handler) == SIG_ERR) {
		LOG_ER("signal USR1 failed: %s", strerror(errno));
		goto done;
	}

	if (!clms_cb->nid_started &&
		clms_amf_init(clms_cb) != NCSCC_RC_SUCCESS) {
		LOG_ER("AMF Initialization failed");
		goto done;
	}

	/* Initialize with saflog. This is necessary to avoid
	 *  getting blocked by LOG during role change (switchover/failover)
	 */
	saflog_init();

	rc = NCSCC_RC_SUCCESS;

 done:
	if (clms_cb->nid_started &&
		nid_notify("CLMD", rc, NULL) != NCSCC_RC_SUCCESS) {
		LOG_ER("nid_notify failed");
		rc = NCSCC_RC_FAILURE;
	}

	TRACE_LEAVE();
	return rc;
}
Beispiel #6
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);
}