chiark / gitweb /
git-cache-proxy: New --serve-timeout option.
[chiark-utils.git] / scripts / git-cache-proxy
index 8747eba9cbf788588a9514b601726d2905f9e5cf..ffdf6eab52fe57bad3b276ad71a21002abc5011e 100755 (executable)
@@ -29,7 +29,8 @@
 
 # git-cache-proxy
 # Copyright 2010 Tony Finch
-# Copyright 2013 Ian Jackson
+# Copyright 2013,2014 Ian Jackson
+# Copyright 2017 Citrix
 # 
 # git-cache-proxy is free software; you can redistribute it and/or
 # modify them under the terms of the GNU General Public License as
@@ -66,6 +67,7 @@ our $housekeepingeverydays = 1;
 our $treeexpiredays = 21;
 our $fetchtimeout = 1800;
 our $maxfetchtimeout = 3600;
+our $servetimeout = 1000;
 our $cachedir = '/var/cache/git-cache-proxy';
 our $housekeepingonly = 0;
 
@@ -171,6 +173,7 @@ for (;;) {
            $cachedir = $1;
        } elsif (s/^--( max-fetch-timeout
                       | fetch-timeout
+                      | serve-timeout
                       | tree-expire-days
                       | housekeeping-interval-days
                       )=(\d+)$//x) {
@@ -360,6 +363,7 @@ sub clonefetch () {
                servinfo "fetch/clone failed: $fetchfail";
            }
        }
+        alarm 0;
 
        if (!$exists) {
            rename $tmpd, $gitd or fail "rename fresh $tmpd to $gitd: $!";
@@ -405,21 +409,28 @@ sub housekeeping () {
            next;
        }
        logm 'info', "housekeeping: subdirs $subdir: cleaning";
-       my $ok = 1;
-       foreach my $suffix (qw(tmp git)) {
-           my $dir = "${subdir}\\.$suffix";
-           my $errs;
-           remove_tree($dir, { safe=>1, error=>\$errs });
-           if (stat $dir) {
-               $ok = 0;
-               logm 'warning', "housekeeping: $dir: problems with".
-                   "deletion prevent cleanup:";
-               foreach my $err (@$errs) {
-                   logm 'info', "problem deleting: $err->[0]: $err->[1]";
+       eval {
+           foreach my $suffix (qw(tmp git)) {
+               my $dir = "${subdir}\\.$suffix";
+               my $tdir = "${subdir}\\.tmp";
+               if ($dir ne $tdir) {
+                   if (!rename $dir,$tdir) {
+                       next if $! == ENOENT;
+                       die "$dir: cannot rename to $tdir: $!\n";
+                   }
+               }
+               system qw(rm -rf --), $tdir;
+               if (stat $tdir) {
+                   die "$dir: problem deleting file(s), rm exited $?\n";
+               } elsif ($! != ENOENT) {
+                   die "$tdir: cannot stat after deletion: $!\n";
                }
            }
-       }
-       if ($ok) {
+       };
+       if (length $@) {
+           chomp $@;
+           logm 'warning', "housekeeping: $subdir: cleanup prevented: $@";
+       } else {
            unlink $lock or hkfail "remove $lock: $!";
        }
     }
@@ -449,8 +460,10 @@ sub housekeepingcheck ($$) {
     }
     if ($dofork) {
        my $child = fork;
-       defined $child or hkfail "fork: $!";
+       defined $child or fail "fork: $!";
        if (!$child) {
+           open STDERR, "|logger -p daemon.warning -t '$us(housekeeping)'"
+               or die "fork: logger $!";
            housekeeping();
            exit 0;
        }
@@ -466,7 +479,7 @@ sub runcommand () {
 
     chdir $gitd or fail "chdir $gitd: $!";
 
-    exec qw(git-upload-pack --strict --timeout=1000 .)
+    exec qw(git-upload-pack --strict), "--timeout=$servetimeout", qw(.)
        or fail "exec git-upload-pack: $!";
 }