diff --git a/src/base.h b/src/base.h index c7e9dd21..fb2fd8ab 100644 --- a/src/base.h +++ b/src/base.h @@ -23,14 +23,10 @@ #include "chunk.h" #include "keyvalue.h" #include "sys-socket.h" -#include "splaytree.h" #include "etag.h" struct fdevents; /* declaration */ - -#ifdef HAVE_FAM_H -# include -#endif +struct stat_cache; /* declaration */ #ifndef O_BINARY # define O_BINARY 0 @@ -219,19 +215,6 @@ typedef struct { buffer *content_type; } stat_cache_entry; -typedef struct { - splay_tree *files; /* the nodes of the tree are stat_cache_entry's */ - - buffer *dir_name; /* for building the dirname from the filename */ -#ifdef HAVE_FAM_H - splay_tree *dirs; /* the nodes of the tree are fam_dir_entry */ - - FAMConnection fam; - int fam_fcce_ndx; -#endif - buffer *hash_key; /* temp-store for the hash-key */ -} stat_cache; - typedef struct { array *mimetypes; @@ -611,7 +594,7 @@ typedef struct server { connections *joblist; connections *fdwaitqueue; - stat_cache *stat_cache; + struct stat_cache *stat_cache; /** * The status array can carry all the status information you want diff --git a/src/server.c b/src/server.c index 71f67ab9..fb5412e8 100644 --- a/src/server.c +++ b/src/server.c @@ -1469,30 +1469,12 @@ static int server_main (server * const srv, int argc, char **argv) { } /* might fail if user is using fam (not gamin) and famd isn't running */ - if (NULL == (srv->stat_cache = stat_cache_init())) { + if (NULL == (srv->stat_cache = stat_cache_init(srv))) { log_error_write(srv, __FILE__, __LINE__, "s", "stat-cache could not be setup, dieing."); return -1; } -#ifdef HAVE_FAM_H - /* setup FAM */ - if (srv->srvconf.stat_cache_engine == STAT_CACHE_ENGINE_FAM) { - if (0 != FAMOpen2(&srv->stat_cache->fam, "lighttpd")) { - log_error_write(srv, __FILE__, __LINE__, "s", - "could not open a fam connection, dieing."); - return -1; - } -#ifdef HAVE_FAMNOEXISTS - FAMNoExists(&srv->stat_cache->fam); -#endif - - fd_close_on_exec(FAMCONNECTION_GETFD(&srv->stat_cache->fam)); - fdevent_register(srv->ev, FAMCONNECTION_GETFD(&srv->stat_cache->fam), stat_cache_handle_fdevent, NULL); - fdevent_event_set(srv->ev, &(srv->stat_cache->fam_fcce_ndx), FAMCONNECTION_GETFD(&srv->stat_cache->fam), FDEVENT_IN); - } -#endif - #ifdef USE_ALARM { /* setup periodic timer (1 second) */ diff --git a/src/stat_cache.c b/src/stat_cache.c index 8e4468d1..48a38c5a 100644 --- a/src/stat_cache.c +++ b/src/stat_cache.c @@ -4,6 +4,7 @@ #include "stat_cache.h" #include "fdevent.h" #include "etag.h" +#include "splaytree.h" #include #include @@ -93,7 +94,22 @@ typedef struct { static fake_keys ctrl; #endif -stat_cache *stat_cache_init(void) { +typedef struct stat_cache { + splay_tree *files; /* the nodes of the tree are stat_cache_entry's */ + + buffer *dir_name; /* for building the dirname from the filename */ +#ifdef HAVE_FAM_H + splay_tree *dirs; /* the nodes of the tree are fam_dir_entry */ + + FAMConnection fam; + int fam_fcce_ndx; +#endif + buffer *hash_key; /* temp-store for the hash-key */ +} stat_cache; + +static handler_t stat_cache_handle_fdevent(server *srv, void *_fce, int revent); + +stat_cache *stat_cache_init(server *srv) { stat_cache *sc = NULL; sc = calloc(1, sizeof(*sc)); @@ -110,6 +126,24 @@ stat_cache *stat_cache_init(void) { ctrl.size = 0; #endif +#ifdef HAVE_FAM_H + /* setup FAM */ + if (srv->srvconf.stat_cache_engine == STAT_CACHE_ENGINE_FAM) { + if (0 != FAMOpen2(&srv->stat_cache->fam, "lighttpd")) { + log_error_write(srv, __FILE__, __LINE__, "s", + "could not open a fam connection, dieing."); + return NULL; + } +#ifdef HAVE_FAMNOEXISTS + FAMNoExists(&srv->stat_cache->fam); +#endif + + fd_close_on_exec(FAMCONNECTION_GETFD(&srv->stat_cache->fam)); + fdevent_register(srv->ev, FAMCONNECTION_GETFD(&srv->stat_cache->fam), stat_cache_handle_fdevent, NULL); + fdevent_event_set(srv->ev, &(srv->stat_cache->fam_fcce_ndx), FAMCONNECTION_GETFD(&srv->stat_cache->fam), FDEVENT_IN); + } +#endif + return sc; } @@ -247,7 +281,7 @@ static uint32_t hashme(buffer *str) { } #ifdef HAVE_FAM_H -handler_t stat_cache_handle_fdevent(server *srv, void *_fce, int revent) { +static handler_t stat_cache_handle_fdevent(server *srv, void *_fce, int revent) { size_t i; stat_cache *sc = srv->stat_cache; size_t events; diff --git a/src/stat_cache.h b/src/stat_cache.h index 72c61f4d..8610fa9b 100644 --- a/src/stat_cache.h +++ b/src/stat_cache.h @@ -4,11 +4,12 @@ #include "base.h" -stat_cache *stat_cache_init(void); -void stat_cache_free(stat_cache *fc); +struct stat_cache; /* declaration */ + +struct stat_cache *stat_cache_init(server *srv); +void stat_cache_free(struct stat_cache *fc); handler_t stat_cache_get_entry(server *srv, connection *con, buffer *name, stat_cache_entry **fce); -handler_t stat_cache_handle_fdevent(server *srv, void *_fce, int revent); int stat_cache_open_rdonly_fstat (server *srv, connection *con, buffer *name, struct stat *st); int stat_cache_trigger_cleanup(server *srv);