From patchwork Thu Dec 2 03:54:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= X-Patchwork-Id: 12651641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DC4DC433F5 for ; Thu, 2 Dec 2021 03:55:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344813AbhLBD6c (ORCPT ); Wed, 1 Dec 2021 22:58:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235730AbhLBD6b (ORCPT ); Wed, 1 Dec 2021 22:58:31 -0500 Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E56F8C061574 for ; Wed, 1 Dec 2021 19:55:09 -0800 (PST) Received: by mail-qv1-xf2e.google.com with SMTP id g9so21895015qvd.2 for ; Wed, 01 Dec 2021 19:55:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uNEEq7W7acSxycuGcbjAK/bIbFVCQgh7WR5sYWIZb1U=; b=Bnd8R0HMWgU7LkIwu09QvcQM3wH0QxXRDhwarleLCHSoEZLl0WnJXp1KvBy96fmGU2 cQd8l49gvoOVynbKcg8zmwB2WjxVX2Qqrod8ZJCCOAQtefx1/WWjmO2So+6k7zCBPMkR NR/PQGxm6GfIhNE02Q7wzF+v+qZrbWsIlcswg3h9o5FUMiYGJsgkJtC/ebYGiT/Edulg mwqK/FRZxBYHaJZP3aKW4V1s509HxsAN6A3rYoAMjcirZ8zBv9pqGKCTT0Og00S66PBr mHn9X80t8gy8AfHTkAcGxxEkanUucgCjDroT9m/m+iJkp9zNWdO+G/ASEE4G5vcxdwS3 XPcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uNEEq7W7acSxycuGcbjAK/bIbFVCQgh7WR5sYWIZb1U=; b=RuCn0iUa1GdldisTxoeXu1d6kzGXP4f6JZr2h+Ov3350GKquCTxAaMB/iDozuh6fJo mDaQVsv7txeH4aS9WjYdxgOFTGSVh/AzgPFv/GqeiJd7VQpFr07RCzPZRmml2hx5sz7+ P1eWDBCXQQjPljjlOyXvZ01vC6rb5x54bgksGVfHhN7ZWqoJ/O5kgOJWtNfzZyzUyZjp tSNhoIt+wP0rSbZKj++Em6DvQKliL5pgQALid3h7spoAc3MEDMG1T6f9cXv+sJW/a7hN l4VSiZhb/yH5mVfKZj2C82jsLIkGwMWECvZ+gF/8yncoViiiBuLVXKVjbrDsr4L7YGfa 7DHw== X-Gm-Message-State: AOAM532rYcauZcjBn18ba+uiVS9z8scTMWEMloTqDI9z4ttMkoHllvpr o5VjiaSS36iAZoGzqD4lEs4h8R+Iybg= X-Google-Smtp-Source: ABdhPJzutgzOdM9kVYfspFBMPGfFgXXqL7CtDvWTWMr/ReIlN6SGsMpu+WszuLtarZAAqchzmSsAPQ== X-Received: by 2002:a0c:edb0:: with SMTP id h16mr10745614qvr.17.1638417309021; Wed, 01 Dec 2021 19:55:09 -0800 (PST) Received: from carlos-mbp.lan (104-1-92-200.lightspeed.sntcca.sbcglobal.net. [104.1.92.200]) by smtp.gmail.com with ESMTPSA id q20sm881949qkl.53.2021.12.01.19.55.08 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Dec 2021 19:55:08 -0800 (PST) From: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= To: git@vger.kernel.org Cc: gitster@pobox.com, chris.torek@gmail.com, phillip.wood@dunelm.org.uk, Johannes.Schindelin@gmx.de, =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= , Phillip Wood Subject: [RFC PATCH 1/3] terminal: teach save_term to fail when not foreground Date: Wed, 1 Dec 2021 19:54:44 -0800 Message-Id: <20211202035446.1154-2-carenas@gmail.com> X-Mailer: git-send-email 2.34.1.460.g364565cfab In-Reply-To: <20211202035446.1154-1-carenas@gmail.com> References: <20211202035446.1154-1-carenas@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org e22b245ea5 (terminal: teach git how to save/restore its terminal settings, 2021-10-05) allows external calls to the termios code, but kept the assumption that all operations were done with foreground processes, which was proven incorrect. Add a check to validate that the current process is indeed in the foreground and in control of the terminal and fail early if not the case. To avoid changing behaviour from the other users of save_term() the full_duplex parameter has been overloaded to restrict the new check to only future callers, as it is set to 0 for all current users. The detection is done in a helper function so it can be reused by all other functions that might benefit from it later, and once that is done that overloading might be unnecessary and cleaned up, but doing so has been punted from this series as it is not needed and might require backward incompatible changes. Helped-by: Phillip Wood Signed-off-by: Carlo Marcelo Arenas Belón --- compat/terminal.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/compat/terminal.c b/compat/terminal.c index 5b903e7c7e..509f2518d1 100644 --- a/compat/terminal.c +++ b/compat/terminal.c @@ -29,16 +29,31 @@ void restore_term(void) return; tcsetattr(term_fd, TCSAFLUSH, &old_term); + close(term_fd); term_fd = -1; } +static int is_controlling_terminal(int fd) +{ + return (getpgid(0) == tcgetpgrp(fd)); +} + int save_term(int full_duplex) { if (term_fd < 0) term_fd = open("/dev/tty", O_RDWR); - return (term_fd < 0) ? -1 : tcgetattr(term_fd, &old_term); + if (term_fd < 0) + return -1; + + if (full_duplex && !is_controlling_terminal(term_fd)) { + close(term_fd); + term_fd = -1; + return -1; + } + + return tcgetattr(term_fd, &old_term); } static int disable_bits(tcflag_t bits) From patchwork Thu Dec 2 03:54:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= X-Patchwork-Id: 12651643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C0894C433EF for ; Thu, 2 Dec 2021 03:55:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344945AbhLBD6d (ORCPT ); Wed, 1 Dec 2021 22:58:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344727AbhLBD6c (ORCPT ); Wed, 1 Dec 2021 22:58:32 -0500 Received: from mail-qv1-xf2a.google.com (mail-qv1-xf2a.google.com [IPv6:2607:f8b0:4864:20::f2a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6EBDC061574 for ; Wed, 1 Dec 2021 19:55:10 -0800 (PST) Received: by mail-qv1-xf2a.google.com with SMTP id kl8so23842216qvb.3 for ; Wed, 01 Dec 2021 19:55:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9FYLX1ebTnBu7jT15Sukm9S6hJVlYNZuw/4hUkk9JnM=; b=l+Fom5GE2Y+VU/NEwmj7tOWEtPJNHmDuqFkrDbU9+BPXnTDqFwzlvnfljepHJknF+7 +sE8+Sn0JpyLdS+jVFNE4JR+KkNtsheNsXpeZNly9eR6D2FZfl0HN5I3Cw3gm/MUBEAd mQbVwXgAZfgfhjbBjOs2yzQSh6uQL3VGRUEiIFtFKZoUkbQNhcmVV0JD6TDTc3QMQqtP o9NQPpwPwo2ryiFsIZA2OdX3TejAiL0lRlzY7MP2bGIYq3AumnitngX5XqWcNpmFY0la BDaZ6DljC9dKLsN/LRGz+18oMRa/MvTCAUXTMrVkZhi1m67C+YaGIOrZcGEKc8dUY8RN TIPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9FYLX1ebTnBu7jT15Sukm9S6hJVlYNZuw/4hUkk9JnM=; b=MPm9rguSZb2aInxVVwpdrBaYJAwXrIAuvHZsG4ghOjnfreWdKbRPdWF8LCpuEDchnn N7OBmbBsMvLRX+WTf37aj+vF7+FrDLG9b/cb/+kj6aJKFXNBgBR8Ryarm9V055gUcZ6w zxFK6sZW/yKOYA6G1YGzo1Y3Mbm6lnO+yRKb96QnHTFabxav0KGt87OvLzqTQ2q0FqDT NmwH0yro2IAqDXwsqgJJbs57/6f1TcXXlB3BvA7YS3SJJ7eqqio5fdHxUfLc+/oio8zq z9PnKvW06JwwUTw8tNvaATtH4vloqj0/21DcmPTqY6151a5pGikF1AMGJWwK41jkB7Ir dW8A== X-Gm-Message-State: AOAM53175WUkkO3dStVIZsi7j3uz3ReSqj4TEfr2/wFjbM11r88Yx1Wf rP/a7ZE3M/g3HW7m76OCGp696tgeOgU= X-Google-Smtp-Source: ABdhPJyHeYhb9osJC2gK9wgF9pVnZ+CHAn7kgTQ/m7gB7WvxFjisPE4vJbKUa16Q5FQMKMow0OoGPg== X-Received: by 2002:a05:6214:27cd:: with SMTP id ge13mr10718099qvb.81.1638417309962; Wed, 01 Dec 2021 19:55:09 -0800 (PST) Received: from carlos-mbp.lan (104-1-92-200.lightspeed.sntcca.sbcglobal.net. [104.1.92.200]) by smtp.gmail.com with ESMTPSA id q20sm881949qkl.53.2021.12.01.19.55.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Dec 2021 19:55:09 -0800 (PST) From: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= To: git@vger.kernel.org Cc: gitster@pobox.com, chris.torek@gmail.com, phillip.wood@dunelm.org.uk, Johannes.Schindelin@gmx.de Subject: [RFC PATCH 2/3] editor: allow for saving/restoring terminal state Date: Wed, 1 Dec 2021 19:54:45 -0800 Message-Id: <20211202035446.1154-3-carenas@gmail.com> X-Mailer: git-send-email 2.34.1.460.g364565cfab In-Reply-To: <20211202035446.1154-1-carenas@gmail.com> References: <20211202035446.1154-1-carenas@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Junio C Hamano When EDITOR is invoked to modify a commit message (or do some other editing), and it is a terminal mode editor, it will need to change the terminal settings, and if it misbehaves could leave the terminal output damaged as shown in recent reports from Windows Terminal[1] Instead use the functions provided by compat/terminal to save the settings of the terminal and recover safely, but only do so if the editor is known to have issues and unless the user has told us through a boolean configuration "editor.stty" that it is safe not to do so. [1] https://github.com/microsoft/terminal/issues/9359 --- The commit message was contributed by me, but the rest comes from: https://lore.kernel.org/git/xmqq7dcnyh5o.fsf@gitster.g/ Signed-of-by is missing as I didn't know what would be preferred or if the Author will be ok with my grammar (ginger free grammar check seems to approve, otherwise) editor.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/editor.c b/editor.c index fdd3eeafa9..70d3f80966 100644 --- a/editor.c +++ b/editor.c @@ -3,6 +3,7 @@ #include "strbuf.h" #include "run-command.h" #include "sigchain.h" +#include "compat/terminal.h" #ifndef DEFAULT_EDITOR #define DEFAULT_EDITOR "vi" @@ -47,6 +48,16 @@ const char *git_sequence_editor(void) return editor; } +static int prepare_term(const char *editor) +{ + int need_saverestore = !strcmp(editor, "vi"); + + git_config_get_bool("editor.stty", &need_saverestore); + if (need_saverestore) + return save_term(1); + return 0; +} + static int launch_specified_editor(const char *editor, const char *path, struct strbuf *buffer, const char *const *env) { @@ -57,7 +68,7 @@ static int launch_specified_editor(const char *editor, const char *path, struct strbuf realpath = STRBUF_INIT; const char *args[] = { editor, NULL, NULL }; struct child_process p = CHILD_PROCESS_INIT; - int ret, sig; + int ret, sig, need_restore = 0; int print_waiting_for_editor = advice_enabled(ADVICE_WAITING_FOR_EDITOR) && isatty(2); if (print_waiting_for_editor) { @@ -83,7 +94,10 @@ static int launch_specified_editor(const char *editor, const char *path, p.env = env; p.use_shell = 1; p.trace2_child_class = "editor"; + need_restore = prepare_term(editor); if (start_command(&p) < 0) { + if (need_restore) + restore_term(); strbuf_release(&realpath); return error("unable to start editor '%s'", editor); } @@ -91,6 +105,8 @@ static int launch_specified_editor(const char *editor, const char *path, sigchain_push(SIGINT, SIG_IGN); sigchain_push(SIGQUIT, SIG_IGN); ret = finish_command(&p); + if (need_restore) + restore_term(); strbuf_release(&realpath); sig = ret - 128; sigchain_pop(SIGINT); From patchwork Thu Dec 2 03:54:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= X-Patchwork-Id: 12651645 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70462C433EF for ; Thu, 2 Dec 2021 03:55:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344893AbhLBD6f (ORCPT ); Wed, 1 Dec 2021 22:58:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344898AbhLBD6d (ORCPT ); Wed, 1 Dec 2021 22:58:33 -0500 Received: from mail-qk1-x72b.google.com (mail-qk1-x72b.google.com [IPv6:2607:f8b0:4864:20::72b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D541AC06174A for ; Wed, 1 Dec 2021 19:55:11 -0800 (PST) Received: by mail-qk1-x72b.google.com with SMTP id p4so33400928qkm.7 for ; Wed, 01 Dec 2021 19:55:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LjiJx955ZP2V7dqt5u7thbYPtiTiaCYCRLRS/UYIR28=; b=qCq554BeWNnQOB9IaD4dDM6/sZtt+cVN3OoBGhPIN3KUm92U+bqRCk7CB8HSso69nH DDMIkKkp6oIy6KkZLAxNjGAeCakInmLcfC8U092P/a1E2bd7gyhM0haKToPD4ouYT/nS pTetUtK0ipZ2eoHkHMC4cG64CJYCuXf71jydowLBRjApAoRfz8SyWVHsVNdsEPAVc13h dyf/nR0mRhZrEAubU046+mRNR8VNdZnD/TJ7dJuqAiEFeIyf4LPSYCPaMSO+oKttadsz K9+D7Ay3Z2etadK0ofZxgAlEIkc/ys131NanNMdsiiD7mpMQjlp1UIwkncI4E5GCnFZw hP0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LjiJx955ZP2V7dqt5u7thbYPtiTiaCYCRLRS/UYIR28=; b=NMyy5vyBxVPGptSAON1YFN74N+ult/5w7qAae/u7UIn2BlWRrMxx5yfDQpap9EB7W1 b6W/FlJBf0Zxuw2wsw77wTztpFjr4o+naaBq7JX++33LH3+3BRrqG2V2VzDyf7ZuUFke O4PgKdov8V1Z8Rd973TFBDHBv2FjHzelIM2Q1Y+gcIWOUPQbORImRBUvCGC2ARUZopNo CE5ZGOFxSzw0AmAidbtN3x8r9yyefMzFleyo4zokw1x9pxcLccykojvOz3oshQ6L193A 8CA5jAF+ZlEsFFA/aRbwmJNk3N8st5V+FUJk3bHj/4+oIIENCVgN4/PpFsz3HdKKsJRE udSA== X-Gm-Message-State: AOAM533Me/3XmZpD9MRyeF6FL8RZEAm++hMn/2vD4jFS+dSaww6x53Sz GHaf7M0xDAw+UNeJoEvg0RAJeI4Qtao= X-Google-Smtp-Source: ABdhPJxxEke+RRIcjhuxfzirXfIe8O983R8iJ1WD53MrcfYF4AzUSN6OWItL0cTuDYCI2p4MgiOrtQ== X-Received: by 2002:a37:8d86:: with SMTP id p128mr10331727qkd.706.1638417310952; Wed, 01 Dec 2021 19:55:10 -0800 (PST) Received: from carlos-mbp.lan (104-1-92-200.lightspeed.sntcca.sbcglobal.net. [104.1.92.200]) by smtp.gmail.com with ESMTPSA id q20sm881949qkl.53.2021.12.01.19.55.10 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 01 Dec 2021 19:55:10 -0800 (PST) From: =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= To: git@vger.kernel.org Cc: gitster@pobox.com, chris.torek@gmail.com, phillip.wood@dunelm.org.uk, Johannes.Schindelin@gmx.de, =?utf-8?q?Carlo_Marcelo_Arenas_Bel=C3=B3n?= Subject: [RFC PATCH 3/3] fixup! editor: allow for saving/restoring terminal state Date: Wed, 1 Dec 2021 19:54:46 -0800 Message-Id: <20211202035446.1154-4-carenas@gmail.com> X-Mailer: git-send-email 2.34.1.460.g364565cfab In-Reply-To: <20211202035446.1154-1-carenas@gmail.com> References: <20211202035446.1154-1-carenas@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Use DEFAULT_EDITOR instead of another hardcoding of "vi". Do a minor refactoring to avoid having to call isatty(2) twice, and while at it, a related reformatting that avoids an overlong line. Only check if we should enable saving/restoring the terminal if the session is interactive. Add documentation for the configuration variable. Signed-off-by: Carlo Marcelo Arenas Belón --- All of the commit message is meant to be thrown away once/if this is squashed into the previous commit. Signed-off-by could be transformed into a Helped-by if anything could be of use here otherwise. Documentation/config.txt | 2 ++ Documentation/config/editor.txt | 8 ++++++++ editor.c | 10 ++++++---- 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 Documentation/config/editor.txt diff --git a/Documentation/config.txt b/Documentation/config.txt index 1167e88e34..342f3cc183 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -361,6 +361,8 @@ include::config/diff.txt[] include::config/difftool.txt[] +include::config/editor.txt[] + include::config/extensions.txt[] include::config/fastimport.txt[] diff --git a/Documentation/config/editor.txt b/Documentation/config/editor.txt new file mode 100644 index 0000000000..b65c2810fa --- /dev/null +++ b/Documentation/config/editor.txt @@ -0,0 +1,8 @@ +editor.stty:: + A boolean variable that tells git to save and restore its + terminal settings when the editor is invoked, to avoid + being affected by garbled input/output, if it misbehaves. ++ +It defaults to 'true' if your editor is "vi" (which is +also the default if there is no `core.editor`), or to +'false' otherwise. diff --git a/editor.c b/editor.c index 70d3f80966..12180039d2 100644 --- a/editor.c +++ b/editor.c @@ -50,7 +50,7 @@ const char *git_sequence_editor(void) static int prepare_term(const char *editor) { - int need_saverestore = !strcmp(editor, "vi"); + int need_saverestore = !strcmp(editor, DEFAULT_EDITOR); git_config_get_bool("editor.stty", &need_saverestore); if (need_saverestore) @@ -68,8 +68,10 @@ static int launch_specified_editor(const char *editor, const char *path, struct strbuf realpath = STRBUF_INIT; const char *args[] = { editor, NULL, NULL }; struct child_process p = CHILD_PROCESS_INIT; - int ret, sig, need_restore = 0; - int print_waiting_for_editor = advice_enabled(ADVICE_WAITING_FOR_EDITOR) && isatty(2); + int ret, sig, need_restore; + int is_interactive = isatty(2); + int print_waiting_for_editor = advice_enabled(ADVICE_WAITING_FOR_EDITOR) && + is_interactive; if (print_waiting_for_editor) { /* @@ -94,7 +96,7 @@ static int launch_specified_editor(const char *editor, const char *path, p.env = env; p.use_shell = 1; p.trace2_child_class = "editor"; - need_restore = prepare_term(editor); + need_restore = is_interactive ? prepare_term(editor) : 0; if (start_command(&p) < 0) { if (need_restore) restore_term();