src/dpdk/lib/librte_eal/freebsd/eal.c
static int
rte_eal_config_attach(void)
{
	void *rte_mem_cfg_addr;
	const char *pathname = eal_runtime_config_path();
	struct rte_config *config = rte_eal_get_configuration();
	const struct internal_config *internal_conf =
		eal_get_internal_configuration();


	if (internal_conf->no_shconf)
		return 0;

	if (mem_cfg_fd < 0){
		mem_cfg_fd = open(pathname, O_RDWR);
		if (mem_cfg_fd < 0) {
			RTE_LOG(ERR, EAL, "Cannot open '%s' for rte_mem_config\n",
				pathname);
			return -1;
		}
	}

	rte_mem_cfg_addr = mmap(NULL, sizeof(*config->mem_config),
				PROT_READ, MAP_SHARED, mem_cfg_fd, 0);
	/* don't close the fd here, it will be closed on reattach */
	if (rte_mem_cfg_addr == MAP_FAILED) {
		close(mem_cfg_fd);
		mem_cfg_fd = -1;
		RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config! error %i (%s)\n",
			errno, strerror(errno));
		return -1;
	}

	config->mem_config = rte_mem_cfg_addr;

	return 0;
}
/* attach to an existing shared memory config */
attach to an existing shared memory config
attach to an existing shared memory config
static int
rte_eal_config_attach(void)
{
	void *rte_mem_cfg_addr;
	const char *pathname = eal_runtime_config_path();
	struct rte_config *config = rte_eal_get_configuration();
	const struct internal_config *internal_conf =
		eal_get_internal_configuration();
	if (internal_conf->no_shconf)
		return 0;
	if (mem_cfg_fd < 0){
		mem_cfg_fd = open(pathname, O_RDWR);
		if (mem_cfg_fd < 0) {
			RTE_LOG(ERR, EAL, "Cannot open '%s' for rte_mem_config\n",
				pathname);
			return -1;
		}
	}
	rte_mem_cfg_addr = mmap(NULL, sizeof(*config->mem_config),
				PROT_READ, MAP_SHARED, mem_cfg_fd, 0);
	if (rte_mem_cfg_addr == MAP_FAILED) {
		close(mem_cfg_fd);
		mem_cfg_fd = -1;
		RTE_LOG(ERR, EAL, "Cannot mmap memory for rte_config! error %i (%s)\n",
			errno, strerror(errno));
		return -1;
	}
	config->mem_config = rte_mem_cfg_addr;
	return 0;
}
static int rte_eal_config_attach ( void ) { void * rte_mem_cfg_addr ; const char * pathname = eal_runtime_config_path ( ) ; struct rte_config * config = rte_eal_get_configuration ( ) ; const struct internal_config * internal_conf = eal_get_internal_configuration ( ) ; if ( internal_conf -> no_shconf ) return 0 ; if ( mem_cfg_fd < 0 ) { mem_cfg_fd = open ( pathname , O_RDWR ) ; if ( mem_cfg_fd < 0 ) { RTE_LOG ( ERR , EAL , " \n " , pathname ) ; return -1 ; } } rte_mem_cfg_addr = mmap ( NULL , sizeof ( * config -> mem_config ) , PROT_READ , MAP_SHARED , mem_cfg_fd , 0 ) ; if ( rte_mem_cfg_addr == MAP_FAILED ) { close ( mem_cfg_fd ) ; mem_cfg_fd = -1 ; RTE_LOG ( ERR , EAL , " \n " , errno , strerror ( errno ) ) ; return -1 ; } config -> mem_config = rte_mem_cfg_addr ; return 0 ; }
attach to an existing shared memory config
attach to an existing shared memory config
/* don't close the fd here, it will be closed on reattach */