Ejemplo n.º 1
0
int wait_for_all_children(void)
{
	int procs_no,i,ret;
	char rc;

	procs_no = count_init_children(PROC_FLAG_INITCHILD);
	for (i=0;i<procs_no;i++) {
		ret = wait_status_code(&rc);
		if (ret < 0 || rc < 0)
			return -1;
	}

	/* we got this far, means everything went ok with 
	 * SIP listeners and module procs
	 *
	 * still need to see if
	 * timers initialized ok */

	for (i=0;i<*init_timer_no;i++) {
		LM_DBG("waiting for timer\n");
		ret = wait_status_code(&rc);
		if (ret < 0 || rc < 0 )
			return -1;
	}

	return 0;
}
Ejemplo n.º 2
0
/* creates status pipes */
int xmlrpc_create_status_pipes(void) {
	int rc, i;

	nr_procs = count_init_children(0) + 2;	/* + 2 timer processes */

	xmlrpc_status_pipes = shm_malloc(nr_procs * sizeof(xmlrpc_pipe));

	if (!xmlrpc_status_pipes) {
		LM_ERR("cannot allocate xmlrpc_status_pipes\n");
		return -1;
	}

	/* create pipes */
	for (i = 0; i < nr_procs; i++) {
		do {
			rc = pipe(xmlrpc_status_pipes[i]);
		} while (rc < 0 && IS_ERR(EINTR));

		if (rc < 0) {
			LM_ERR("cannot create status pipe [%d:%s]\n", errno, strerror(errno));
			return -1;
		}
	}
	return 0;
}
Ejemplo n.º 3
0
static int mod_init(void)
{
	int i, udp_receiver_no;

	LM_INFO("initializing module\n");

	memset(&dlg_binds, 0, sizeof(dlg_binds));
	if (load_dlg_api(&dlg_binds) != 0) {
		LM_ERR("failed to load dlg api\n");
		return -1;
	}

	sdp_buffer.s = pkg_malloc(SDP_BUFFER_SIZE);
	if (!sdp_buffer.s) {
		LM_ERR("insufficient pkg memory\n");
		return -1;
	}

    udp_receiver_no = count_init_children(0);

	if (!dont_fork) {

#ifdef USE_TCP
		udp_receiver_no -= !tcp_disable ? tcp_children_no : 0;
#endif

		udp_receiver_no--; /* MAIN */
	}

	udp_receiver_no -= 2; /* TIMER, SANGOMA WORKER */

	LM_DBG("Children: %d\n", udp_receiver_no);

    udp_receiver_pipes = pkg_malloc(2 * udp_receiver_no *
	                                sizeof(*udp_receiver_pipes));
    if (!udp_receiver_pipes) {
        LM_ERR("Not enough pkg mem\n");
        return -1;
    }

	index_lock = shm_malloc(sizeof(*index_lock));
	if (!index_lock) {
		LM_ERR("No more shm mem\n");
		return -1;
	}

	if (!lock_init(index_lock)) {
		LM_ERR("Failed to init lock\n");
		return -1;
	}

	proc_counter = shm_malloc(sizeof(*proc_counter));
	if (!proc_counter) {
		LM_ERR("Not enough shm mem\n");
		return -1;
	}

	*proc_counter = 0;

	if (pipe(sangoma_pipe) != 0) {
		LM_ERR("Failed to create sangoma worker pipe\n");
		return -1;
	}

	LM_DBG("Sangoma pipe: [%d %d]\n", sangoma_pipe[0], sangoma_pipe[1]);

	for (i = 0; i < udp_receiver_no; i++) {
		if (pipe(udp_receiver_pipes + 2 * i) != 0) {
			LM_ERR("Failed to create pipe for UDP receiver %d\n", i);
			return -1;
		}

		LM_DBG("SIP pipe: [%d %d]\n", udp_receiver_pipes[2 * i],
		       udp_receiver_pipes[2 * i + 1]);
	}

	sngtc_init_cfg.operation_mode   = SNGTC_MODE_SOAP_CLIENT;
	sngtc_init_cfg.log              = sng_logger;
	sngtc_init_cfg.create_rtp       = sng_create_rtp;
	sngtc_init_cfg.create_rtp_port  = sng_create_rtp_port;
	sngtc_init_cfg.destroy_rtp      = sng_destroy_rtp;
	sngtc_init_cfg.release_rtp_port = sng_release_rtp_port;

	if (sngtc_detect_init_modules(&sngtc_init_cfg, &i) != 0) {
		LM_ERR("failed to detect vocallo modules\n");
		return -1;
	}

	LM_DBG("Detected %d vocallo modules\n", i);

	if (sngtc_activate_modules(&sngtc_init_cfg, &i) != 0) {
		LM_ERR("failed to activate vocallo modules\n");
		return -1;
	}

	LM_DBG("Activated %d vocallo modules\n", i);

	return 0;
}