Diff options
Diffstat (limited to 'source/cache.c')
-rw-r--r--source/cache.c35
1 file changed, 10 insertions, 25 deletions
diff --git a/source/cache.c b/source/cache.c
index 9594fd6..7a39f1b 100644
--- a/source/cache.c
+++ b/source/cache.c
@@ -31,21 +31,6 @@
#define FNV_OFFSET 0x811c9dc5
#define FNV_PRIME 0x01000193
-/*
- * Cache trouble goes to stderr, which under CGI is the web server's error
- * log, so that it cannot land in the middle of the page being written to
- * stdout.
- */
-__attribute__((format (printf,1,2)))
-static void log_error(const char *format, ...)
-{
- va_list args;
-
- va_start(args, format);
- vfprintf(stderr, format, args);
- va_end(args);
-}
-
struct cache_slot {
const char *key;
size_t keylen;
@@ -182,7 +167,7 @@ static int serve_slot(struct cache_slot *slot)
err = print_slot(slot);
// A client that went away mid-page is not trouble worth a line.
if (err && err != EPIPE)
- log_error("[cgit] Unable to send slot %s: %s (%d)\n", slot->path, strerror(err), err);
+ fprintf(stderr, "[cgit] Unable to send slot %s: %s (%d)\n", slot->path, strerror(err), err);
return err;
}
@@ -347,7 +332,7 @@ static void publish_slot(struct cache_slot *slot)
int err = unlock_slot(slot, 1);
if (err)
- log_error("[cgit] Unable to publish cache slot %s: %s (%d)\n", slot->path,
+ fprintf(stderr, "[cgit] Unable to publish cache slot %s: %s (%d)\n", slot->path,
strerror(err), err);
}
@@ -448,7 +433,7 @@ static int process_slot(struct cache_slot *slot)
// and two popular pages sharing one slot evict each other on every
// alternating visit.
if (!err)
- log_error("[cgit] Cache slot %s holds a different key, consider a larger cache-size\n",
+ fprintf(stderr, "[cgit] Cache slot %s holds a different key, consider a larger cache-size\n",
slot->path);
// If any part of creating a slot fails the page is still rendered
@@ -456,13 +441,13 @@ static int process_slot(struct cache_slot *slot)
// because it did.
close_slot(slot);
if ((err = lock_slot(slot)) != 0) {
- log_error("[cgit] Unable to lock slot %s: %s (%d)\n", slot->lock_path, strerror(err), err);
+ fprintf(stderr, "[cgit] Unable to lock slot %s: %s (%d)\n", slot->lock_path, strerror(err), err);
slot->fn();
return 0;
}
if ((err = fill_slot(slot)) != 0) {
- log_error("[cgit] Unable to fill slot %s: %s (%d)\n", slot->lock_path, strerror(err), err);
+ fprintf(stderr, "[cgit] Unable to fill slot %s: %s (%d)\n", slot->lock_path, strerror(err), err);
unlock_slot(slot, 0);
close_lock(slot);
// Rendering again is only right when nothing was delivered,
@@ -540,14 +525,14 @@ int cache_process(int size, const char *path, const char *key, int ttl, size_t m
}
if (!path) {
- log_error("[cgit] Cache path not specified, caching is disabled\n");
+ fprintf(stderr, "[cgit] Cache path not specified, caching is disabled\n");
fn();
return 0;
}
if (!key)
key = "";
if (!key_fits_slot(key)) {
- log_error("[cgit] Cache key too long for a slot, caching is disabled for this request\n");
+ fprintf(stderr, "[cgit] Cache key too long for a slot, caching is disabled for this request\n");
fn();
return 0;
}
@@ -591,13 +576,13 @@ int cache_ls(const char *path)
int keylen;
if (!path) {
- log_error("[cgit] Cache path not specified\n");
+ fprintf(stderr, "[cgit] Cache path not specified\n");
return -1;
}
dir = opendir(path);
if (!dir) {
err = errno;
- log_error("[cgit] Unable to open %s: %s (%d)\n", path, strerror(err), err);
+ fprintf(stderr, "[cgit] Unable to open %s: %s (%d)\n", path, strerror(err), err);
return err;
}
strbuf_addstr(&slot_path, path);
@@ -610,7 +595,7 @@ int cache_ls(const char *path)
strbuf_addstr(&slot_path, ent->d_name);
slot.path = slot_path.buf;
if ((err = open_slot(&slot)) != 0) {
- log_error("[cgit] Unable to open %s: %s (%d)\n", slot_path.buf, strerror(err), err);
+ fprintf(stderr, "[cgit] Unable to open %s: %s (%d)\n", slot_path.buf, strerror(err), err);
close_slot(&slot);
continue;
}