Skip to content

Commit 0693f9d

Browse files
committed
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 <[email protected]>
1 parent c55fae4 commit 0693f9d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lockfile.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)
140140
signal(SIGHUP, remove_lock_file_on_signal);
141141
signal(SIGTERM, remove_lock_file_on_signal);
142142
signal(SIGQUIT, remove_lock_file_on_signal);
143+
signal(SIGPIPE, remove_lock_file_on_signal);
143144
atexit(remove_lock_file);
144145
}
145146
lk->owner = getpid();

t/t3600-rm.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,4 +251,21 @@ test_expect_success 'refresh index before checking if it is up-to-date' '
251251
252252
'
253253

254+
test_expect_success 'choking "git rm" should not let it die with cruft' '
255+
git reset -q --hard &&
256+
H=0000000000000000000000000000000000000000 &&
257+
i=0 &&
258+
while test $i -lt 12000
259+
do
260+
echo "100644 $H 0 some-file-$i"
261+
i=$(( $i + 1 ))
262+
done | git update-index --index-info &&
263+
git rm -n "some-file-*" | :;
264+
test -f .git/index.lock
265+
status=$?
266+
rm -f .git/index.lock
267+
git reset -q --hard
268+
test "$status" != 0
269+
'
270+
254271
test_done

0 commit comments

Comments
 (0)