about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-04-27 11:01:08 +0200
committerRory& <root@rory.gay>2025-04-27 11:01:08 +0200
commit43939110959a719b0b346780e8f0d0c028320180 (patch)
treece409293a633a8e9fa26834e05616bc38e79c265
parentFix test script, serve resources (diff)
downloadcgit-magenta-43939110959a719b0b346780e8f0d0c028320180.tar.xz
Sendfile, minor fixes in static file support, spawn more processes in test, css fixes
-rw-r--r--.gitattributes3
-rw-r--r--cgit.c22
-rw-r--r--cgit.css2
-rwxr-xr-xtest.sh3
4 files changed, 25 insertions, 5 deletions
diff --git a/.gitattributes b/.gitattributes
new file mode 100644

index 0000000..1daa00f --- /dev/null +++ b/.gitattributes
@@ -0,0 +1,3 @@ +* text=auto +*.py text=auto eol=lf +*.sh text=auto eol=lf diff --git a/cgit.c b/cgit.c
index 8b20f27..cbb1929 100644 --- a/cgit.c +++ b/cgit.c
@@ -9,6 +9,9 @@ #define USE_THE_REPOSITORY_VARIABLE #include "cgit.h" + +#include <sys/sendfile.h> + #include "cache.h" #include "cmd.h" #include "configfile.h" @@ -1105,7 +1108,7 @@ int cmd_main(int argc, const char **argv) ) { // files are in the same directory as the cgit binary char filename[1024]; - snprintf(filename, sizeof(filename), "%s/%s", dirname(argv[0]), script_name + 1); + snprintf(filename, sizeof(filename), "%s/%s", dirname((char*) argv[0]), script_name + 1); struct stat st; if (!stat(filename, &st)) { FILE *f = fopen(filename, "r"); @@ -1120,12 +1123,25 @@ int cmd_main(int argc, const char **argv) else if (ext && !strcmp(ext, ".js")) ctx.page.mimetype = "application/javascript"; + + cgit_print_http_headers(); +#ifndef HAVE_LINUX_SENDFILE char *buf = xmalloc(st.st_size); fread(buf, 1, st.st_size, f); - fclose(f); - cgit_print_http_headers(); + fwrite(buf, 1, st.st_size, stdout); free(buf); +#else + fflush(0); // manually flush headers + ssize_t sfErr = sendfile(STDOUT_FILENO, fileno(f), NULL, st.st_size); + if (sfErr < 0) { + perror("sendfile"); + fclose(f); + return -1; + } +#endif + + fclose(f); return 0; } } diff --git a/cgit.css b/cgit.css
index f9a3165..2574563 100644 --- a/cgit.css +++ b/cgit.css
@@ -991,4 +991,6 @@ div#cgit table.ssdiff td.space div { div#cgit table.ssdiff td.head { border-top-color: #555; border-bottom-color: #555; } div#cgit table.ssdiff td.head div.head { color: #eee; } div#cgit table.ssdiff td.foot { border-top-color: #555; } + div#cgit table.diff td span.head { color: #eee; } + div#cgit table.diff td span.hunk { color: #44f; } } diff --git a/test.sh b/test.sh
index 1fb2658..ca9e56e 100755 --- a/test.sh +++ b/test.sh
@@ -9,6 +9,5 @@ nix build nixpkgs#nginx --out-link test_utils/nginx nix build nixpkgs#fcgiwrap --out-link test_utils/fcgiwrap nix build nixpkgs#git --out-link test_utils/git - -test_utils/fcgiwrap/bin/fcgiwrap -s unix:test_utils/fcgiwrap.sock -c 4 & +test_utils/fcgiwrap/bin/fcgiwrap -s unix:test_utils/fcgiwrap.sock -c $(($(nproc)*4)) & test_utils/nginx/bin/nginx -c $(pwd)/tests/nginx.conf -p $(pwd)/test_utils