static GObject * mate_rr_labeler_constructor (GType type, guint n_construct_properties, GObjectConstructParam *construct_properties) { MateRRLabeler *self = (MateRRLabeler*) G_OBJECT_CLASS (mate_rr_labeler_parent_class)->constructor (type, n_construct_properties, construct_properties); setup_from_config (self); return (GObject*) self; }
void lwan_init(lwan_t *l) { int max_threads = sysconf(_SC_NPROCESSORS_ONLN); struct rlimit r; /* Load defaults */ memcpy(&l->config, &default_config, sizeof(default_config)); /* Initialize status first, as it is used by other things during * their initialization. */ lwan_status_init(l); /* These will only print debugging messages. Debug messages are always * printed if we're on a debug build, so the quiet setting will be * respected. */ lwan_job_thread_init(); lwan_response_init(); lwan_tables_init(); /* Load the configuration file. */ if (!setup_from_config(l)) lwan_status_warning("Could not read config file, using defaults"); /* Continue initialization as normal. */ lwan_status_debug("Initializing lwan web server"); l->thread.count = max_threads > 0 ? max_threads : 2; if (getrlimit(RLIMIT_NOFILE, &r) < 0) lwan_status_critical_perror("getrlimit"); if (r.rlim_max == RLIM_INFINITY) r.rlim_cur *= 8; else if (r.rlim_cur < r.rlim_max) r.rlim_cur = r.rlim_max; if (setrlimit(RLIMIT_NOFILE, &r) < 0) lwan_status_critical_perror("setrlimit"); l->conns = calloc(r.rlim_cur, sizeof(lwan_connection_t)); l->thread.max_fd = r.rlim_cur / l->thread.count; lwan_status_info("Using %d threads, maximum %d sockets per thread", l->thread.count, l->thread.max_fd); for (--r.rlim_cur; r.rlim_cur; --r.rlim_cur) l->conns[r.rlim_cur].response_buffer = strbuf_new(); srand(time(NULL)); signal(SIGPIPE, SIG_IGN); close(STDIN_FILENO); lwan_thread_init(l); lwan_socket_init(l); lwan_http_authorize_init(); }
void lwan_init_with_config(lwan_t *l, const lwan_config_t *config) { /* Load defaults */ memset(l, 0, sizeof(*l)); memcpy(&l->config, config, sizeof(*config)); /* Initialize status first, as it is used by other things during * their initialization. */ lwan_status_init(l); /* These will only print debugging messages. Debug messages are always * printed if we're on a debug build, so the quiet setting will be * respected. */ lwan_job_thread_init(); lwan_tables_init(); lwan_module_init(l); /* Load the configuration file. */ if (config == &default_config) { if (!setup_from_config(l)) lwan_status_warning("Could not read config file, using defaults"); /* `quiet` key might have changed value. */ lwan_status_init(l); } lwan_response_init(l); /* Continue initialization as normal. */ lwan_status_debug("Initializing lwan web server"); if (!l->config.n_threads) { l->thread.count = get_number_of_cpus(); if (l->thread.count == 1) l->thread.count = 2; } else { l->thread.count = l->config.n_threads; } rlim_t max_open_files = setup_open_file_count_limits(); allocate_connections(l, (size_t)max_open_files); l->thread.max_fd = (unsigned)max_open_files / (unsigned)l->thread.count; lwan_status_info("Using %d threads, maximum %d sockets per thread", l->thread.count, l->thread.max_fd); signal(SIGPIPE, SIG_IGN); lwan_thread_init(l); lwan_socket_init(l); lwan_http_authorize_init(); }
static void try_setup_from_config(struct lwan *l, const struct lwan_config *config) { if (!setup_from_config(l, config->config_file_path)) { if (config->config_file_path) { lwan_status_critical("Could not read config file: %s", config->config_file_path); } } /* `quiet` key might have changed value. */ lwan_status_init(l); }