git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2] rollback lock files on more signals than just SIGINT

From
Paolo Bonzini <bonzini@gnu.org>
Date
May 29, 2008, 14:55 UTC
Message-ID
<E1K1jnV-0007HC-Om@fencepost.gnu.org>
In-Reply-To
<alpine.DEB.1.00.0805291541430.13507@racer.site.net>

Other signals are also common, for example SIGTERM and SIGHUP. This patch modifies the lock file mechanism to catch more signals. It also modifies http-push.c which was missing SIGTERM.

Signed-off-by: Paolo Bonzini <bonzini@gnu.org>
---
 http-push.c       |    1 +
 lockfile.c        |    3 +++
 t/t7502-commit.sh |   14 ++++++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)
	>> It would be curious at least to set the commit_style to COMMIT_NORMAL
	>> after creating the index_lock, and upgrade it to COMMIT_PARTIAL later
	>> on.  I contemplated that, and my patch is the simplest code that's 
	>> needed and works.
	> 
	> As I said, I think it is a regression, because you change code.  Your 
	> argument as to why leaves me desiring another solution.
	
	Ok, here it is.  But it's not what you were expecting. :-P
diff --git a/http-push.c b/http-push.c
index f173dcd..c93e781 100644
--- a/http-push.c
+++ b/http-push.c
@@ -2277,6 +2277,7 @@ int main(int argc, char **argv)
 	signal(SIGINT, remove_locks_on_signal);
 	signal(SIGHUP, remove_locks_on_signal);
 	signal(SIGQUIT, remove_locks_on_signal);
+	signal(SIGTERM, remove_locks_on_signal);
 
 	/* Check whether the remote has server info files */
 	remote->can_update_info_refs = 0;
diff --git a/lockfile.c b/lockfile.c
index cfc7335..4023797 100644
--- a/lockfile.c
+++ b/lockfile.c
@@ -135,6 +135,9 @@ static int lock_file(struct lock_file *lk, const char *path)
 	if (0 <= lk->fd) {
 		if (!lock_file_list) {
 			signal(SIGINT, remove_lock_file_on_signal);
+			signal(SIGHUP, remove_lock_file_on_signal);
+			signal(SIGTERM, remove_lock_file_on_signal);
+			signal(SIGQUIT, remove_lock_file_on_signal);
 			atexit(remove_lock_file);
 		}
 		lk->owner = getpid();
diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh
index 3531a99..46ec1ce 100755
--- a/t/t7502-commit.sh
+++ b/t/t7502-commit.sh
@@ -212,4 +212,18 @@ test_expect_success 'do not fire editor in the presence of conflicts' '
 	test "`cat .git/result`" = "editor not started"
 '
 
+pwd=`pwd`
+cat > .git/FAKE_EDITOR << EOF
+#! /bin/sh
+# kill -TERM command added below.
+EOF
+
+test_expect_success 'a SIGTERM should break locks' '
+	echo >>negative &&
+	sh -c '\''
+	  echo kill -TERM $$ >> .git/FAKE_EDITOR
+	  GIT_EDITOR=.git/FAKE_EDITOR exec git commit -a'\'' && exit 1  # should fail
+	! test -f .git/index.lock
+'
+
 test_done
-- 
1.5.5
Previous: Johannes SchindelinNext: Mike Ralphson
Message 7 of 10 in “rollback index if git-commit is interrupted by a signal”
  1. rollback index if git-commit is interrupted by a signalPaolo Bonzini, May 29, 2008
  2. Johannes SchindelinMay 29, 2008
  3. Paolo BonziniMay 29, 2008
  4. Johannes SchindelinMay 29, 2008
  5. Paolo BonziniMay 29, 2008
  6. Johannes SchindelinMay 29, 2008
  7. rollback lock files on more signals than just SIGINTPaolo Bonzini, May 29, 2008
  8. Mike RalphsonJun 4, 2008
  9. Junio C HamanoJun 4, 2008
  10. Mike RalphsonJun 5, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.