mirror of
https://github.com/git/git
synced 2024-11-05 18:59:29 +00:00
Make sure lockfiles are unlocked when dying on SIGPIPE
We cleaned up lockfiles upon receiving the usual suspects HUP, TERM, QUIT but a wicked user could kill us of asphyxiation by piping our output to a pipe that does not read. Protect ourselves by catching SIGPIPE and clean up the lockfiles as well in such a case. Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
c55fae43c4
commit
0693f9ddad
2 changed files with 18 additions and 0 deletions
|
@ -140,6 +140,7 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)
|
||||||
signal(SIGHUP, remove_lock_file_on_signal);
|
signal(SIGHUP, remove_lock_file_on_signal);
|
||||||
signal(SIGTERM, remove_lock_file_on_signal);
|
signal(SIGTERM, remove_lock_file_on_signal);
|
||||||
signal(SIGQUIT, remove_lock_file_on_signal);
|
signal(SIGQUIT, remove_lock_file_on_signal);
|
||||||
|
signal(SIGPIPE, remove_lock_file_on_signal);
|
||||||
atexit(remove_lock_file);
|
atexit(remove_lock_file);
|
||||||
}
|
}
|
||||||
lk->owner = getpid();
|
lk->owner = getpid();
|
||||||
|
|
|
@ -251,4 +251,21 @@ test_expect_success 'refresh index before checking if it is up-to-date' '
|
||||||
|
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'choking "git rm" should not let it die with cruft' '
|
||||||
|
git reset -q --hard &&
|
||||||
|
H=0000000000000000000000000000000000000000 &&
|
||||||
|
i=0 &&
|
||||||
|
while test $i -lt 12000
|
||||||
|
do
|
||||||
|
echo "100644 $H 0 some-file-$i"
|
||||||
|
i=$(( $i + 1 ))
|
||||||
|
done | git update-index --index-info &&
|
||||||
|
git rm -n "some-file-*" | :;
|
||||||
|
test -f .git/index.lock
|
||||||
|
status=$?
|
||||||
|
rm -f .git/index.lock
|
||||||
|
git reset -q --hard
|
||||||
|
test "$status" != 0
|
||||||
|
'
|
||||||
|
|
||||||
test_done
|
test_done
|
||||||
|
|
Loading…
Reference in a new issue