/** * Initialize smfnd * * @return uns32 */ static uns32 initialize_smfnd(void) { uns32 rc; TRACE_ENTER(); if (ncs_agents_startup() != NCSCC_RC_SUCCESS) { LOG_ER("ncs_agents_startup FAILED"); rc = NCSCC_RC_FAILURE; goto done; } /* Initialize smfnd control block */ if (smfnd_cb_init(smfnd_cb) != NCSCC_RC_SUCCESS) { TRACE("smfnd_cb_init FAILED"); rc = NCSCC_RC_FAILURE; goto done; } /* Create the mailbox used for communication with SMFD/SMFA */ if ((rc = m_NCS_IPC_CREATE(&smfnd_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(&smfnd_cb->mbx) != NCSCC_RC_SUCCESS)) { LOG_ER("m_NCS_IPC_ATTACH FAILED %d", rc); goto done; } /* Create a selection object for USR1 signal handling */ if ((rc = ncs_sel_obj_create(&smfnd_cb->usr1_sel_obj)) != NCSCC_RC_SUCCESS) { LOG_ER("ncs_sel_obj_create failed"); goto done; } /* Initialize mds communication */ if ((rc = smfnd_mds_init(smfnd_cb)) != NCSCC_RC_SUCCESS) { TRACE("smfnd_mds_init FAILED %d", rc); return rc; } /* Check if AMF started */ if (smfnd_cb->nid_started == 0) { /* Started by AMF, so let's init AMF */ if ((rc = smfnd_amf_init(smfnd_cb)) != NCSCC_RC_SUCCESS) { LOG_ER("init amf failed"); goto done; } } done: TRACE_LEAVE(); return (rc); }
/** * Initialize the RDE server. * * @return int, 0=OK */ static int initialize_rde(void) { RDE_RDA_CB *rde_rda_cb = &rde_cb->rde_rda_cb; int rc = NCSCC_RC_FAILURE; char *val; /* Determine how this process was started, by NID or AMF */ if (getenv("SA_AMF_COMPONENT_NAME") == NULL) rde_cb->rde_amf_cb.nid_started = true; if ((val = getenv("RDE_DISCOVER_PEER_TIMEOUT")) != NULL) discover_peer_timeout = strtoul(val, NULL, 0); TRACE("discover_peer_timeout=%d", discover_peer_timeout); if ((rc = ncs_core_agents_startup()) != NCSCC_RC_SUCCESS) { LOG_ER("ncs_core_agents_startup FAILED"); goto init_failed; } if (rde_cb->rde_amf_cb.nid_started && (rc = ncs_sel_obj_create(&usr1_sel_obj)) != NCSCC_RC_SUCCESS) { LOG_ER("ncs_sel_obj_create FAILED"); goto init_failed; } if ((rc = ncs_ipc_create(&rde_cb->mbx)) != NCSCC_RC_SUCCESS) { LOG_ER("ncs_ipc_create FAILED"); goto init_failed; } if ((rc = ncs_ipc_attach(&rde_cb->mbx)) != NCSCC_RC_SUCCESS) { LOG_ER("ncs_ipc_attach FAILED"); goto init_failed; } rde_my_node_id = ncs_get_node_id(); if ((rc = rde_rda_open(RDE_RDA_SOCK_NAME, rde_rda_cb)) != NCSCC_RC_SUCCESS) goto init_failed; if (rde_cb->rde_amf_cb.nid_started && signal(SIGUSR1, sigusr1_handler) == SIG_ERR) { LOG_ER("signal USR1 FAILED: %s", strerror(errno)); goto init_failed; } if (rde_mds_register(rde_cb) != NCSCC_RC_SUCCESS) goto init_failed; rc = NCSCC_RC_SUCCESS; init_failed: return rc; }
/** * Install TERM signal handler and return descriptor to monitor * @param[out] term_fd socket descriptor to monitor for SIGTERM event */ void daemon_sigterm_install(int *term_fd) { if (ncs_sel_obj_create(&term_sel_obj) != NCSCC_RC_SUCCESS) { syslog(LOG_ERR, "ncs_sel_obj_create failed"); exit(EXIT_FAILURE); } if (signal(SIGTERM, sigterm_handler) == SIG_ERR) { syslog(LOG_ERR, "signal TERM failed: %s", strerror(errno)); exit(EXIT_FAILURE); } *term_fd = term_sel_obj.rmv_obj; }
/** * 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; }
/** * 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; }
/* * Exit if anything fails. This will cause ntfs to restart ntfimcn */ int main(int argc, char** argv) { const char* logPath; const char* trace_label = "osafntfimcnd"; SaAisErrorT ais_error = SA_AIS_OK; /* * Activate Log Trace */ openlog(basename(argv[0]), LOG_PID, LOG_LOCAL0); if ((logPath = getenv("NTFSCN_TRACE_PATHNAME"))) { category_mask = 0xffffffff; } else { logPath = PKGLOGDIR "/" NTFIMCN_DEFAULT_LOG; } if (logtrace_init(trace_label, logPath, category_mask) == -1) { syslog(LOG_ERR, "osafntfimcnd logtrace_init FAILED"); /* We allow to execute anyway. */ } /* * Initiate HA state */ if (strcmp(argv[1],"active") == 0) { ntfimcn_cb.haState = SA_AMF_HA_ACTIVE; } else { ntfimcn_cb.haState = SA_AMF_HA_STANDBY; } /* * Initiate external functionallity * Exit on fail. This will cause ntfs to restart ntfimcn */ if (ntfimcn_ntf_init(&ntfimcn_cb) == NTFIMCN_INTERNAL_ERROR) { LOG_ER("ntfimcn_ntf_init() Fail"); _Exit(EXIT_FAILURE); } if (ntfimcn_imm_init(&ntfimcn_cb) == NTFIMCN_INTERNAL_ERROR) { LOG_ER("ntfimcn_imm_init() Fail"); imcn_exit(EXIT_FAILURE); } /* Signal for TRACE on/off */ if (signal(SIGUSR2, sigusr2_handler) == SIG_ERR) { LOG_ER("signal USR2 failed: %s", strerror(errno)); /* We allow to execute anyway. */ } if (ntfimcn_send_lost_cm_notification() == NTFIMCN_INTERNAL_ERROR) { LOG_ER("send_lost_cm_notification() Fail"); imcn_exit(EXIT_FAILURE); } /* Termination signal with handler */ if (ncs_sel_obj_create(&term_sel_obj) != NCSCC_RC_SUCCESS) { LOG_ER("ncs_sel_obj_create failed"); _Exit(EXIT_FAILURE); } if (signal(SIGTERM, sigterm_handler) == SIG_ERR) { LOG_ER("signal TERM failed: %s", strerror(errno)); _Exit(EXIT_FAILURE); } /* * Initiate polling */ fds[FD_IMM].fd = ntfimcn_cb.immSelectionObject; fds[FD_IMM].events = POLLIN; fds[FD_TERM].fd = term_sel_obj.rmv_obj; fds[FD_TERM].events = POLLIN; LOG_NO("Started"); while (1) { if (poll(fds, nfds, -1) == (-1)) { if (errno == EINTR) { continue; } LOG_ER("poll Fail - %s", strerror(errno)); imcn_exit(EXIT_FAILURE); } if (fds[FD_TERM].revents & POLLIN) { handle_sigterm_event(); } if (fds[FD_IMM].revents & POLLIN) { ais_error = saImmOiDispatch(ntfimcn_cb.immOiHandle, SA_DISPATCH_ALL); if (ais_error != SA_AIS_OK) { LOG_NO("saImmOiDispatch() Fail %s",saf_error(ais_error)); imcn_exit(EXIT_FAILURE); } } } return 0; /* Dummy */ }
/** * Initialize smfd * * @return uns32 */ static uns32 initialize_smfd(void) { uns32 rc; TRACE_ENTER(); /* Set the behaviour of SMF-IMM interactions */ immutilWrapperProfile.errorsAreFatal = 0; /* False, no reboot when fail */ immutilWrapperProfile.nTries = 500; /* Times */ immutilWrapperProfile.retryInterval = 400; /* MS */ if (ncs_agents_startup() != NCSCC_RC_SUCCESS) { LOG_ER("ncs_agents_startup FAILED"); rc = NCSCC_RC_FAILURE; goto done; } /* Initialize smfd control block */ if (smfd_cb_init(smfd_cb) != NCSCC_RC_SUCCESS) { TRACE("smfd_cb_init FAILED"); rc = NCSCC_RC_FAILURE; goto done; } /* Create the mailbox used for communication with SMFND */ if ((rc = m_NCS_IPC_CREATE(&smfd_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(&smfd_cb->mbx) != NCSCC_RC_SUCCESS)) { LOG_ER("m_NCS_IPC_ATTACH FAILED %d", rc); goto done; } /* Create a selection object for USR1 signal handling */ if ((rc = ncs_sel_obj_create(&smfd_cb->usr1_sel_obj)) != NCSCC_RC_SUCCESS) { LOG_ER("ncs_sel_obj_create failed"); goto done; } /* Init mds communication */ if ((rc = smfd_mds_init(smfd_cb)) != NCSCC_RC_SUCCESS) { TRACE("smfd_mds_init FAILED %d", rc); return rc; } /* Init campaign OI */ if ((rc = campaign_oi_init(smfd_cb)) != NCSCC_RC_SUCCESS) { TRACE("campaign_oi_init FAILED %d", rc); return rc; } /* Check if AMF started */ if (smfd_cb->nid_started == 0) { /* Started by AMF, so let's init AMF */ if ((rc = smfd_amf_init(smfd_cb)) != NCSCC_RC_SUCCESS) { LOG_ER("init amf failed"); goto done; } } done: TRACE_LEAVE(); return (rc); }