Diffstat (limited to 'cache.c')
| -rw-r--r-- | cache.c | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -24,6 +24,7 @@ struct cache_slot { int keylen; int ttl; cache_fill_fn fn; + void *cbdata; int cache_fd; int lock_fd; const char *cache_name; @@ -186,7 +187,7 @@ static int fill_slot(struct cache_slot *slot) return errno; /* Generate cache content */ - slot->fn(); + slot->fn(slot->cbdata); /* Restore stdout */ if (dup2(tmp, STDOUT_FILENO) == -1) @@ -276,7 +277,7 @@ static int process_slot(struct cache_slot *slot) if ((err = lock_slot(slot)) != 0) { cache_log("[cgit] Unable to lock slot %s: %s (%d)\n", slot->lock_name, strerror(err), err); - slot->fn(); + slot->fn(slot->cbdata); return 0; } @@ -285,7 +286,7 @@ static int process_slot(struct cache_slot *slot) slot->lock_name, strerror(err), err); unlock_slot(slot, 0); close_lock(slot); - slot->fn(); + slot->fn(slot->cbdata); return 0; } // We've got a valid cache slot in the lock file, which @@ -309,7 +310,7 @@ static int process_slot(struct cache_slot *slot) /* Print cached content to stdout, generate the content if necessary. */ int cache_process(int size, const char *path, const char *key, int ttl, - cache_fill_fn fn) + cache_fill_fn fn, void *cbdata) { unsigned long hash; int i; @@ -320,14 +321,14 @@ int cache_process(int size, const char *path, const char *key, int ttl, /* If the cache is disabled, just generate the content */ if (size <= 0) { - fn(); + fn(cbdata); return 0; } /* Verify input, calculate filenames */ if (!path) { cache_log("[cgit] Cache path not specified, caching is disabled\n"); - fn(); + fn(cbdata); return 0; } if (!key) @@ -342,6 +343,7 @@ int cache_process(int size, const char *path, const char *key, int ttl, strbuf_addbuf(&lockname, &filename); strbuf_addstr(&lockname, ".lock"); slot.fn = fn; + slot.cbdata = cbdata; slot.ttl = ttl; slot.cache_name = filename.buf; slot.lock_name = lockname.buf; |