diff options
Diffstat (limited to 'source/cache.c')
| -rw-r--r-- | source/cache.c | 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 29 insertions, 34 deletions
diff --git a/source/cache.c b/source/cache.c index 2d546bb..28558b1 100644 --- a/source/cache.c +++ b/source/cache.c @@ -88,9 +88,10 @@ static int open_slot(struct cache_slot *slot) keylen = nul - slot->buf; if (slot->key) - slot->key_matches = keylen >= 0 && - (size_t)keylen == slot->keylen && - !memcmp(slot->key, slot->buf, keylen + 1); + slot->key_matches = + keylen >= 0 && + (size_t)keylen == slot->keylen && + !memcmp(slot->key, slot->buf, keylen + 1); return 0; } @@ -168,10 +169,7 @@ static int serve_slot(struct cache_slot *slot) err = print_slot(slot); if (err) - log_error("[cgit] Error printing slot %s: %s (%d)\n", - slot->path, - strerror(err), - err); + log_error("[cgit] Error printing slot %s: %s (%d)\n", slot->path, strerror(err), err); return err; } @@ -192,9 +190,11 @@ static int is_modified(struct cache_slot *slot) if (stat(slot->path, ¤t)) return 1; - return (current.st_ino != slot->st.st_ino || - current.st_mtime != slot->st.st_mtime || - current.st_size != slot->st.st_size); + return ( + current.st_ino != slot->st.st_ino || + current.st_mtime != slot->st.st_mtime || + current.st_size != slot->st.st_size + ); } static int close_lock(struct cache_slot *slot) @@ -225,8 +225,7 @@ static int lock_slot(struct cache_slot *slot) }; struct stat held, named; - slot->lock_fd = open(slot->lock_path, O_RDWR | O_CREAT, - S_IRUSR | S_IWUSR); + slot->lock_fd = open(slot->lock_path, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); if (slot->lock_fd == -1) return errno; if (fcntl(slot->lock_fd, F_SETLK, &lock) < 0) { @@ -239,8 +238,12 @@ static int lock_slot(struct cache_slot *slot) // finishing in between renames that inode into place as the live // slot, and once the path is confirmed to still name this file that // rename can no longer happen, because it takes the lock held here. - if (fstat(slot->lock_fd, &held) || stat(slot->lock_path, &named) || - held.st_ino != named.st_ino || held.st_dev != named.st_dev) { + if ( + fstat(slot->lock_fd, &held) || + stat(slot->lock_path, &named) || + held.st_ino != named.st_ino || + held.st_dev != named.st_dev + ) { close(slot->lock_fd); slot->lock_fd = -1; return EAGAIN; @@ -386,23 +389,20 @@ 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", slot->path); + log_error("[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 // straight to the client and the caller is told the request succeeded, // because it did. close_slot(slot); if ((err = lock_slot(slot)) != 0) { - log_error("[cgit] Error locking slot %s: %s (%d)\n", - slot->lock_path, strerror(err), err); + log_error("[cgit] Error locking slot %s: %s (%d)\n", slot->lock_path, strerror(err), err); slot->fn(); return 0; } if ((err = fill_slot(slot)) != 0) { - log_error("[cgit] Error filling slot %s: %s (%d)\n", - slot->lock_path, strerror(err), err); + log_error("[cgit] Error filling 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, @@ -459,8 +459,7 @@ unsigned long cache_hash_str(const char *str) return h; } -int cache_process(int size, const char *path, const char *key, int ttl, - cache_fill_fn fn) +int cache_process(int size, const char *path, const char *key, int ttl, cache_fill_fn fn) { unsigned long hash; int i; @@ -482,8 +481,7 @@ int cache_process(int size, const char *path, const char *key, int ttl, 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"); + log_error("[cgit] Cache key too long for a slot, caching is disabled for this request\n"); fn(); return 0; } @@ -531,8 +529,7 @@ int cache_ls(const char *path) dir = opendir(path); if (!dir) { err = errno; - log_error("[cgit] Error opening %s: %s (%d)\n", - path, strerror(err), err); + log_error("[cgit] Error opening %s: %s (%d)\n", path, strerror(err), err); return err; } strbuf_addstr(&slot_path, path); @@ -545,20 +542,18 @@ 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] Error opening %s: %s (%d)\n", - slot_path.buf, strerror(err), err); + log_error("[cgit] Error opening %s: %s (%d)\n", slot_path.buf, strerror(err), err); continue; } // A truncated or corrupt slot may hold no NUL, so the print is // bounded by what was read and cannot run off the end. nul = memchr(slot.buf, 0, slot.buflen); keylen = nul ? (int)(nul - slot.buf) : slot.buflen; - htmlf("%s %s %10"PRIuMAX" %.*s\n", - slot_path.buf, - format_time("%Y-%m-%d %H:%M:%S", - slot.st.st_mtime), - (uintmax_t)slot.st.st_size, - keylen, slot.buf); + htmlf( + "%s %s %10"PRIuMAX" %.*s\n", slot_path.buf, + format_time("%Y-%m-%d %H:%M:%S", slot.st.st_mtime), + (uintmax_t)slot.st.st_size, keylen, slot.buf + ); close_slot(&slot); } closedir(dir); |
