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

Re: [PATCH] Fix signal handler

From
MEMarkus Elfring <markus.elfring@web.de>
Date
Feb 10, 2010, 17:08 UTC
Message-ID
<4B72E81B.3020900@web.de>
In-Reply-To
<4B71A2EE.8070708@web.de>
Hello,

How do Git software developers think about the appended update suggestion? Would you like to integrate such adjustments into your source code repository?

Regards, Markus

>From c37d8dafef11168d8302d40c8d1453943a058d95 Mon Sep 17 00:00:00 2001
From: Markus Elfring <Markus.Elfring@web.de>
Date: Wed, 10 Feb 2010 17:05:45 +0100
Subject: [PATCH] Fix a signal handler
A global flag can only be set by a signal handler in a portable way if it has got the data type "sig_atomic_t". The previously used assignment of a function pointer in the function "early_output" was moved to another variable in the function "setup_early_output".
The involved software design details were also mentioned on the mailing list.
---
 builtin-log.c |   12 +++---------
 revision.c    |   14 ++++++--------
 revision.h    |    3 ++-
 3 files changed, 11 insertions(+), 18 deletions(-)
diff --git a/builtin-log.c b/builtin-log.c
index 8d16832..358c98b 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -123,7 +123,7 @@ static void show_early_header(struct rev_info *rev, const char *stage, int nr)
 
 static struct itimerval early_output_timer;
 
-static void log_show_early(struct rev_info *revs, struct commit_list *list)
+extern void log_show_early(struct rev_info *revs, struct commit_list *list)
 {
 	int i = revs->early_output;
 	int show_header = 1;
@@ -170,20 +170,14 @@ static void log_show_early(struct rev_info *revs, struct commit_list *list)
 
 static void early_output(int signal)
 {
-	show_early_output = log_show_early;
+	show_early_output = 1;
 }
 
 static void setup_early_output(struct rev_info *rev)
 {
 	struct sigaction sa;
 
-	/*
-	 * Set up the signal handler, minimally intrusively:
-	 * we only set a single volatile integer word (not
-	 * using sigatomic_t - trying to avoid unnecessary
-	 * system dependencies and headers), and using
-	 * SA_RESTART.
-	 */
+	early_output_function = &log_show_early;
 	memset(&sa, 0, sizeof(sa));
 	sa.sa_handler = early_output;
 	sigemptyset(&sa.sa_mask);
diff --git a/revision.c b/revision.c
index 3ba6d99..62402fb 100644
--- a/revision.c
+++ b/revision.c
@@ -13,7 +13,8 @@
 #include "decorate.h"
 #include "log-tree.h"
 
-volatile show_early_output_fn_t show_early_output;
+sig_atomic_t show_early_output = 0;
+show_early_output_fn_t early_output_function = NULL;
 
 char *path_name(const struct name_path *path, const char *name)
 {
@@ -654,7 +655,6 @@ static int limit_list(struct rev_info *revs)
 		struct commit_list *entry = list;
 		struct commit *commit = list->item;
 		struct object *obj = &commit->object;
-		show_early_output_fn_t show;
 
 		list = list->next;
 		free(entry);
@@ -680,12 +680,10 @@ static int limit_list(struct rev_info *revs)
 		date = commit->date;
 		p = &commit_list_insert(commit, p)->next;
 
-		show = show_early_output;
-		if (!show)
-			continue;
-
-		show(revs, newlist);
-		show_early_output = NULL;
+		if (show_early_output) {
+			(*early_output_function)(revs, newlist);
+			show_early_output = 0;
+		}
 	}
 	if (revs->cherry_pick)
 		cherry_pick_list(newlist, revs);
diff --git a/revision.h b/revision.h
index a14deef..93a8ffc 100644
--- a/revision.h
+++ b/revision.h
@@ -135,7 +135,8 @@ struct rev_info {
 
 /* revision.c */
 typedef void (*show_early_output_fn_t)(struct rev_info *, struct commit_list *);
-extern volatile show_early_output_fn_t show_early_output;
+extern show_early_output_fn_t early_output_function;
+extern sig_atomic_t show_early_output;
 
 extern void init_revisions(struct rev_info *revs, const char *prefix);
 extern int setup_revisions(int argc, const char **argv, struct rev_info *revs, const char *def);
-- 
1.6.6.1
Previous: Daniel BarkalowNext: Shawn O. Pearce
Message 19 of 36 in “Fix signal handler”
  1. Markus ElfringFeb 2, 2010
  2. Jeff KingFeb 2, 2010
  3. Markus ElfringFeb 2, 2010
  4. Jeff KingFeb 2, 2010
  5. Markus ElfringFeb 3, 2010
  6. Jeff KingFeb 3, 2010
  7. Markus ElfringFeb 3, 2010
  8. Thomas RastFeb 3, 2010
  9. Markus ElfringFeb 3, 2010
  10. Shawn O. PearceFeb 3, 2010
  11. Andreas EricssonFeb 3, 2010
  12. Markus ElfringFeb 3, 2010
  13. Andreas EricssonFeb 4, 2010
  14. Jeff KingFeb 3, 2010
  15. Markus ElfringFeb 3, 2010
  16. Bill LearFeb 3, 2010
  17. Markus ElfringFeb 9, 2010
  18. Daniel BarkalowFeb 9, 2010
  19. Markus ElfringFeb 10, 2010
  20. Shawn O. PearceFeb 10, 2010
  21. Jeff KingFeb 10, 2010
  22. Jeff KingFeb 10, 2010
  23. Markus ElfringFeb 13, 2010
  24. Jeff KingFeb 14, 2010
  25. Junio C HamanoFeb 14, 2010
  26. Markus ElfringFeb 18, 2010
  27. Junio C HamanoFeb 18, 2010
  28. Markus ElfringFeb 19, 2010
  29. Markus ElfringFeb 22, 2010
  30. Junio C HamanoFeb 22, 2010
  31. Markus ElfringFeb 23, 2010
  32. Markus ElfringFeb 23, 2010
  33. Junio C HamanoFeb 23, 2010
  34. Markus ElfringFeb 24, 2010
  35. Andreas EricssonFeb 24, 2010
  36. Markus ElfringFeb 24, 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.