From mboxrd@z Thu Jan 1 00:00:00 1970 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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D0276C4332F for ; Mon, 21 Nov 2022 16:32:24 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 68C0E85071; Mon, 21 Nov 2022 17:32:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=digi.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=digi.com header.i=@digi.com header.b="P1mx9GV8"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3E6B08536B; Mon, 21 Nov 2022 17:32:21 +0100 (CET) Received: from outbound-ip23a.ess.barracuda.com (outbound-ip23a.ess.barracuda.com [209.222.82.205]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 8C975806EE for ; Mon, 21 Nov 2022 17:32:15 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=digi.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=Hector.Palacios@digi.com Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2100.outbound.protection.outlook.com [104.47.58.100]) by mx-outbound9-135.us-east-2a.ess.aws.cudaops.com (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 21 Nov 2022 16:32:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OvpYcSu2r1mjHXMqJGdSt1rvqvXwCcl6GlIshDWjEXIH3HhkNTHjhEsWRjKbaYeOHsGwgjAALnEoD7fXN7/UjLRjCarFyrELzzukCpoaT++CqfREoajrwxYS3N1a3gFRXkMhKPn0EOyDzjq3tfV7yIscMRwTusl4VqNMsyMgFWM0FY6rF9EHs8aKBShL0s1MxDKCIMnbmj8wTiEFvmjHbmt1ufn3wTln0O+cb+61G+QE6NbcbI80IgFzZGvgi6gE+M/jt2jxe8/D5+pMt7IW7hQ/W5VbawOO4OxW09Kzh3rsUgpoStjaFeStPbNAE3g7vSZ1G6YO3pY4Dth+MxJDrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=hkt4IJ6P+VB5Mt3LNV+wUu4gNDA+hFazWu/7oi1DAx0=; b=hByb7FBV8yszQqoYj9J6yBmhLNAZu/wGskQtuJSV8ewQ9/av0ZEOkNrVbq4t428qRmL4J0nmR7s2WR/0bm51J7ZWyFCuFV66iFXbACTw/rVC1H9VBT4Hp2FLmr++NiARN4eIDcwGQiqG5TzhrfgSUsUte4E+oNCS/gOVdg/fhy69mBOK8ePXSvx1lnsSxhLZd8TUdlQ1dhLKyQaL0XygUDa0z2vMwJgqmk222YjYxml5rEpUVu+g+YgGj9K673gk0epkGX2XDmHiqrsKXvBo8240dpCM6Dhfh7aNif0hNwJ94cps0m9WU6XE9BVhMwN/9f76TnwWBT9ItLZYWD2maQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=digi.com; dmarc=pass action=none header.from=digi.com; dkim=pass header.d=digi.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digi.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hkt4IJ6P+VB5Mt3LNV+wUu4gNDA+hFazWu/7oi1DAx0=; b=P1mx9GV8ZG/9i/6xcp5KQCTv6f+6Z3j4LNF81inedf1F51pBAinc0Tah3reslCweqvh+EffInrUjGxy455BHzKW8Jd7wrYkS3f+VYc9kaVD+rQUUjKtQAC/SUbU/fnHB7u8LvoIONzbJ2ag8BZ1uH87ixYB9lBij9/zAp4CllQNXn7o4u7BQVYl0h5vYWuOWrUVPkeAHHiUDqqbqeRsKhe3WkpmOCdn7i3zmwlSgP7dekIB8NSjMq3lkEBBGZPRWztgVuEnOiFg4oZvYiXoYm3Xe1V96YRnTTal09yg7RfKe3D2jYsyHGH94g1IYFBvO5pKIUFW/NVY+HxfQhJW2Tw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=digi.com; Received: from BY5PR10MB4370.namprd10.prod.outlook.com (2603:10b6:a03:20b::19) by BN0PR10MB4951.namprd10.prod.outlook.com (2603:10b6:408:117::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.15; Mon, 21 Nov 2022 16:32:10 +0000 Received: from BY5PR10MB4370.namprd10.prod.outlook.com ([fe80::58c8:8cc0:212:ce2f]) by BY5PR10MB4370.namprd10.prod.outlook.com ([fe80::58c8:8cc0:212:ce2f%3]) with mapi id 15.20.5834.015; Mon, 21 Nov 2022 16:32:09 +0000 Message-ID: <8299f0ef-cdd4-e7fe-56ea-0458e87d4de4@digi.com> Date: Mon, 21 Nov 2022 17:32:04 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH] cli_hush: fix 'exit' cmd that was not exiting scripts Content-Language: en-US From: Hector Palacios To: Marek Vasut , u-boot@lists.denx.de Cc: festevam@gmail.com References: <20221118111937.24531-1-hector.palacios@digi.com> <3825c799-3c82-378a-5133-2f7c584e58d9@denx.de> Organization: Digi In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: CH0P223CA0008.NAMP223.PROD.OUTLOOK.COM (2603:10b6:610:116::19) To BY5PR10MB4370.namprd10.prod.outlook.com (2603:10b6:a03:20b::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BY5PR10MB4370:EE_|BN0PR10MB4951:EE_ X-MS-Office365-Filtering-Correlation-Id: e09eee88-d4ab-49de-3109-08dacbddefaa X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VYM7DHHCbThfbyQ6S0qjMg65Mc22hKWeX1p0BeFwrG/DZrC8OCtRvzAJDfVa51D0mv/uk909P7PiV9AL6R2IDGpM8A1l07929VjkYwVDZmjO8JOCzgd/OlzMZE3U4LrvQlLGwkGOldf0dvV2DsDCqt03Zk7sos9k9bvrb7uItmjbFikFT2L5mmdHjqQw4jmpy0493DCgb+dvhfnkjfNiSjAS3GS2sN5WD5RvJ1qCzcwrYXNWg6h+21dqg9Fd9nGt77fYw8Mc2INHHLiNo21y14h69CZwBMwAyZG68uTHFsj2YybNZ62fAIRD2ZtPwUPzdVQt7fl2LhoudBlTOEX67oOMz/rdDGg4Qu4AxMNGNsbpkQXbzaTUJe4ny8W18pf/Ur4If0H3Sq1JNzxynE1h8muG4hKM4Bl4FMZ+HuHmdtsMTl5pCh+a/p/GxKIPCe19NjAeLZ2e7/wOLQ2CFZmEu0GFNN7wnXw7NaJuoq33isGQexDtJ4iIyvL9ruhn1Ry4uCee0OSgGp5UbTZze6UXwMQGBsTOKvQKIDF02tMqp6k5EMHx3EnXkWjQsehDYXRgKgG92o//HCZ50HexbRt2Ser8MxCIRV/6L0zhL8E251vcKoYHKxWNZeApXy38/n6Ppbyp2zPZ7MEnH7XOoEi5jERQaoMmehK+GaXwSuJWB/X7Kw+4ftJ7PyfKqSNIyRy89V/5k2s5ce+//G5KXnBo6HZjfTslpFwYDQzBHVYyToU= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BY5PR10MB4370.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(376002)(366004)(396003)(346002)(39850400004)(136003)(451199015)(86362001)(31696002)(36756003)(4326008)(53546011)(41300700001)(66946007)(2616005)(66556008)(66574015)(66476007)(186003)(36916002)(5660300002)(8676002)(8936002)(6486002)(6666004)(478600001)(26005)(6512007)(316002)(44832011)(38100700002)(6506007)(83380400001)(2906002)(31686004)(45980500001)(43740500002); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?aUJUVm82VFA4QW11Z2gzV0x1TTZSSjV5SkpsRzVLakdCVkJTQXJOV3k0Ulkx?= =?utf-8?B?REhnVVgzN1NmK2pZNVlCbzBQTkRJa1NsckQzcVNGU0VNTVI1aFdGQVBLN09X?= =?utf-8?B?bmQ1VW1xNWQ2R3JTcmlFQXB6U3luallrR3d3R2VUcEZ0cFdUUHA2b01Ca0NJ?= =?utf-8?B?dEsxWU1vajltZ0U4UDlIV1FnYmVGRVdHbU9vTmtvVytYWkE1d21hMkRNenUv?= =?utf-8?B?ci90akZqbW1EOWo2eUp2ajZkUS9yRW5iV0gzdklaWHBXbXJnMHhab3dyamp6?= =?utf-8?B?TVhhdTRHR25ZQzRCWVVLYVpndmhWSVljMXJsclR2RXI0QmZVc0xuK1V4SVlH?= =?utf-8?B?bCtXZTVqNUNtNU5uK2h4SzVRakdrYWtkL3BocHJhU3FYMVJYbjBPVHRhNXBo?= =?utf-8?B?RFMyNmJmR25OUXp3aWRDeE8zc1VrU3g2WjFoVnEwR2NrUzlickZFTjc4QzlR?= =?utf-8?B?RVo1YUV0UWxrekY1dn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?ZzdBM3haZnBBTmM0dkN4MThZNUJxdG8wQWMvQzNjM3ZMeko3VjdJL2Zxazhn?= =?utf-8?B?YkxRekI2TUNvWTk4WVZDZFFad2pRWnVnWWszZkdrWTJMei8venFhaXJITFY5?= =?utf-8?B?NGtGWHRIYWlBS1dUS2NLNCtkejBpMkFIenh4YVE3Ty93T2c2VmlPQzVPQVF0?= =?utf-8?B?QmQxRmM1L0NmbFVCZUc5VWM1alRqMnN1NWR6MnZrZjFIRW9mL1dwbkMwR1ZB?= =?utf-8?B?R3BrL3gxKzdLY0FuOUI5L3ZtMHJvK2tLdDV6b1NjMVo3SUpId1drem5rWkt4?= =?utf-8?B?am5GSzhCSVJQTnZ2OGNEUmM4Wm1yVjhwWUxiZ1JJV3plcDlnRlJBOTVJLzFR?= =?utf-8?B?b3MvVnFYZHFVeUJaVUc3Z3dqcXd4bUk3UlBwTzd6MmRjSWtoWjdqKzJyYWgw?= =?utf-8?B?MVE3K3V0dmFDaHRJSEpwRVpZVFM3WStyOVkvRFMvMzdNNUcrU1k1T3RueFpG?= =?utf-8?B?VExxcFFtR0w4aVpyRFdpNkhLcU9XeDVsbmdUdkIxaU1zMmRidE9FM0drckpk?= =?utf-8?B?cThEYjZMd2xPMlZseW1Ya3pXWXgyRGI2T3lSaUcvWEtDZlBsTHArRGphR290?= =?utf-8?B?Rmc1dFlvTlcrTld3REs2WG45bVo0RzdpRlNmUzZ6bndrd1Fvem1US0VvNzdR?= =?utf-8?B?c2lTTzBkbzJ0Vll6WUV3aWkycDNHMjQ2eElWc3pPZTM2THAvcW5uRUUwb2NB?= =?utf-8?Q?IzkD5mDqEnOxdqgZY0f25jYIB?= X-OriginatorOrg: digi.com X-MS-Exchange-CrossTenant-Network-Message-Id: e09eee88-d4ab-49de-3109-08dacbddefaa X-MS-Exchange-CrossTenant-AuthSource: BY5PR10MB4370.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2022 16:32:09.7640 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: abb4cdb7-1b7e-483e-a143-7ebfd1184b9e X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ZO7m9knmb+dqo4wkPKwHlTl4q9vMSUfQOJFa96cExfK+OC4EJg/hEkj1aXajFeADyK+0DGOEAya6XijZBF8OOQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN0PR10MB4951 X-BESS-ID: 1669048333-102439-5395-1548-1 X-BESS-VER: 2019.1_20221114.2026 X-BESS-Apparent-Source-IP: 104.47.58.100 X-BESS-Outbound-Spam-Score: 0.50 X-BESS-Outbound-Spam-Report: Code version 3.2, rules version 3.2.2.244302 [from cloudscan19-118.us-east-2b.ess.aws.cudaops.com] Rule breakdown below pts rule name description ---- ---------------------- -------------------------------- 0.50 BSF_RULE7568M META: Custom Rule 7568M 0.00 BSF_BESS_OUTBOUND META: BESS Outbound X-BESS-Outbound-Spam-Status: SCORE=0.50 using account:ESS112744 scores of KILL_LEVEL=7.0 tests=BSF_RULE7568M, BSF_BESS_OUTBOUND X-BESS-BRTS-Status: 1 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On 11/21/22 09:55, Hector Palacios wrote: > Hi Marek, > > On 11/19/22 15:12, Marek Vasut wrote: >> On 11/18/22 12:19, Hector Palacios wrote: >>> Commit 8c4e3b79bd0bb76eea16869e9666e19047c0d005 supposedly >>> passed one-level up the argument passed to 'exit' but it also >>> broke 'exit' purpose of stopping a script. >>> >>> In reality, even if 'do_exit()' is capable of returning any >>> integer, the cli only admits '1' or '0' as return values. >>> >>> This commit respects the current implementation to allow 'exit' >>> to at least return '1' for future processing, but returns >>> when the command being run is 'exit'. >>> >>> Before this: >>> >>>       => setenv foo 'echo bar ; exit 3 ; echo should not see this'; >>> run foo; echo $? >>>       bar >>>       should not see this >>>       0 >>>       => setenv foo 'echo bar ; exit 1 ; echo should not see this'; >>> run foo; echo $? >>>       bar >>>       should not see this >>>       0 >>>       => setenv foo 'echo bar ; exit 0 ; echo should not see this'; >>> run foo; echo $? >>>       bar >>>       should not see this >>>       0 >>>       => setenv foo 'echo bar ; exit -1 ; echo should not see this'; >>> run foo; echo $? >>>       bar >>>       should not see this >>>       0 >>>       => setenv foo 'echo bar ; exit -2 ; echo should not see this'; >>> run foo; echo $? >>>       bar >>>       should not see this >>>       0 >>>       => setenv foo 'echo bar ; exit ; echo should not see this'; run >>> foo; echo $? >>>       bar >>>       should not see this >>>       0 >>> >>> After this: >>> >>>          => setenv foo 'echo bar ; exit 3 ; echo should not see >>> this'; run foo; echo $? >>>          bar >>>          1 >>>          => setenv foo 'echo bar ; exit 1 ; echo should not see >>> this'; run foo; echo $? >>>          bar >>>          1 >>>          => setenv foo 'echo bar ; exit 0 ; echo should not see >>> this'; run foo; echo $? >>>          bar >>>          0 >>>          => setenv foo 'echo bar ; exit -1 ; echo should not see >>> this'; run foo; echo $? >>>          bar >>>          0 >>>          => setenv foo 'echo bar ; exit -2 ; echo should not see >>> this'; run foo; echo $? >>>          bar >>>          0 >>>          => setenv foo 'echo bar ; exit ; echo should not see this'; >>> run foo; echo $? >>>          bar >>>          0 >>> >>> Reported-by: Adrian Vovk >>> Signed-off-by: Hector Palacios >>> --- >>>   common/cli_hush.c | 4 ++++ >>>   1 file changed, 4 insertions(+) >>> >>> diff --git a/common/cli_hush.c b/common/cli_hush.c >>> index 1467ff81b35b..9fe8b87e02d7 100644 >>> --- a/common/cli_hush.c >>> +++ b/common/cli_hush.c >>> @@ -1902,6 +1902,10 @@ static int run_list_real(struct pipe *pi) >>>                       last_return_code = -rcode - 2; >>>                       return -2;      /* exit */ >>>               } >>> +             if (!strcmp(pi->progs->argv[0], "exit")) { >>> +                     last_return_code = rcode; >>> +                     return rcode;   /* exit */ >>> +             } >>>               last_return_code=(rcode == 0) ? 0 : 1; >>>   #endif >>>   #ifndef __U_BOOT__ >> >> Looking at the code just above this change 'if (rcode < -1) >> last_return_code = -rcode - 2', that explains the odd 'return -r - 2' in >> cmd/exit.c I think. > > That's what I thought, too. The cli captures a -2 as the number to exit > a  script, and with -rcode -2 was exiting and returning a 0. > Instead of capturing a magic number, I'm suggesting to capture 'exit' > command. > > >> I wonder, can we somehow fix the return code handling in cmd/exit.c >> instead, so that it would cover both this behavior listed in this patch, >> and 8c4e3b79bd0 ("cmd: exit: Fix return value") ? The cmd/exit.c seems >> like the right place to fix it. > > I didn't revert or touched 8c4e3b79bd0 but if what you wanted to do with > that commit is to return any positive integer to the upper layers, I > must say that just doesn't work because the cli_hush only processes 1 > (failure) or 0 (success), so there's no way for something such as 'exit > 3' to produce a $? of 3. > I think the 'exit' command should only be used with this old U-Boot > standard of considering 1 a failure and 0 a success. > > I could remove the 'if (rcode < -1)  last_return_code = -rcode - 2', > which doesn't add much value now, but other than that I'm unsure of what > you have in mind as to fix cmd/exit.c. I just saw my patch causes a data abort on if conditionals, when accessing argv[0]. Maybe we'd rather simply revert 8c4e3b79bd0 ("cmd: exit: Fix return value") and let the exit command return 0 in all cases, as it is documented, at least until we find a proper solution. -- Héctor Palacios