summary refs log tree commit diff
path: root/bin
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-09-12 02:35:44 -0400
committerJune McEnroe <june@causal.agency>2019-09-12 02:35:44 -0400
commitb46e8bb966e559bb8ac0cd9d514d19a97d969566 (patch)
treee237d897b589e5a0c1b9b4490057401d55a5d2db /bin
parentAdd title -v flag (diff)
downloadsrc-b46e8bb966e559bb8ac0cd9d514d19a97d969566.tar.gz
src-b46e8bb966e559bb8ac0cd9d514d19a97d969566.zip
Consume entire body
Aborting the request and leaving data around may be causing intermittent
errors. Just discard the rest of the data.
Diffstat (limited to '')
-rw-r--r--bin/title.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/bin/title.c b/bin/title.c
index affc3ceb..11cb9fb7 100644
--- a/bin/title.c
+++ b/bin/title.c
@@ -82,6 +82,7 @@ static void showTitle(const char *title) {
 }
 
 static CURL *curl;
+static bool title;
 static struct {
 	char buf[8192];
 	size_t len;
@@ -93,11 +94,10 @@ static regex_t TitleRegex;
 
 static size_t handleBody(char *buf, size_t size, size_t nitems, void *user) {
 	(void)user;
-
 	size_t len = size * nitems;
 	size_t cap = sizeof(body.buf) - body.len - 1;
 	size_t new = (len < cap ? len : cap);
-	if (!new) return 0;
+	if (title || !new) return len;
 
 	memcpy(&body.buf[body.len], buf, new);
 	body.len += new;
@@ -107,7 +107,9 @@ static size_t handleBody(char *buf, size_t size, size_t nitems, void *user) {
 	if (regexec(&TitleRegex, body.buf, 2, match, 0)) return len;
 	body.buf[match[1].rm_eo] = '\0';
 	showTitle(&body.buf[match[1].rm_so]);
-	return 0;
+	title = true;
+
+	return len;
 }
 
 static CURLcode fetchTitle(const char *url) {
@@ -124,9 +126,9 @@ static CURLcode fetchTitle(const char *url) {
 	if (!type || strncmp(type, "text/html", 9)) return CURLE_OK;
 
 	body.len = 0;
+	title = false;
 	curl_easy_setopt(curl, CURLOPT_NOBODY, 0L);
 	code = curl_easy_perform(curl);
-	if (code == CURLE_WRITE_ERROR) return CURLE_OK;
 	return code;
 }
 
;number> On startup, /etc/cgitrc is parsed, followed by argument parsing and finally querystring parsing. If --nocache is specified (or set in /etc/gitrc), caching is disabled and cgit instead generates pages to stdout. The combined effect of these two changes makes testing/debugging a lot less painfull. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-16Add head comment to shared.cLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-16Add head comment to ui-commit.cLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-16gitweb ripoff: set tr:hover to highligt current rowLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-16Make repo header a link to summary pageLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-16Move cgit_print_date into ui-shared, reuse in ui-summaryLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-16Add ui-commit.c + misc ui cleanupsLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-15Add a common commit parserLars Hjemli Make a better commit parser, replacing the ugly one in ui-log.c Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-14Add simple pager to log pageLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-13Add separate makefile-rule to clear current cacheLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-13Remove implementation details from READMELars Hjemli Let README describe the "bigger picture" instead. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-13Small layout adjustments to summary and blob viewLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-13Add display of tree content w/ui-tree.cLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-12cache_lock: do xstrdup/free on lockfileLars Hjemli Since fmt() uses 8 alternating static buffers, and cache_lock might call cache_create_dirs() multiple times, which in turn might call fmt() twice, after four iterations lockfile would be overwritten by a cachedirectory path. In worst case, this could cause the cachedirectory to be unlinked and replaced by a cachefile. Fix: use xstrdup() on the result from fmt() before assigning to lockfile, and call free(lockfile) before exit. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-11Don't truncate valid cachefilesLars Hjemli An embarrassing thinko in cgit_check_cache() would truncate valid cachefiles in the following situation: 1) process A notices a missing/expired cachefile 2) process B gets scheduled, locks, fills and unlocks the cachefile 3) process A gets scheduled, locks the cachefile, notices that the cachefile now exist/is not expired anymore, and continues to overwrite it with an empty lockfile. Thanks to Linus for noticing (again). Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-11Move global variables + callback functions into shared.cLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-11Move functions for generic object output into ui-view.cLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-11Move log-functions into ui-log.cLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-11Move repo summary functions into ui-summary.cLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-11Move functions for repolist output into ui-repolist.cLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-11Move common output-functions into ui-shared.cLars Hjemli While at it, replace the cgit_[lib_]error constants with a proper function Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-11Rename config.c to parsing.c + move cgit_parse_query from cgit.c to parsing.cLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-11Avoid infinite loops in caching layerLars Hjemli Add a global variable, cgit_max_lock_attemps, to avoid the possibility of infinite loops when failing to acquire a lockfile. This could happen on broken setups or under crazy server load. Incidentally, this also fixes a lurking bug in cache_lock() where an uninitialized returnvalue was used. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-11Let 'make install' clear all cachefilesLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-11Fix cache algorithm loopholeLars Hjemli This closes the door for unneccessary calls to cgit_fill_cache(). Noticed by Linus. Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-10Add version identifier in generated filesLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-10Add license file and copyright noticesLars Hjemli Signed-off-by: Lars Hjemli <hjemli@gmail.com> 2006-12-10Add caching infrastructureLars Hjemli