chiark / gitweb /
git-cache-proxy: Use open-coded fork/exec for git gc
authorIan Jackson <ian.jackson@eu.citrix.com>
Tue, 11 Feb 2020 18:32:49 +0000 (18:32 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 11 Feb 2020 18:57:35 +0000 (18:57 +0000)
This allows us to handle ENOENT from chdir specially.  We want to
tolerate this, because it can happen if the previous lockholder
cleaned it all up.

Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
scripts/git-cache-proxy

index 636ebfecb2adb51e0f0296ccd7a334c3e51ea89e..ec5ff7f2e81aa9c4fd67069e537479e812f5f60c 100755 (executable)
@@ -447,12 +447,19 @@ sub housekeeping () {
            $mode_action = sub {
                my $gclog = "$subdir/gc.log";
                unlink $gclog or $!==ENOENT or hkfail "remove $gclog: $!";
-               my $r = system qw(sh -ec),
-                   'cd "$1"; shift; exec "$@"', 'x', "$subdir\\.git",
-                   qw(git gc --quiet);
-               if ($r) {
+               my $child = fork // hkfail "fork (for $subdir): $!";
+               if (!$child) {
+                   if (!chdir "$subdir\\.git") {
+                       exit 0 if $!==ENOENT;
+                       die "for gc: chdir $subdir: $!\n";
+                   }
+                   exec qw(git gc --quiet);
+                   die "exec git gc (for $subdir): $!\n";
+               }
+               waitpid($child, 0) == $child or hkfail "waitpid failed! $!";
+               if ($?) {
                    logm 'err',
                      "housekeeping: subdirs $subdir: gc failed (status $r)";
"housekeeping: subdirs $subdir: gc failed (wait status $?)";
                } else {
                    update_gcstamp("$subdir\\.git");
                    logm 'debug',