From patchwork Tue Feb 7 19:33:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 13132067 X-Patchwork-Delegate: herbert@gondor.apana.org.au 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 07799C636CC for ; Tue, 7 Feb 2023 19:33:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231964AbjBGTdz (ORCPT ); Tue, 7 Feb 2023 14:33:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231890AbjBGTdr (ORCPT ); Tue, 7 Feb 2023 14:33:47 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2E5DB3CE2A for ; Tue, 7 Feb 2023 11:33:32 -0800 (PST) Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 5E7E2168C; Tue, 7 Feb 2023 20:33:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202211; t=1675798411; bh=oG85JYBGvLuuf1f9mnO1Hi0KC6QwnxIWND62LdFm5YM=; h=Date:From:To:Subject:References:In-Reply-To:From; b=MTsGBSNvbWymwlR9Ok6vZ9koUNk122Gt6GjTSDh0baTUoAlmuS7hEyGmZqXb6Dmqs OpqEpmWHFNL7lqO1DAclYNnpWgYiuy4uUR46WqE803jfsP+10AQujqd8sop4zH41qN JUb5qDceZbB1rgbAjQ8E5MxO5zcRu/sZKezvrhMvYnS12ipsh/tCkKbq3YXm97Thqj RKjVEnjsJVjEsL4g+FBM2+eBec755xoU4cZyHJJIZg5gsI/MxCfq0S9EWMDQQMEz87 /UYcbt5XUK56bw/QzejfJ0/ZdNnRoGjkNl1jATwWTgicAZtxj4yscC+s0KNEzfcwg1 H3td1uF5yjKaQ== Date: Tue, 7 Feb 2023 20:33:30 +0100 From: =?utf-8?b?0L3QsNCx?= To: Harald van Dijk , dash@vger.kernel.org Subject: [PATCH 2/6] fc -s: don't loop forever when executing the latest entry Message-ID: <7166822efa32d227a28d86bd1fb505f09bb7cf0c.1675798292.git.nabijaczleweli@nabijaczleweli.xyz> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20220429 Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org Quoting CVS comment: Ensure [...] that we break out of the loop after executing it. With the previous code, because the re-executed command was added to the history, it would think that it still had to execute it, leading to an infinite loop. The last thing which differs from ksh is that we get the "fc -s" command into the history, but this is actually rather a feature in my humble opinion. POSIX disagrees: [W]hen the -l option is not specified, the resulting lines shall be entered at the end of the history list and then re-executed by sh. The fc command that caused the editing shall not be entered into the history list. But this is a separate issue, since even without -s dash puts fc into the history (i.e. id; ls; fc 1 2; fc -l; yields 1=id, 2=ls, 3=fc -l). Test cases: $ id uid=1000(nabijaczleweli) gid=100(users) groups=100(users) $ fc -s 1 id uid=1000(nabijaczleweli) gid=100(users) groups=100(users) $ fc -l 1 id 2 fc -s 1 3 id -- >8 -- $ ls autogen.sh ChangeLog ... $ id uid=1000(nabijaczleweli) gid=100(users) groups=100(users) $ fc -s -1 id uid=1000(nabijaczleweli) gid=100(users) groups=100(users) -- >8 -- $ ls autogen.sh ChangeLog ... $ id uid=1000(nabijaczleweli) gid=100(users) groups=100(users) $ fc -s -2 ls autogen.sh ChangeLog ... -- >8 -- $ ls autogen.sh ChangeLog ... $ id uid=1000(nabijaczleweli) gid=100(users) groups=100(users) $ fc -s -2 ls autogen.sh ChangeLog ... $ id 1 uid=1(daemon) gid=1(daemon) groups=1(daemon) $ id 2 uid=2(bin) gid=2(bin) groups=2(bin) $ fc -s 3 fc -s -2 id 1 uid=1(daemon) gid=1(daemon) groups=1(daemon) $ fc -l 1 ls 2 id 3 fc -s -2 4 ls 5 id 1 6 id 2 7 fc -s 3 8 id 1 -- >8 -- $ id 1 uid=1(daemon) gid=1(daemon) groups=1(daemon) $ fc -s 2 fc -s 2 fc -s 2 fc -s 2 fc -s 2 src/dash: 1: fc: called recursively too many times and I'm happy to call this "behaving exactly as I expected when I was typing it in", so removing the XXX. Adapted-from: NetBSD src bin/sh/histedit.c rev 1.38 by aymeric@ --- src/histedit.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/histedit.c b/src/histedit.c index fc87283..28956ec 100644 --- a/src/histedit.c +++ b/src/histedit.c @@ -382,12 +382,10 @@ histcmd(int argc, char **argv) evalstring(s, 0); if (displayhist && hist) { - /* - * XXX what about recursive and - * relative histnums. - */ history(hist, &he, H_ENTER, s); } + + break; } else fputs(s, efp); }