Esempio n. 1
0
static int mod_init(void)
{
	struct id_list* l;
	
	if (listen_lst==0) {
		add_binrpc_socket(PARAM_STRING, DEFAULT_CTL_SOCKET);
	}
	DBG("listening on:\n");
	for (l=listen_lst; l; l=l->next){
		fd_no++;
		switch(l->proto){
			case UNIXD_SOCK:
				DBG("        [%s:unix dgram]  %s\n",
						payload_proto_name(l->data_proto), l->name);
				break;
			case UNIXS_SOCK:
				DBG("        [%s:unix stream] %s\n",
						payload_proto_name(l->data_proto), l->name);
				break;
			case UDP_SOCK:
				DBG("        [%s:udp]         %s:%d\n", 
						payload_proto_name(l->data_proto), l->name,
						l->port?l->port:DEFAULT_CTL_PORT);
				break;
			case TCP_SOCK:
				DBG("        [%s:tcp]         %s:%d\n",
						payload_proto_name(l->data_proto), l->name,
						l->port?l->port:DEFAULT_CTL_PORT);
				break;
			case FIFO_SOCK:
				DBG("        [%s:fifo]         %s\n",
						payload_proto_name(l->data_proto), l->name);
				fd_no++; /* fifos use 2 fds */
				break;
			default:
				LOG(L_CRIT, "BUG: ctrl: listen protocol %d not supported\n",
						l->proto);
				goto error;
			}
	}
	/* open socket now, before suid */
	if (init_ctrl_sockets(&ctrl_sock_lst, listen_lst, DEFAULT_CTL_PORT,
			usock_mode, usock_uid, usock_gid)<0){
		LOG(L_ERR, "ERROR: ctl: mod_init: init ctrl. sockets failed\n");
		goto error;
	}
	if (ctrl_sock_lst){
		/* we will fork */
		register_procs(1); /* we will be creating an extra process */
		register_fds(fd_no);
		/* The child process will keep updating its local configuration */
		cfg_register_child(1);
	}
#ifdef USE_FIFO
	fifo_rpc_init();
#endif
	return 0;
error:
	return -1;
}
Esempio n. 2
0
static void  ctrl_listen_ls_rpc(rpc_t* rpc, void* ctx)
{
	struct ctrl_socket* cs;
	
	for (cs=ctrl_sock_lst; cs; cs=cs->next){
		rpc->add(ctx, "ssss", payload_proto_name(cs->p_proto),
						socket_proto_name(cs->transport),
						cs->name, (cs->port)?int2str(cs->port, 0):"");
	}
}
Esempio n. 3
0
static int mod_init(void)
{
	struct id_list* l;
	char ctl_socket_path[CTL_SOCKET_PATH_SIZE];

	binrpc_callbacks_init();

	if(binrpc_max_body_size<=0)
		binrpc_max_body_size = 4;
	if(binrpc_struct_max_body_size<=0)
		binrpc_struct_max_body_size = 1;
	binrpc_max_body_size *= 1024;
	binrpc_struct_max_body_size *= 1024;

	if (listen_lst==0) {
		if(strcmp(runtime_dir, RUN_DIR)==0) {
			add_binrpc_socket(PARAM_STRING, DEFAULT_CTL_SOCKET);
		} else {
			if(sizeof(DEFAULT_CTL_SOCKET_PROTO)
					+ sizeof(DEFAULT_CTL_SOCKET_NAME)
					+ strlen(runtime_dir) + 4 > CTL_SOCKET_PATH_SIZE) {
				LM_ERR("ctl socket path is too big\n");
				return -1;
			}
			strcpy(ctl_socket_path, DEFAULT_CTL_SOCKET_PROTO);
			strcat(ctl_socket_path, runtime_dir);
			strcat(ctl_socket_path, "/");
			strcat(ctl_socket_path, DEFAULT_CTL_SOCKET_NAME);
			add_binrpc_socket(PARAM_STRING, ctl_socket_path);
		}
	}
	DBG("listening on:\n");
	for (l=listen_lst; l; l=l->next){
		fd_no++;
		switch(l->proto){
			case UNIXD_SOCK:
				DBG("        [%s:unix dgram]  %s\n",
						payload_proto_name(l->data_proto), l->name);
				break;
			case UNIXS_SOCK:
				DBG("        [%s:unix stream] %s\n",
						payload_proto_name(l->data_proto), l->name);
				break;
			case UDP_SOCK:
				DBG("        [%s:udp]         %s:%d\n",
						payload_proto_name(l->data_proto), l->name,
						l->port?l->port:DEFAULT_CTL_PORT);
				break;
			case TCP_SOCK:
				DBG("        [%s:tcp]         %s:%d\n",
						payload_proto_name(l->data_proto), l->name,
						l->port?l->port:DEFAULT_CTL_PORT);
				break;
#ifdef USE_FIFO
			case FIFO_SOCK:
				DBG("        [%s:fifo]         %s\n",
						payload_proto_name(l->data_proto), l->name);
				fd_no++; /* fifos use 2 fds */
				break;
#endif
			default:
				LOG(L_CRIT, "BUG: ctrl: listen protocol %d not supported\n",
						l->proto);
				goto error;
			}
	}
	/* get the uid/gid from core if not set for the module */
	if(usock_uid==-1 && sock_uid!=-1) usock_uid = sock_uid;
	if(usock_gid==-1 && sock_gid!=-1) usock_gid = sock_gid;
	/* open socket now, before suid */
	if (init_ctrl_sockets(&ctrl_sock_lst, listen_lst, DEFAULT_CTL_PORT,
			usock_mode, usock_uid, usock_gid)<0){
		LOG(L_ERR, "ERROR: ctl: mod_init: init ctrl. sockets failed\n");
		goto error;
	}
	if (ctrl_sock_lst){
		/* we will fork */
		register_procs(1); /* we will be creating an extra process */
		register_fds(fd_no);
		/* The child process will keep updating its local configuration */
		cfg_register_child(1);
	}
#ifdef USE_FIFO
	fifo_rpc_init();
#endif
	return 0;
error:
	return -1;
}