Browse Source

[multiple] stat_cache_path_stat() for struct st

stat_cache_path_stat() for cached (struct st *)
master
Glenn Strauss 3 months ago
parent
commit
fe02111888
7 changed files with 27 additions and 25 deletions
  1. +4
    -9
      src/mod_cgi.c
  2. +3
    -3
      src/mod_expire.c
  3. +1
    -2
      src/mod_indexfile.c
  4. +2
    -2
      src/mod_rewrite.c
  5. +9
    -9
      src/response.c
  6. +5
    -0
      src/stat_cache.c
  7. +3
    -0
      src/stat_cache.h

+ 4
- 9
src/mod_cgi.c View File

@ -747,12 +747,6 @@ static int cgi_write_request(handler_ctx *hctx, int fd) {
return 0;
}
static const struct stat * cgi_stat(buffer *path) {
/* CGI might be executable even if it is not readable */
const stat_cache_entry * const sce = stat_cache_get_entry(path);
return sce ? &sce->st : NULL;
}
static int cgi_create_env(request_st * const r, plugin_data * const p, handler_ctx * const hctx, buffer * const cgi_handler) {
char *args[3];
int to_cgi_fds[2];
@ -761,7 +755,7 @@ static int cgi_create_env(request_st * const r, plugin_data * const p, handler_c
UNUSED(p);
if (!buffer_string_is_empty(cgi_handler)) {
if (NULL == cgi_stat(cgi_handler)) {
if (NULL == stat_cache_path_stat(cgi_handler)) {
log_perror(r->conf.errh, __FILE__, __LINE__,
"stat for cgi-handler %s", cgi_handler->ptr);
return -1;
@ -887,7 +881,7 @@ static int cgi_create_env(request_st * const r, plugin_data * const p, handler_c
URIHANDLER_FUNC(cgi_is_handled) {
plugin_data *p = p_d;
const struct stat *st;
const stat_cache_st *st;
data_string *ds;
if (NULL != r->handler_module) return HANDLER_GO_ON;
@ -899,9 +893,10 @@ URIHANDLER_FUNC(cgi_is_handled) {
ds = (data_string *)array_match_key_suffix(p->conf.cgi, &r->physical.path);
if (NULL == ds) return HANDLER_GO_ON;
st = cgi_stat(&r->physical.path);
st = stat_cache_path_stat(&r->physical.path);
if (NULL == st) return HANDLER_GO_ON;
/* (aside: CGI might be executable even if it is not readable) */
if (!S_ISREG(st->st_mode)) return HANDLER_GO_ON;
if (p->conf.execute_x_only == 1 && (st->st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) == 0) return HANDLER_GO_ON;


+ 3
- 3
src/mod_expire.c View File

@ -304,10 +304,10 @@ REQUEST_FUNC(mod_expire_handler) {
expires += cur_ts;
}
else { /* modification */
stat_cache_entry *sce = stat_cache_get_entry(&r->physical.path);
const stat_cache_st * const st = stat_cache_path_stat(&r->physical.path);
/* can't set modification-based expire if mtime is not available */
if (NULL == sce) return HANDLER_GO_ON;
expires += sce->st.st_mtime;
if (NULL == st) return HANDLER_GO_ON;
expires += st->st_mtime;
}
/* expires should be at least cur_ts */


+ 1
- 2
src/mod_indexfile.c View File

@ -113,8 +113,7 @@ URIHANDLER_FUNC(mod_indexfile_subrequest) {
}
buffer_append_string_buffer(b, &ds->value);
stat_cache_entry * const sce = stat_cache_get_entry(b);
if (NULL == sce) {
if (NULL == stat_cache_path_stat(b)) {
if (errno == EACCES) {
r->http_status = 403;
buffer_reset(&r->physical.path);


+ 2
- 2
src/mod_rewrite.c View File

@ -323,8 +323,8 @@ URIHANDLER_FUNC(mod_rewrite_physical) {
if (!p->conf.rewrite_NF || !p->conf.rewrite_NF->used) return HANDLER_GO_ON;
/* skip if physical.path is a regular file */
stat_cache_entry *sce = stat_cache_get_entry(&r->physical.path);
if (sce && S_ISREG(sce->st.st_mode)) return HANDLER_GO_ON;
const stat_cache_st * const st = stat_cache_path_stat(&r->physical.path);
if (st && S_ISREG(st->st_mode)) return HANDLER_GO_ON;
return process_rewrite_rules(r, p, p->conf.rewrite_NF);
}


+ 9
- 9
src/response.c View File

@ -174,9 +174,9 @@ http_response_write_header (request_st * const r)
static handler_t http_response_physical_path_check(request_st * const r) {
stat_cache_entry *sce = stat_cache_get_entry(&r->physical.path);
const stat_cache_st *st = stat_cache_path_stat(&r->physical.path);
if (sce) {
if (st) {
/* file exists */
} else {
char *pathinfo = NULL;
@ -246,16 +246,16 @@ static handler_t http_response_physical_path_check(request_st * const r) {
buffer * const tb = r->tmp_buf;
for (char *pprev = pathinfo; pathinfo; pprev = pathinfo, pathinfo = strchr(pathinfo+1, '/')) {
buffer_copy_string_len(tb, r->physical.path.ptr, pathinfo - r->physical.path.ptr);
stat_cache_entry *nsce = stat_cache_get_entry(tb);
if (NULL == nsce) {
const stat_cache_st * const nst = stat_cache_path_stat(tb);
if (NULL == nst) {
pathinfo = pathinfo != pprev ? pprev : NULL;
break;
}
sce = nsce;
if (!S_ISDIR(sce->st.st_mode)) break;
st = nst;
if (!S_ISDIR(st->st_mode)) break;
}
if (NULL == pathinfo || !S_ISREG(sce->st.st_mode)) {
if (NULL == pathinfo || !S_ISREG(st->st_mode)) {
/* no it really doesn't exists */
r->http_status = 404;
@ -309,10 +309,10 @@ static handler_t http_response_physical_path_check(request_st * const r) {
return HANDLER_FINISHED;
}
if (S_ISREG(sce->st.st_mode)) /*(common case)*/
if (S_ISREG(st->st_mode)) /*(common case)*/
return HANDLER_GO_ON;
if (S_ISDIR(sce->st.st_mode)) {
if (S_ISDIR(st->st_mode)) {
if (r->uri.path.ptr[buffer_string_length(&r->uri.path) - 1] != '/') {
/* redirect to .../ */


+ 5
- 0
src/stat_cache.c View File

@ -1090,6 +1090,11 @@ stat_cache_entry * stat_cache_get_entry_open(const buffer * const name, const in
return sce; /* (note: sce->fd might still be -1 if open() failed) */
}
const stat_cache_st * stat_cache_path_stat (const buffer * const name) {
const stat_cache_entry * const sce = stat_cache_get_entry(name);
return sce ? &sce->st : NULL;
}
int stat_cache_path_isdir(const buffer *name) {
const stat_cache_entry * const sce = stat_cache_get_entry(name);
return (sce && (S_ISDIR(sce->st.st_mode) ? 1 : (errno = ENOTDIR, 0)));


+ 3
- 0
src/stat_cache.h View File

@ -10,6 +10,8 @@
#include <sys/time.h>
#include <sys/stat.h>
typedef struct stat stat_cache_st;
typedef struct {
buffer name;
time_t stat_ts;
@ -52,6 +54,7 @@ void stat_cache_delete_dir(const char *name, uint32_t len);
void stat_cache_invalidate_entry(const char *name, uint32_t len);
stat_cache_entry * stat_cache_get_entry(const buffer *name);
stat_cache_entry * stat_cache_get_entry_open(const buffer *name, int symlinks);
const stat_cache_st * stat_cache_path_stat(const buffer *name);
int stat_cache_path_isdir(const buffer *name);
__attribute_cold__


Loading…
Cancel
Save