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

[PATCH 3/7] t: translate SIGINT to an exit

From
Jeff King <peff@peff.net>
Date
Mar 13, 2015, 04:48 UTC
Message-ID
<20150313044848.GC18532@peff.net>
In-Reply-To
<20150313044101.GA18476@peff.net>

Right now if a test script receives SIGINT (e.g., because a test was hanging and the user hit ^C), the shell exits immediately. This can be annoying if the test script did any global setup, like starting apache or git-daemon, as it will not have an opportunity to clean up after itself. A subsequent run of the test won't be able to start its own daemon, and will either fail or skip the tests.

Instead, let's trap SIGINT to make sure we do a clean shutdown, and just chain it to a normal exit (which will trigger any cleanup).

Signed-off-by: Jeff King <peff@peff.net>
---
Possibly we should catch other signals here, too, but SIGINT is the one
that has been biting me over the years (I would sometimes have a stray
apache process hanging around, and I only recently figured out what
caused it).

I think "trap ... INT" is the most portable way to say this. I would have thought numbers were more portable, but they are actually an XSI add-on. Likewise, "SIGINT" is allowed in POSIX but not required. "INT" is part of POSIX.

This is the cleanest way I could come up with to implement this. We could also just include "INT" on the same line as the die, but:

  1. Then every script which sets a handler (like lib-httpd.sh) would
     need to be modified to munge the INT trap, too.
  2. It double-calls die, then. We die from the INT handler, which
     triggers the EXIT handler. I guess we could clear the handler
     inside die() if we needed to.

So I'd rather go this route, unless there turns out to be a weird portability problem.

 t/test-lib.sh | 1 +
 1 file changed, 1 insertion(+)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index c096778..f4ba3ff 100644
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -299,6 +299,7 @@ die () {
 
 GIT_EXIT_OK=
 trap 'die' EXIT
+trap 'exit $?' INT
 
 # The user-facing functions are loaded from a separate file so that
 # test_perf subshells can have them too
-- 
2.3.2.472.geadab3c
Previous: Jeff KingNext: Jeff King
Message 5 of 12 in “fix transfer.hiderefs with smart http”
  1. 0/7 fix transfer.hiderefs with smart httpJeff King, Mar 13, 2015
  2. 1/7 upload-pack: fix transfer.hiderefs over smart-httpJeff King, Mar 13, 2015
  3. Junio C HamanoMar 13, 2015
  4. 2/7 upload-pack: do not check NULL return of lookup_unknown_objectJeff King, Mar 13, 2015
  5. 3/7 t: translate SIGINT to an exitJeff King, Mar 13, 2015
  6. 4/7 t: redirect stderr GIT_TRACE to descriptor 4Jeff King, Mar 13, 2015
  7. 5/7 t: pass GIT_TRACE through ApacheJeff King, Mar 13, 2015
  8. 6/7 t5541: move run_with_cmdline_limit to test-lib.shJeff King, Mar 13, 2015
  9. Eric SunshineMar 13, 2015
  10. 7/7 t5551: make EXPENSIVE test cheaperJeff King, Mar 13, 2015
  11. Jeff KingMar 13, 2015
  12. Duy NguyenMar 13, 2015

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.