Skip to content

Commit 9b6b994

Browse files
pks-tgitster
authored andcommitted
builtin/gc: stop processing log file on signal
When detaching, git-gc(1) will redirect its stderr to a "gc.log" log file, which is then used to surface errors of a backgrounded process to the user. To ensure that the file is properly managed on abnormal exit paths, we install both signal and exit handlers that try to either commit the underlying lock file or roll it back in case there wasn't any error. This logic is severly broken when handling signals though, as we end up calling all kinds of functions that are not signal safe. This includes malloc(3P) via `git_path()`, fprintf(3P), fflush(3P) and many more functions. The consequence can be anything, from deadlocks to crashes. Unfortunately, we cannot really do much about this without a larger refactoring. The least-worst thing we can do is to not set up the signal handler in the first place. This will still cause us to remove the lockfile, as the underlying tempfile subsystem already knows to unlink locks when receiving a signal. But it may cause us to remove the lock even in the case where it would have contained actual errors, which is a change in behaviour. The consequence is that "gc.log" will not be committed, and thus subsequent calls to `git gc --auto` won't bail out because of this. Arguably though, it is better to retry garbage collection rather than having the process run into a potentially-corrupted state. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0ce44e2 commit 9b6b994

File tree

1 file changed

+0
-8
lines changed

1 file changed

+0
-8
lines changed

builtin/gc.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,6 @@ static void process_log_file_at_exit(void)
109109
process_log_file();
110110
}
111111

112-
static void process_log_file_on_signal(int signo)
113-
{
114-
process_log_file();
115-
sigchain_pop(signo);
116-
raise(signo);
117-
}
118-
119112
static int gc_config_is_timestamp_never(const char *var)
120113
{
121114
const char *value;
@@ -807,7 +800,6 @@ int cmd_gc(int argc, const char **argv, const char *prefix)
807800
git_path("gc.log"),
808801
LOCK_DIE_ON_ERROR);
809802
dup2(get_lock_file_fd(&log_lock), 2);
810-
sigchain_push_common(process_log_file_on_signal);
811803
atexit(process_log_file_at_exit);
812804
}
813805

0 commit comments

Comments
 (0)