Ejemplo n.º 1
0
/****************************************************************************
  Name          :  ncs_mqa_startup

  Description   :  This routine creates a MQSv agent infrastructure to interface
                   with MQSv service. Once the infrastructure is created from
                   then on use_count is incremented for every startup request.

  Arguments     :  - NIL-

  Return Values :  NCSCC_RC_SUCCESS/NCSCC_RC_FAILURE

  Notes         :  None
******************************************************************************/
unsigned int ncs_mqa_startup(void)
{
	NCS_LIB_REQ_INFO lib_create;
	char *value = NULL;

	osaf_mutex_lock_ordie(&s_agent_startup_mutex);
	if (mqa_use_count > 0) {
		/* Already created, so just increment the use_count */
		mqa_use_count++;
		osaf_mutex_unlock_ordie(&s_agent_startup_mutex);
		return NCSCC_RC_SUCCESS;
	}

   /*** Init MQA ***/
	memset(&lib_create, 0, sizeof(lib_create));
	lib_create.i_op = NCS_LIB_REQ_CREATE;
	if (mqa_lib_req(&lib_create) != NCSCC_RC_SUCCESS) {
		osaf_mutex_unlock_ordie(&s_agent_startup_mutex);
		return m_LEAP_DBG_SINK(NCSCC_RC_FAILURE);
	} else {
		printf("\nMQSV:MQA:ON");
		mqa_use_count = 1;
	}

	/* Initialize trace system first of all so we can see what is going. */
	if ((value = getenv("MQA_TRACE_PATHNAME")) != NULL) {
		logtrace_init("mqa", value, CATEGORY_ALL);
	}

	osaf_mutex_unlock_ordie(&s_agent_startup_mutex);
	return NCSCC_RC_SUCCESS;
}
Ejemplo n.º 2
0
static void logtrace_init_constructor(void)
{
    char *value;
    /* Initialize trace system first of all so we can see what is going. */
    if ((value = getenv("EDA_TRACE_PATH_FILENAME")) != NULL) {
        if (logtrace_init("eda", value, CATEGORY_ALL) != 0) {
            /* error, we cannot do anything */
            return;
        }
    }
}
Ejemplo n.º 3
0
int logtrace_init_daemon(const char *_ident, const char *_pathname, unsigned int _tracemask, int _loglevel)
{
    if (signal(SIGUSR2, sigusr2_handler) == SIG_ERR) {
        syslog(LOG_ERR, "logtrace: registering SIGUSR2 failed, (%s)", strerror(errno));
        return -1;
    }

    if (signal(SIGUSR1, sigusr1_handler) == SIG_ERR) {
        syslog(LOG_ERR, "logtrace: registering SIGUSR1 failed, (%s)", strerror(errno));
        return -1;
    }

    loglevel = _loglevel;
    setlogmask(LOG_UPTO(_loglevel));

    return logtrace_init(_ident, _pathname, _tracemask);
}
Ejemplo n.º 4
0
int logtrace_init_daemon(const char *_ident, const char *_pathname, unsigned int _tracemask, int _logmask)
{
	if (signal(SIGUSR2, sigusr2_handler) == SIG_ERR) {
		syslog(LOG_ERR, "logtrace: registering SIGUSR2 failed, (%s)", strerror(errno));
		return -1;
	}

	setlogmask(_logmask);

	if (signal(SIGHUP, sighup_handler) == SIG_ERR) {
		syslog(LOG_ERR, "logtrace: registering SIGHUP failed, (%s)", strerror(errno));
		return -1;
	}

	logmask = _logmask;

	return logtrace_init(_ident, _pathname, _tracemask);
}
Ejemplo n.º 5
0
/*
 * 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 */
}