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

[PATCH 2/5] verify-tag: use sigchain library to block SIGPIPE

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Mar 20, 2010, 05:12 UTC
Message-ID
<20100320051219.GB24791@progeny.tock>
In-Reply-To
<20100320050953.GA24746@progeny.tock>

Without this change, callers cannot use verify_tag() safely without blocking SIGPIPE themselves.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 builtin/verify-tag.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/builtin/verify-tag.c b/builtin/verify-tag.c
index 9f482c2..91dd1c1 100644
--- a/builtin/verify-tag.c
+++ b/builtin/verify-tag.c
@@ -10,6 +10,7 @@
 #include "tag.h"
 #include "run-command.h"
 #include <signal.h>
+#include "sigchain.h"
 #include "parse-options.h"
 
 static const char * const verify_tag_usage[] = {
@@ -54,8 +55,15 @@ static int run_gpg_verify(const char *buf, unsigned long size, int verbose)
 		return error("could not run gpg.");
 	}
 
+	/*
+	 * gpg will stop as soon as it knows the signature is bad,
+	 * which can result in SIGPIPE.
+	 */
+	sigchain_push(SIGPIPE, SIG_IGN);
 	write_in_full(gpg.in, buf, len);
 	close(gpg.in);
+	sigchain_pop(SIGPIPE);
+
 	ret = finish_command(&gpg);
 
 	unlink_or_warn(path);
@@ -104,9 +112,6 @@ int cmd_verify_tag(int argc, const char **argv, const char *prefix)
 	if (argc <= i)
 		usage_with_options(verify_tag_usage, verify_tag_options);
 
-	/* sometimes the program was terminated because this signal
-	 * was received in the process of writing the gpg input: */
-	signal(SIGPIPE, SIG_IGN);
 	while (i < argc)
 		if (verify_tag(argv[i++], verbose))
 			had_error = 1;
-- 
1.7.0.2
Previous: Jonathan NiederNext: Jonathan Nieder
Message 5 of 9 in “libify verify_tag()”
  1. 0/5 libify verify_tag()Jonathan Nieder, Mar 20, 2010
  2. 1/5 tag -v: use ‘git verify-tag’ without dashJonathan Nieder, Mar 20, 2010
  3. Johannes SixtMar 20, 2010
  4. Jonathan NiederMar 20, 2010
  5. 2/5 verify-tag: use sigchain library to block SIGPIPEJonathan Nieder, Mar 20, 2010
  6. 3/5 Expose verify_tag()Jonathan Nieder, Mar 20, 2010
  7. 4/5 tag -v: Do not spawn a separate process for verify-tagJonathan Nieder, Mar 20, 2010
  8. 4/5 tag -v: Do not spawn a separate process for verify-tagJonathan Nieder, Mar 20, 2010
  9. 5/5 verify_tag_signature(): let caller look up tag object sha1Jonathan Nieder, Mar 20, 2010

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.