static void citp_opts_getenv(citp_opts_t* opts) { /* ?? TODO: would like to use opts_citp_def.h here */ const char* s; unsigned v; opts->log_via_ioctl = 3; /* TODO: Old name. Keeping reading 'til 2011, then purge. */ GET_ENV_OPT_HEX("EF_Log_VIA_IOCTL", log_via_ioctl); GET_ENV_OPT_INT("EF_LOG_VIA_IOCTL", log_via_ioctl); if( (s = getenv("EF_LOG_FILE")) && opts->log_via_ioctl == 3) { opts->log_via_ioctl = 0; citp_log_to_file(s); } else if( opts->log_via_ioctl == 3 ) { /* citp_setup_logging_early() have already detected stderr as * tty/non-tty, so just trust it. */ if( ci_log_fn == citp_log_fn_drv ) opts->log_via_ioctl = 1; else opts->log_via_ioctl = 0; } if( opts->log_via_ioctl ) { ci_log_options &=~ CI_LOG_PID; citp_setup_logging_change(citp_log_fn_drv); } else { if( getenv("EF_LOG_TIMESTAMPS") ) ci_log_options |= CI_LOG_TIME; citp_setup_logging_change(citp_log_fn_ul); } if( getenv("EF_POLL_NONBLOCK_FAST_LOOPS") && ! getenv("EF_POLL_NONBLOCK_FAST_USEC") ) log("ERROR: EF_POLL_NONBLOCK_FAST_LOOPS is deprecated, use" " EF_POLL_NONBLOCK_FAST_USEC instead"); if( getenv("EF_POLL_FAST_LOOPS") && ! getenv("EF_POLL_FAST_USEC") ) log("ERROR: EF_POLL_FAST_LOOPS is deprecated, use" " EF_POLL_FAST_USEC instead"); if( (s = getenv("EF_POLL_USEC")) && atoi(s) ) { GET_ENV_OPT_INT("EF_POLL_USEC", ul_spin_usec); opts->ul_select_spin = 1; opts->ul_poll_spin = 1; #if CI_CFG_USERSPACE_EPOLL opts->ul_epoll_spin = 1; #endif #if CI_CFG_UDP opts->udp_recv_spin = 1; opts->udp_send_spin = 1; #endif opts->tcp_recv_spin = 1; opts->tcp_send_spin = 1; opts->pkt_wait_spin = 1; opts->sock_lock_buzz = 1; opts->stack_lock_buzz = 1; } if( (s = getenv("EF_BUZZ_USEC")) && atoi(s) ) { opts->sock_lock_buzz = 1; opts->stack_lock_buzz = 1; } GET_ENV_OPT_HEX("EF_UNIX_LOG", log_level); GET_ENV_OPT_INT("EF_PROBE", probe); GET_ENV_OPT_INT("EF_TCP", ul_tcp); GET_ENV_OPT_INT("EF_UDP", ul_udp); GET_ENV_OPT_INT("EF_UL_SELECT", ul_select); GET_ENV_OPT_INT("EF_SELECT_SPIN", ul_select_spin); GET_ENV_OPT_INT("EF_SELECT_FAST", ul_select_fast); GET_ENV_OPT_INT("EF_UL_POLL", ul_poll); GET_ENV_OPT_INT("EF_POLL_SPIN", ul_poll_spin); GET_ENV_OPT_INT("EF_POLL_FAST", ul_poll_fast); GET_ENV_OPT_INT("EF_POLL_FAST_USEC", ul_poll_fast_usec); GET_ENV_OPT_INT("EF_POLL_NONBLOCK_FAST_USEC", ul_poll_nonblock_fast_usec); GET_ENV_OPT_INT("EF_SELECT_FAST_USEC", ul_select_fast_usec); GET_ENV_OPT_INT("EF_SELECT_NONBLOCK_FAST_USEC", ul_select_nonblock_fast_usec); #if CI_CFG_UDP GET_ENV_OPT_INT("EF_UDP_RECV_SPIN", udp_recv_spin); GET_ENV_OPT_INT("EF_UDP_SEND_SPIN", udp_send_spin); #endif GET_ENV_OPT_INT("EF_TCP_RECV_SPIN", tcp_recv_spin); GET_ENV_OPT_INT("EF_TCP_SEND_SPIN", tcp_send_spin); GET_ENV_OPT_INT("EF_TCP_ACCEPT_SPIN", tcp_accept_spin); GET_ENV_OPT_INT("EF_TCP_CONNECT_SPIN",tcp_connect_spin); GET_ENV_OPT_INT("EF_PKT_WAIT_SPIN", pkt_wait_spin); #if CI_CFG_USERSPACE_PIPE GET_ENV_OPT_INT("EF_PIPE_RECV_SPIN", pipe_recv_spin); GET_ENV_OPT_INT("EF_PIPE_SEND_SPIN", pipe_send_spin); GET_ENV_OPT_INT("EF_PIPE_SIZE", pipe_size); #endif GET_ENV_OPT_INT("EF_SOCK_LOCK_BUZZ", sock_lock_buzz); GET_ENV_OPT_INT("EF_STACK_LOCK_BUZZ", stack_lock_buzz); GET_ENV_OPT_INT("EF_SO_BUSY_POLL_SPIN", so_busy_poll_spin); #if CI_CFG_USERSPACE_EPOLL GET_ENV_OPT_INT("EF_UL_EPOLL", ul_epoll); if( opts->ul_epoll == 0 && ci_cfg_opts.netif_opts.int_driven == 0 ) { ci_log("EF_INT_DRIVEN=0 and EF_UL_EPOLL=0 are not compatible. " "EF_INT_DRIVEN can be set to 0 implicitly, because of non-zero " "EF_POLL_USEC. If you need both spinning and EF_UL_EPOLL=0, " "please set EF_INT_DRIVEN=1 explicitly."); } GET_ENV_OPT_INT("EF_EPOLL_SPIN", ul_epoll_spin); GET_ENV_OPT_INT("EF_EPOLL_CTL_FAST", ul_epoll_ctl_fast); GET_ENV_OPT_INT("EF_EPOLL_CTL_HANDOFF",ul_epoll_ctl_handoff); GET_ENV_OPT_INT("EF_EPOLL_MT_SAFE", ul_epoll_mt_safe); #endif GET_ENV_OPT_INT("EF_FDTABLE_SIZE", fdtable_size); GET_ENV_OPT_INT("EF_SPIN_USEC", ul_spin_usec); GET_ENV_OPT_INT("EF_STACK_PER_THREAD",stack_per_thread); GET_ENV_OPT_INT("EF_DONT_ACCELERATE", dont_accelerate); GET_ENV_OPT_INT("EF_FDTABLE_STRICT", fdtable_strict); GET_ENV_OPT_INT("EF_FDS_MT_SAFE", fds_mt_safe); GET_ENV_OPT_INT("EF_NO_FAIL", no_fail); GET_ENV_OPT_INT("EF_SA_ONSTACK_INTERCEPT", sa_onstack_intercept); GET_ENV_OPT_INT("EF_ACCEPT_INHERIT_NONBLOCK", accept_force_inherit_nonblock); GET_ENV_OPT_INT("EF_VFORK_MODE", vfork_mode); #if CI_CFG_USERSPACE_PIPE GET_ENV_OPT_INT("EF_PIPE", ul_pipe); #endif if( (s = getenv("EF_FORK_NETIF")) && sscanf(s, "%x", &v) == 1 ) { opts->fork_netif = CI_MIN(v, CI_UNIX_FORK_NETIF_BOTH); } if( (s = getenv("EF_NETIF_DTOR")) && sscanf(s, "%x", &v) == 1 ) { opts->netif_dtor = CI_MIN(v, CITP_NETIF_DTOR_ALL); } if( (s = getenv("EF_SIGNALS_NOPOSTPONE")) ) { opts->signals_no_postpone = 0; while( sscanf(s, "%u", &v) == 1 ) { opts->signals_no_postpone |= (1 << (v-1)); s = strchr(s, ','); if( s == NULL ) break; s++; } } if( (s = getenv("EF_CLUSTER_NAME")) ) { strncpy(opts->cluster_name, s, CI_CFG_CLUSTER_NAME_LEN); opts->cluster_name[CI_CFG_CLUSTER_NAME_LEN] = '\0'; } else { opts->cluster_name[0] = '\0'; } GET_ENV_OPT_INT("EF_CLUSTER_SIZE", cluster_size); if( opts->cluster_size < 2 ) log("ERROR: cluster_size < 2 are not supported"); GET_ENV_OPT_INT("EF_CLUSTER_RESTART", cluster_restart_opt); get_env_opt_port_list(&opts->tcp_reuseports, "EF_TCP_FORCE_REUSEPORT"); get_env_opt_port_list(&opts->udp_reuseports, "EF_UDP_FORCE_REUSEPORT"); #if CI_CFG_FD_CACHING get_env_opt_port_list(&opts->sock_cache_ports, "EF_SOCKET_CACHE_PORTS"); #endif }
static void citp_opts_getenv(citp_opts_t* opts) { /* ?? TODO: would like to use opts_citp_def.h here */ const char* s; unsigned v; opts->log_via_ioctl = 3; /* TODO: Old name. Keeping reading 'til 2011, then purge. */ GET_ENV_OPT_HEX("EF_Log_VIA_IOCTL", log_via_ioctl); GET_ENV_OPT_INT("EF_LOG_VIA_IOCTL", log_via_ioctl); if( (s = getenv("EF_LOG_FILE")) && opts->log_via_ioctl == 3) { opts->log_via_ioctl = 0; citp_log_to_file(s); } else if( opts->log_via_ioctl == 3 ) { /* citp_setup_logging_early() have already detected stderr as * tty/non-tty, so just trust it. */ if( ci_log_fn == citp_log_fn_drv ) opts->log_via_ioctl = 1; else opts->log_via_ioctl = 0; } if( opts->log_via_ioctl ) { ci_log_options &=~ CI_LOG_PID; citp_setup_logging_change(citp_log_fn_drv); } else { GET_ENV_OPT_INT("EF_LOG_TIMESTAMPS", log_timestamps); if( opts->log_timestamps ) ci_log_options |= CI_LOG_TIME; citp_setup_logging_change(citp_log_fn_ul); } if( getenv("EF_LOG_THREAD") ) ci_log_options |= CI_LOG_TID; if( getenv("EF_POLL_NONBLOCK_FAST_LOOPS") && ! getenv("EF_POLL_NONBLOCK_FAST_USEC") ) log("ERROR: EF_POLL_NONBLOCK_FAST_LOOPS is deprecated, use" " EF_POLL_NONBLOCK_FAST_USEC instead"); if( getenv("EF_POLL_FAST_LOOPS") && ! getenv("EF_POLL_FAST_USEC") ) log("ERROR: EF_POLL_FAST_LOOPS is deprecated, use" " EF_POLL_FAST_USEC instead"); if( (s = getenv("EF_POLL_USEC")) && atoi(s) ) { /* Any changes to the behaviour triggered by this meta * option must also be made to the extensions API option * ONLOAD_SPIN_MIMIC_EF_POLL */ GET_ENV_OPT_INT("EF_POLL_USEC", ul_spin_usec); GET_ENV_OPT_INT("EF_SLEEP_SPIN_USEC", sleep_spin_usec); opts->ul_select_spin = 1; opts->ul_poll_spin = 1; #if CI_CFG_USERSPACE_EPOLL opts->ul_epoll_spin = 1; #endif #if CI_CFG_UDP opts->udp_recv_spin = 1; opts->udp_send_spin = 1; #endif opts->tcp_recv_spin = 1; opts->tcp_send_spin = 1; opts->pkt_wait_spin = 1; opts->sock_lock_buzz = 1; opts->stack_lock_buzz = 1; } if( (s = getenv("EF_BUZZ_USEC")) && atoi(s) ) { opts->sock_lock_buzz = 1; opts->stack_lock_buzz = 1; } GET_ENV_OPT_HEX("EF_UNIX_LOG", log_level); GET_ENV_OPT_INT("EF_PROBE", probe); GET_ENV_OPT_INT("EF_TCP", ul_tcp); GET_ENV_OPT_INT("EF_UDP", ul_udp); GET_ENV_OPT_INT("EF_UL_SELECT", ul_select); GET_ENV_OPT_INT("EF_SELECT_SPIN", ul_select_spin); GET_ENV_OPT_INT("EF_SELECT_FAST", ul_select_fast); GET_ENV_OPT_INT("EF_UL_POLL", ul_poll); GET_ENV_OPT_INT("EF_POLL_SPIN", ul_poll_spin); GET_ENV_OPT_INT("EF_POLL_FAST", ul_poll_fast); GET_ENV_OPT_INT("EF_POLL_FAST_USEC", ul_poll_fast_usec); GET_ENV_OPT_INT("EF_POLL_NONBLOCK_FAST_USEC", ul_poll_nonblock_fast_usec); GET_ENV_OPT_INT("EF_SELECT_FAST_USEC", ul_select_fast_usec); GET_ENV_OPT_INT("EF_SELECT_NONBLOCK_FAST_USEC", ul_select_nonblock_fast_usec); #if CI_CFG_UDP GET_ENV_OPT_INT("EF_UDP_RECV_SPIN", udp_recv_spin); GET_ENV_OPT_INT("EF_UDP_SEND_SPIN", udp_send_spin); #endif GET_ENV_OPT_INT("EF_TCP_RECV_SPIN", tcp_recv_spin); GET_ENV_OPT_INT("EF_TCP_SEND_SPIN", tcp_send_spin); GET_ENV_OPT_INT("EF_TCP_ACCEPT_SPIN", tcp_accept_spin); GET_ENV_OPT_INT("EF_TCP_CONNECT_SPIN",tcp_connect_spin); GET_ENV_OPT_INT("EF_PKT_WAIT_SPIN", pkt_wait_spin); #if CI_CFG_USERSPACE_PIPE GET_ENV_OPT_INT("EF_PIPE_RECV_SPIN", pipe_recv_spin); GET_ENV_OPT_INT("EF_PIPE_SEND_SPIN", pipe_send_spin); GET_ENV_OPT_INT("EF_PIPE_SIZE", pipe_size); #endif GET_ENV_OPT_INT("EF_SOCK_LOCK_BUZZ", sock_lock_buzz); GET_ENV_OPT_INT("EF_STACK_LOCK_BUZZ", stack_lock_buzz); GET_ENV_OPT_INT("EF_SO_BUSY_POLL_SPIN", so_busy_poll_spin); #if CI_CFG_USERSPACE_EPOLL GET_ENV_OPT_INT("EF_UL_EPOLL", ul_epoll); GET_ENV_OPT_INT("EF_EPOLL_SPIN", ul_epoll_spin); GET_ENV_OPT_INT("EF_EPOLL_CTL_FAST", ul_epoll_ctl_fast); GET_ENV_OPT_INT("EF_EPOLL_CTL_HANDOFF",ul_epoll_ctl_handoff); GET_ENV_OPT_INT("EF_EPOLL_MT_SAFE", ul_epoll_mt_safe); GET_ENV_OPT_INT("EF_WODA_SINGLE_INTERFACE", woda_single_if); #endif GET_ENV_OPT_INT("EF_FDTABLE_SIZE", fdtable_size); GET_ENV_OPT_INT("EF_SPIN_USEC", ul_spin_usec); GET_ENV_OPT_INT("EF_SLEEP_SPIN_USEC", sleep_spin_usec); GET_ENV_OPT_INT("EF_STACK_PER_THREAD",stack_per_thread); GET_ENV_OPT_INT("EF_DONT_ACCELERATE", dont_accelerate); GET_ENV_OPT_INT("EF_FDTABLE_STRICT", fdtable_strict); GET_ENV_OPT_INT("EF_FDS_MT_SAFE", fds_mt_safe); GET_ENV_OPT_INT("EF_NO_FAIL", no_fail); GET_ENV_OPT_INT("EF_SA_ONSTACK_INTERCEPT", sa_onstack_intercept); GET_ENV_OPT_INT("EF_ACCEPT_INHERIT_NONBLOCK", accept_force_inherit_nonblock); GET_ENV_OPT_INT("EF_VFORK_MODE", vfork_mode); #if CI_CFG_USERSPACE_PIPE GET_ENV_OPT_INT("EF_PIPE", ul_pipe); #endif GET_ENV_OPT_INT("EF_SYNC_CPLANE_AT_CREATE", sync_cplane); if( (s = getenv("EF_FORK_NETIF")) && sscanf(s, "%x", &v) == 1 ) { opts->fork_netif = CI_MIN(v, CI_UNIX_FORK_NETIF_BOTH); } if( (s = getenv("EF_NETIF_DTOR")) && sscanf(s, "%x", &v) == 1 ) { opts->netif_dtor = CI_MIN(v, CITP_NETIF_DTOR_ALL); } if( (s = getenv("EF_SIGNALS_NOPOSTPONE")) ) { opts->signals_no_postpone = 0; while( sscanf(s, "%u", &v) == 1 ) { opts->signals_no_postpone |= (1 << (v-1)); s = strchr(s, ','); if( s == NULL ) break; s++; } } if( (s = getenv("EF_CLUSTER_NAME")) ) { strncpy(opts->cluster_name, s, CI_CFG_CLUSTER_NAME_LEN); opts->cluster_name[CI_CFG_CLUSTER_NAME_LEN] = '\0'; } else { opts->cluster_name[0] = '\0'; } GET_ENV_OPT_INT("EF_CLUSTER_SIZE", cluster_size); if( opts->cluster_size < 1 ) log("ERROR: cluster_size needs to be a positive number"); GET_ENV_OPT_INT("EF_CLUSTER_RESTART", cluster_restart_opt); GET_ENV_OPT_INT("EF_CLUSTER_HOT_RESTART", cluster_hot_restart_opt); get_env_opt_port_list(&opts->tcp_reuseports, "EF_TCP_FORCE_REUSEPORT"); get_env_opt_port_list(&opts->udp_reuseports, "EF_UDP_FORCE_REUSEPORT"); #if CI_CFG_FD_CACHING get_env_opt_port_list(&opts->sock_cache_ports, "EF_SOCKET_CACHE_PORTS"); #endif GET_ENV_OPT_INT("EF_ONLOAD_FD_BASE", fd_base); }