commit - aea518b5677939b97a7c9068389ec98a00dc0ffc
commit + ab5bda7ecb7748b16898b3af71948dc94ce96296
blob - bade32d3e29cece20e0d29c794fa2278089c97d1
blob + 479f4639051bdda4d60bc7cf7e8a2684fffb6429
--- gotwebd/config.c
+++ gotwebd/config.c
IMSG_SIZE_CHECK(imsg, srv);
memcpy(srv, p, sizeof(*srv));
- srv->cached_repos = calloc(GOTWEBD_REPO_CACHESIZE,
- sizeof(*srv->cached_repos));
- if (srv->cached_repos == NULL)
- fatal("%s: calloc", __func__);
- srv->ncached_repos = 0;
/* log server info */
log_debug("%s: server=%s fcgi_socket=%s unix_socket=%s", __func__,
blob - 3e8466064873d75e20e680212e5b1f24acd7893d
blob + 4c1f36d7b4c7b61ced5a157bdb8e09d7f51b4636
--- gotwebd/gotweb.c
+++ gotwebd/gotweb.c
free(t->repos[i]);
free(t->repos);
}
+ if (t->repo)
+ got_repo_close(t->repo);
free(t);
}
r = gotweb_render_repo_fragment(c->tp, repo_dir);
gotweb_free_repo_dir(repo_dir);
+ repo_dir = NULL;
+ got_repo_close(t->repo);
+ t->repo = NULL;
if (r == -1)
return -1;
return -1;
return gotweb_render_url(c, url);
-}
-
-static struct got_repository *
-find_cached_repo(struct server *srv, const char *path)
-{
- int i;
-
- for (i = 0; i < srv->ncached_repos; i++) {
- if (strcmp(srv->cached_repos[i].path, path) == 0)
- return srv->cached_repos[i].repo;
- }
-
- return NULL;
}
static const struct got_error *
-cache_repo(struct got_repository **new, struct server *srv,
- struct repo_dir *repo_dir, struct socket *sock)
-{
- const struct got_error *error = NULL;
- struct got_repository *repo;
- struct cached_repo *cr;
- int evicted = 0;
-
- if (srv->ncached_repos >= GOTWEBD_REPO_CACHESIZE) {
- cr = &srv->cached_repos[srv->ncached_repos - 1];
- error = got_repo_close(cr->repo);
- memset(cr, 0, sizeof(*cr));
- srv->ncached_repos--;
- if (error)
- return error;
- memmove(&srv->cached_repos[1], &srv->cached_repos[0],
- srv->ncached_repos * sizeof(srv->cached_repos[0]));
- cr = &srv->cached_repos[0];
- evicted = 1;
- } else {
- cr = &srv->cached_repos[srv->ncached_repos];
- }
-
- error = got_repo_open(&repo, repo_dir->path, NULL, sock->pack_fds);
- if (error) {
- if (evicted) {
- memmove(&srv->cached_repos[0], &srv->cached_repos[1],
- srv->ncached_repos * sizeof(srv->cached_repos[0]));
- }
- return error;
- }
-
- if (strlcpy(cr->path, repo_dir->path, sizeof(cr->path))
- >= sizeof(cr->path)) {
- if (evicted) {
- memmove(&srv->cached_repos[0], &srv->cached_repos[1],
- srv->ncached_repos * sizeof(srv->cached_repos[0]));
- }
- return got_error(GOT_ERR_NO_SPACE);
- }
-
- cr->repo = repo;
- srv->ncached_repos++;
- *new = repo;
- return NULL;
-}
-
-static const struct got_error *
gotweb_load_got_path(struct request *c, struct repo_dir *repo_dir)
{
const struct got_error *error = NULL;
struct socket *sock = c->sock;
struct server *srv = c->srv;
struct transport *t = c->t;
- struct got_repository *repo = NULL;
DIR *dt;
char *dir_test;
} else {
repo_dir->path = dir_test;
dir_test = NULL;
- goto done;
+ goto open_repo;
}
if (asprintf(&dir_test, "%s/%s", srv->repos_path,
- repo_dir->name) == -1)
- return got_error_from_errno("asprintf");
+ repo_dir->name) == -1) {
+ error = got_error_from_errno("asprintf");
+ goto err;
+ }
dt = opendir(dir_test);
if (dt == NULL) {
dir_test = NULL;
}
-done:
+open_repo:
if (srv->respect_exportok &&
faccessat(dirfd(dt), "git-daemon-export-ok", F_OK, 0) == -1) {
error = got_error_path(repo_dir->name, GOT_ERR_NOT_GIT_REPO);
goto err;
}
- repo = find_cached_repo(srv, repo_dir->path);
- if (repo == NULL) {
- error = cache_repo(&repo, srv, repo_dir, sock);
- if (error)
- goto err;
- }
- t->repo = repo;
+ error = got_repo_open(&t->repo, repo_dir->path, NULL, sock->pack_fds);
+ if (error)
+ goto err;
error = gotweb_get_repo_description(&repo_dir->description, srv,
repo_dir->path, dirfd(dt));
if (error)
free(dir_test);
if (dt != NULL && closedir(dt) == EOF && error == NULL)
error = got_error_from_errno("closedir");
+ if (error && t->repo) {
+ got_repo_close(t->repo);
+ t->repo = NULL;
+ }
return error;
}
blob - bb9f162ecc3b44d973ee60be9445e234cd5f9986
blob + b1ce8d623d39d6ff2faaf210c67f7020e0d4dda5
--- gotwebd/gotwebd.h
+++ gotwebd/gotwebd.h
#define GOTWEBD_MAXNAME 64
#define GOTWEBD_MAXPORT 6
#define GOTWEBD_NUMPROC 3
-#define GOTWEBD_REPO_CACHESIZE 4
#define GOTWEBD_SOCK_FILENO 3
#define PROC_MAX_INSTANCES 32
};
TAILQ_HEAD(addresslist, address);
-struct cached_repo {
- char path[PATH_MAX];
- struct got_repository *repo;
-};
-
struct server {
TAILQ_ENTRY(server) entry;
struct addresslist al;
-
- struct cached_repo *cached_repos;
- int ncached_repos;
char name[GOTWEBD_MAXTEXT];
blob - 955f6f78dbc1dfa3ebee40db102caa324f8bb4b1
blob + 9bc30d898bbeace1de6db826d8fdd38f722fe4f3
--- gotwebd/sockets.c
+++ gotwebd/sockets.c
{
struct server *srv, *tsrv;
struct socket *sock, *tsock;
- int i;
sockets_purge(gotwebd_env);
}
/* clean servers */
- TAILQ_FOREACH_SAFE(srv, &gotwebd_env->servers, entry, tsrv) {
- for (i = 0; i < srv->ncached_repos; i++)
- got_repo_close(srv->cached_repos[i].repo);
+ TAILQ_FOREACH_SAFE(srv, &gotwebd_env->servers, entry, tsrv)
free(srv);
- }
free(gotwebd_env);
}