From mboxrd@z Thu Jan 1 00:00:00 1970 From: Jeff King Subject: [PATCH 3/5] launch_editor: ignore terminal signals while editor has control Date: Fri, 30 Nov 2012 17:41:26 -0500 Message-ID: <20121130224125.GC23772@sigill.intra.peff.net> References: <20121130223943.GA27120@sigill.intra.peff.net> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Cc: Junio C Hamano , Paul Fox , Krzysztof Mazur To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Fri Nov 30 23:41:45 2012 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TeZHE-0008PP-Ec for gcvg-git-2@plane.gmane.org; Fri, 30 Nov 2012 23:41:44 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754125Ab2K3Wl2 (ORCPT ); Fri, 30 Nov 2012 17:41:28 -0500 Received: from 75-15-5-89.uvs.iplsin.sbcglobal.net ([75.15.5.89]:47994 "EHLO peff.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754045Ab2K3Wl2 (ORCPT ); Fri, 30 Nov 2012 17:41:28 -0500 Received: (qmail 6993 invoked by uid 107); 30 Nov 2012 22:42:25 -0000 Received: from sigill.intra.peff.net (HELO sigill.intra.peff.net) (10.0.0.7) (smtp-auth username relayok, mechanism cram-md5) by peff.net (qpsmtpd/0.84) with ESMTPA; Fri, 30 Nov 2012 17:42:25 -0500 Received: by sigill.intra.peff.net (sSMTP sendmail emulation); Fri, 30 Nov 2012 17:41:26 -0500 Content-Disposition: inline In-Reply-To: <20121130223943.GA27120@sigill.intra.peff.net> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: From: Paul Fox The user's editor likely catches SIGINT (ctrl-C). but if the user spawns a command from the editor and uses ctrl-C to kill that command, the SIGINT will likely also kill git itself (depending on the editor, this can leave the terminal in an unusable state). Let's ignore it while the editor is running, and do the same for SIGQUIT, which many editors also ignore. This matches the behavior if we were to use system(3) instead of run-command. Signed-off-by: Paul Fox Signed-off-by: Jeff King --- editor.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/editor.c b/editor.c index 842f782..c892a81 100644 --- a/editor.c +++ b/editor.c @@ -1,6 +1,7 @@ #include "cache.h" #include "strbuf.h" #include "run-command.h" +#include "sigchain.h" #ifndef DEFAULT_EDITOR #define DEFAULT_EDITOR "vi" @@ -38,6 +39,7 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en if (strcmp(editor, ":")) { const char *args[] = { editor, path, NULL }; struct child_process p; + int ret; memset(&p, 0, sizeof(p)); p.argv = args; @@ -46,7 +48,12 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en if (start_command(&p) < 0) return error("unable to start editor '%s'", editor); - if (finish_command(&p)) + sigchain_push(SIGINT, SIG_IGN); + sigchain_push(SIGQUIT, SIG_IGN); + ret = finish_command(&p); + sigchain_pop(SIGINT); + sigchain_pop(SIGQUIT); + if (ret) return error("There was a problem with the editor '%s'.", editor); } -- 1.8.0.1.620.g558b0aa