From: Dmitry Potapov <dpotapov@gmail.com>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>, Johannes Sixt <j6t@kdbg.org>,
Joey Hess <joey@kitenet.net>
Subject: RFC: [PATCH] ignore SIGINT&QUIT while waiting for external command
Date: Tue, 19 Oct 2010 15:59:43 +0400 [thread overview]
Message-ID: <20101019115943.GA8065@dpotapov.dyndns.org> (raw)
In-Reply-To: <AANLkTi=tvyzyz2xpezufHLFc44HDbtMibkhNEvYxPB2g@mail.gmail.com>
Before git 1.6.4, we used execvp to run external git dashed commands,
thus git did not return until this command is finished. With switching to
run_command (which was necessary to fix a pager issue; see d8e96fd86d4),
CTRL-C could cause that git returned before than the git dashed command is
finished.
The solution is to disable SIGINT and SIGQUIT as it is normally done by
system(). Disabling these signals is done only when silent_exec_failure
is set, which means that the current process is used as a proxy to run
another command.
Signed-off-by: Dmitry Potapov <dpotapov@gmail.com>
---
run-command.c | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/run-command.c b/run-command.c
index 2a1041e..14af035 100644
--- a/run-command.c
+++ b/run-command.c
@@ -93,6 +93,10 @@ static inline void set_cloexec(int fd)
fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
}
+#ifndef WIN32
+static sighandler_t sigint, sigquit;
+#endif
+
static int wait_or_whine(pid_t pid, const char *argv0, int silent_exec_failure)
{
int status, code = -1;
@@ -102,6 +106,13 @@ static int wait_or_whine(pid_t pid, const char *argv0, int silent_exec_failure)
while ((waiting = waitpid(pid, &status, 0)) < 0 && errno == EINTR)
; /* nothing */
+#ifndef WIN32
+ if (silent_exec_failure) {
+ /* Restore signal handlers */
+ signal(SIGINT, sigint);
+ signal(SIGQUIT, sigquit);
+ }
+#endif
if (waiting < 0) {
failed_errno = errno;
error("waitpid for %s failed: %s", argv0, strerror(errno));
@@ -202,8 +213,16 @@ fail_pipe:
notify_pipe[0] = notify_pipe[1] = -1;
fflush(NULL);
+ if (cmd->silent_exec_failure) {
+ sigint = signal(SIGINT, SIG_IGN);
+ sigquit = signal(SIGQUIT, SIG_IGN);
+ }
cmd->pid = fork();
if (!cmd->pid) {
+ if (cmd->silent_exec_failure) {
+ signal(SIGINT, sigint);
+ signal(SIGQUIT, sigquit);
+ }
/*
* Redirect the channel to write syscall error messages to
* before redirecting the process's stderr so that all die()
--
1.7.3.1
next prev parent reply other threads:[~2010-10-19 11:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-19 4:53 git subcommand sigint gotcha Joey Hess
2010-10-19 9:55 ` Dmitry Potapov
2010-10-19 11:59 ` Dmitry Potapov [this message]
2010-10-19 13:32 ` RFC: [PATCH] ignore SIGINT&QUIT while waiting for external command Jeff King
2010-10-19 13:40 ` Jeff King
2010-10-19 19:16 ` Jonathan Nieder
2010-10-19 19:50 ` Jeff King
2010-10-19 21:06 ` Jakub Narebski
2010-10-19 21:07 ` Jonathan Nieder
2010-10-19 16:31 ` Dmitry Potapov
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=20101019115943.GA8065@dpotapov.dyndns.org \
--to=dpotapov@gmail.com \
--cc=git@vger.kernel.org \
--cc=j6t@kdbg.org \
--cc=joey@kitenet.net \
--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).