git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Markus Elfring <Markus.Elfring@web.de>
To: Junio C Hamano <gitster@pobox.com>
Cc: Jeff King <peff@peff.net>, git@vger.kernel.org
Subject: Re: [PATCH] Fix a signal handler
Date: Mon, 22 Feb 2010 13:10:51 +0100	[thread overview]
Message-ID: <4B82744B.4060805@web.de> (raw)
In-Reply-To: <7veikib96d.fsf@alter.siamese.dyndns.org>

> Of are you asking me if I'd apply your patch if you send a polished update,
> and asking me to decide it before seeing the patch?

Would you like to pick this source code adjustment up?

Regards,
Markus

---
From e138904a08ceaf469fa2f4d0ec87b5891be14760 Mon Sep 17 00:00:00 2001
From: Markus Elfring <Markus.Elfring@web.de>
Date: Mon, 22 Feb 2010 11:53:35 +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.

Signed-off-by: Markus Elfring <Markus.Elfring@web.de>

---
 builtin-log.c |   10 ++--------
 revision.c    |   14 ++++++--------
 revision.h    |    3 ++-
 3 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/builtin-log.c b/builtin-log.c
index e0d5caa..beccf7f 100644
--- a/builtin-log.c
+++ b/builtin-log.c
@@ -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.7.0

  parent reply	other threads:[~2010-02-22 12:11 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-02 16:14 Fix signal handler Markus Elfring
2010-02-02 20:58 ` Jeff King
2010-02-02 21:44   ` Markus Elfring
2010-02-02 22:32     ` Jeff King
2010-02-03 10:20       ` Markus Elfring
2010-02-03 10:29         ` Jeff King
2010-02-03 11:55           ` Markus Elfring
2010-02-03 13:12             ` Thomas Rast
2010-02-03 15:46               ` Markus Elfring
2010-02-03 15:52                 ` Shawn O. Pearce
2010-02-03 15:53                 ` Andreas Ericsson
2010-02-03 16:24                   ` Markus Elfring
2010-02-04  7:23                     ` Andreas Ericsson
2010-02-03 15:17             ` Jeff King
2010-02-03 16:04               ` Markus Elfring
2010-02-03 16:26                 ` Bill Lear
2010-02-09 18:01   ` Markus Elfring
2010-02-09 23:49     ` Daniel Barkalow
2010-02-10 17:08     ` [PATCH] " Markus Elfring
2010-02-10 17:14       ` Shawn O. Pearce
2010-02-10 17:35         ` Jeff King
2010-02-10 17:33       ` Jeff King
2010-02-13 13:30         ` Markus Elfring
2010-02-14  6:47           ` Jeff King
2010-02-14 10:19             ` Junio C Hamano
2010-02-18 16:31               ` Markus Elfring
2010-02-18 20:06                 ` Junio C Hamano
2010-02-19 11:05                   ` Markus Elfring
2010-02-22 12:10                   ` Markus Elfring [this message]
2010-02-22 18:31                     ` [PATCH] Fix a " Junio C Hamano
2010-02-23  8:55                       ` Markus Elfring
2010-02-23  9:10                         ` Markus Elfring
2010-02-23 21:48                         ` Junio C Hamano
2010-02-24 10:38                           ` Markus Elfring
2010-02-24 10:51                             ` Andreas Ericsson
2010-02-24 11:08                           ` Markus Elfring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4B82744B.4060805@web.de \
    --to=markus.elfring@web.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).