src/ngx_pagespeed.cc
// called after configuration is complete, but before nginx starts forking
called after configuration is complete, but before nginx starts forking
called after configuration is complete but before nginx starts forking
ngx_int_t ps_init_module(ngx_cycle_t* cycle) {
  ps_main_conf_t* cfg_m = static_cast<ps_main_conf_t*>(
      ngx_http_cycle_get_module_main_conf(cycle, ngx_pagespeed));
  if (cfg_m == NULL) {
    return NGX_OK;
  }
  ngx_http_core_main_conf_t* cmcf = static_cast<ngx_http_core_main_conf_t*>(
      ngx_http_cycle_get_module_main_conf(cycle, ngx_http_core_module));
  ngx_http_core_srv_conf_t** cscfp = static_cast<ngx_http_core_srv_conf_t**>(
      cmcf->servers.elts);
  ngx_uint_t s;
  std::vector<SystemServerContext*> server_contexts;
  for (s = 0; s < cmcf->servers.nelts; s++) {
    ps_srv_conf_t* cfg_s = static_cast<ps_srv_conf_t*>(
        cscfp[s]->ctx->srv_conf[ngx_pagespeed.ctx_index]);
    if (cfg_s->server_context != NULL) {
      server_contexts.push_back(cfg_s->server_context);
    }
  }
  GoogleString error_message;
  int error_index = -1;
  Statistics* global_statistics = NULL;
  cfg_m->driver_factory->PostConfig(
      server_contexts, &error_message, &error_index, &global_statistics);
  if (error_index != -1) {
    server_contexts[error_index]->message_handler()->Message(
        kError, "ngx_pagespeed is enabled. %s", error_message.c_str());
    return NGX_ERROR;
  }
  if (!server_contexts.empty()) {
    ps_ignore_sigpipe();
    if (global_statistics == NULL) {
      NgxRewriteDriverFactory::InitStats(cfg_m->driver_factory->statistics());
    }
    ngx_http_core_loc_conf_t* clcf = static_cast<ngx_http_core_loc_conf_t*>(
        ngx_http_conf_get_module_loc_conf((*cscfp), ngx_http_core_module));
    cfg_m->driver_factory->set_resolver(clcf->resolver);
    cfg_m->driver_factory->set_resolver_timeout(clcf->resolver_timeout);
    if (!cfg_m->driver_factory->CheckResolver()) {
      cfg_m->handler->Message(
          kError,
          "UseNativeFetcher is on, please configure a resolver.");
      return NGX_ERROR;
    }
    cfg_m->driver_factory->LoggingInit(cycle->log, true);
    cfg_m->driver_factory->RootInit();
  } else {
    delete cfg_m->driver_factory;
    cfg_m->driver_factory = NULL;
    active_driver_factory = NULL;
  }
  return NGX_OK;
}
ngx_int_t ps_init_module ( ngx_cycle_t * cycle ) { ps_main_conf_t * cfg_m = static_cast < ps_main_conf_t * > ( ngx_http_cycle_get_module_main_conf ( cycle , ngx_pagespeed ) ) ; if ( cfg_m == NULL ) { return NGX_OK ; } ngx_http_core_main_conf_t * cmcf = static_cast < ngx_http_core_main_conf_t * > ( ngx_http_cycle_get_module_main_conf ( cycle , ngx_http_core_module ) ) ; ngx_http_core_srv_conf_t * * cscfp = static_cast < ngx_http_core_srv_conf_t * * > ( cmcf -> servers . elts ) ; ngx_uint_t s ; std :: vector < SystemServerContext * > server_contexts ; for ( s = 0 ; s < cmcf -> servers . nelts ; s ++ ) { ps_srv_conf_t * cfg_s = static_cast < ps_srv_conf_t * > ( cscfp [ s ] -> ctx -> srv_conf [ ngx_pagespeed . ctx_index ] ) ; if ( cfg_s -> server_context != NULL ) { server_contexts . push_back ( cfg_s -> server_context ) ; } } GoogleString error_message ; int error_index = -1 ; Statistics * global_statistics = NULL ; cfg_m -> driver_factory -> PostConfig ( server_contexts , & error_message , & error_index , & global_statistics ) ; if ( error_index != -1 ) { server_contexts [ error_index ] -> message_handler ( ) -> Message ( kError , " " , error_message . c_str ( ) ) ; return NGX_ERROR ; } if ( ! server_contexts . empty ( ) ) { ps_ignore_sigpipe ( ) ; if ( global_statistics == NULL ) { NgxRewriteDriverFactory :: InitStats ( cfg_m -> driver_factory -> statistics ( ) ) ; } ngx_http_core_loc_conf_t * clcf = static_cast < ngx_http_core_loc_conf_t * > ( ngx_http_conf_get_module_loc_conf ( ( * cscfp ) , ngx_http_core_module ) ) ; cfg_m -> driver_factory -> set_resolver ( clcf -> resolver ) ; cfg_m -> driver_factory -> set_resolver_timeout ( clcf -> resolver_timeout ) ; if ( ! cfg_m -> driver_factory -> CheckResolver ( ) ) { cfg_m -> handler -> Message ( kError , " " ) ; return NGX_ERROR ; } cfg_m -> driver_factory -> LoggingInit ( cycle -> log , true ) ; cfg_m -> driver_factory -> RootInit ( ) ; } else { delete cfg_m -> driver_factory ; cfg_m -> driver_factory = NULL ; active_driver_factory = NULL ; } return NGX_OK ; }
called after configuration is complete, but before nginx starts forking
called after configuration is complete but before nginx starts forking
// See https://github.com/apache/incubator-pagespeed-ngx/issues/1220 // Iterate over all configured server{} blocks to collect the server contexts. // TODO(oschaaf): this ignores sigpipe messages from memcached. // however, it would be better to not have those signals generated // in the first place, as suppressing them this way may interfere // with other modules that actually are interested in these signals // If no shared-mem statistics are enabled, then init using the default // NullStatistics.