src/ngx_pagespeed.cc
// Given a directory path that pagespeed needs, create it and set permissions so
// the worker can access, but only if needed.
Given a directory path that pagespeed needs, create it and set permissions so
the worker can access, but only if needed.
Given a directory path that pagespeed needs create it and set permissions so the worker can access but only if needed .
char* ps_init_dir(const StringPiece& directive,
                  const StringPiece& path,
                  ngx_conf_t* cf) {
  if (path.size() == 0 || path[0] != '/') {
    return string_piece_to_pool_string(
        cf->pool, net_instaweb::StrCat(directive, " ", path,
                                       " must start with a slash"));
  }
  net_instaweb::StdioFileSystem file_system;
  net_instaweb::NullMessageHandler message_handler;
  GoogleString gs_path;
  path.CopyToString(&gs_path);
  if (!file_system.IsDir(gs_path.c_str(), &message_handler).is_true()) {
    if (!file_system.RecursivelyMakeDir(path, &message_handler)) {
      return string_piece_to_pool_string(
          cf->pool, net_instaweb::StrCat(
              directive, " path ", path,
              " does not exist and could not be created."));
    }
  }
  if (geteuid() != 0) {
    return NULL;  
  }
  ngx_core_conf_t* ccf = reinterpret_cast<ngx_core_conf_t*>(
      ngx_get_conf(cf->cycle->conf_ctx, ngx_core_module));
  CHECK(ccf != NULL);
  struct stat gs_stat;
  if (stat(gs_path.c_str(), &gs_stat) != 0) {
    return string_piece_to_pool_string(
        cf->pool, net_instaweb::StrCat(
            directive, " ", path, " stat() failed"));
  }
  if (gs_stat.st_uid != ccf->user) {
    if (chown(gs_path.c_str(), ccf->user, ccf->group) != 0) {
      return string_piece_to_pool_string(
          cf->pool, net_instaweb::StrCat(
              directive, " ", path, " unable to set permissions"));
    }
  }
  return NULL;
}
char * ps_init_dir ( const StringPiece & directive , const StringPiece & path , ngx_conf_t * cf ) { if ( path . size ( ) == 0 || path [ 0 ] != ' ' ) { return string_piece_to_pool_string ( cf -> pool , net_instaweb :: StrCat ( directive , " " , path , " " ) ) ; } net_instaweb :: StdioFileSystem file_system ; net_instaweb :: NullMessageHandler message_handler ; GoogleString gs_path ; path . CopyToString ( & gs_path ) ; if ( ! file_system . IsDir ( gs_path . c_str ( ) , & message_handler ) . is_true ( ) ) { if ( ! file_system . RecursivelyMakeDir ( path , & message_handler ) ) { return string_piece_to_pool_string ( cf -> pool , net_instaweb :: StrCat ( directive , " " , path , " " ) ) ; } } if ( geteuid ( ) != 0 ) { return NULL ; } ngx_core_conf_t * ccf = reinterpret_cast < ngx_core_conf_t * > ( ngx_get_conf ( cf -> cycle -> conf_ctx , ngx_core_module ) ) ; CHECK ( ccf != NULL ) ; struct stat gs_stat ; if ( stat ( gs_path . c_str ( ) , & gs_stat ) != 0 ) { return string_piece_to_pool_string ( cf -> pool , net_instaweb :: StrCat ( directive , " " , path , " " ) ) ; } if ( gs_stat . st_uid != ccf -> user ) { if ( chown ( gs_path . c_str ( ) , ccf -> user , ccf -> group ) != 0 ) { return string_piece_to_pool_string ( cf -> pool , net_instaweb :: StrCat ( directive , " " , path , " " ) ) ; } } return NULL ; }
Given a directory path that pagespeed needs, create it and set permissions so
the worker can access, but only if needed.
Given a directory path that pagespeed needs create it and set permissions so the worker can access but only if needed .
// Directory created, but may not be readable by the worker processes. // We're not root, so we're staying whoever we are. // chown if owner differs from nginx worker user.