From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1olqh3-0004b1-1q for mharc-grub-devel@gnu.org; Fri, 21 Oct 2022 08:00:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1olqgt-0004X0-F7 for grub-devel@gnu.org; Fri, 21 Oct 2022 07:59:58 -0400 Received: from dibed.net-space.pl ([84.10.22.86]) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_3DES_EDE_CBC_SHA1:192) (Exim 4.90_1) (envelope-from ) id 1olqgf-0006TR-PP for grub-devel@gnu.org; Fri, 21 Oct 2022 07:59:55 -0400 Received: from router-fw.i.net-space.pl ([192.168.52.1]:46728 "EHLO tomti.i.net-space.pl") by router-fw-old.i.net-space.pl with ESMTP id S2158906AbiJUL7g (ORCPT ); Fri, 21 Oct 2022 13:59:36 +0200 X-Comment: RFC 2476 MSA function at dibed.net-space.pl logged sender identity as: dkiper Date: Fri, 21 Oct 2022 13:59:27 +0200 From: Daniel Kiper To: Glenn Washburn Cc: grub-devel@gnu.org, Li Gen Subject: Re: [PATCH v2] cmp: Only return success when both files have the same contents Message-ID: <20221021115927.sin25m2p4jkkzecw@tomti.i.net-space.pl> References: <20221021044626.1926827-1-development@efficientek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221021044626.1926827-1-development@efficientek.com> User-Agent: NeoMutt/20170113 (1.7.2) Received-SPF: pass client-ip=84.10.22.86; envelope-from=dkiper@net-space.pl; helo=dibed.net-space.pl X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 21 Oct 2022 11:59:59 -0000 On Thu, Oct 20, 2022 at 11:46:26PM -0500, Glenn Washburn wrote: > From: Li Gen > > This allows the cmp command to be used in GRUB scripts to conditionally > run commands based on whether two files are the same. > > Update documentation accordingly. > > Signed-off-by: Li Gen > Signed-off-by: Glenn Washburn > --- > Range-diff against v1: > 1: 5832522ca2 ! 1: 3e6c866d87 cmp: Only return success when both files have the same contents > @@ Commit message > This allows the cmp command to be used in GRUB scripts to conditionally > run commands based on whether two files are the same. > > + Update documentation accordingly. > + > Signed-off-by: Li Gen > Signed-off-by: Glenn Washburn > > + ## docs/grub.texi ## > +@@ docs/grub.texi: bytes like this: > + Differ at the offset 777: 0xbe [foo], 0xef [bar] > + @end example > + > +-If they are completely identical, nothing will be printed. > ++If they are completely identical, nothing will be printed, and @code{$?} > ++will be set to 0. Otherwise, if the files are not identical, @code{$?} > ++will be set to a nonzero value. > + @end deffn > + > + > + > ## grub-core/commands/cmp.c ## > @@ grub-core/commands/cmp.c: grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)), > grub_file_t file2 = 0; > > docs/grub.texi | 4 +++- > grub-core/commands/cmp.c | 4 +++- > 2 files changed, 6 insertions(+), 2 deletions(-) > > diff --git a/docs/grub.texi b/docs/grub.texi > index 4a6fb1a727..b12f47d351 100644 > --- a/docs/grub.texi > +++ b/docs/grub.texi > @@ -4486,7 +4486,9 @@ bytes like this: > Differ at the offset 777: 0xbe [foo], 0xef [bar] > @end example > > -If they are completely identical, nothing will be printed. > +If they are completely identical, nothing will be printed, and @code{$?} > +will be set to 0. Otherwise, if the files are not identical, @code{$?} > +will be set to a nonzero value. I think the updated doc is not in line with the code. > @end deffn > > > diff --git a/grub-core/commands/cmp.c b/grub-core/commands/cmp.c > index e9c3b25d34..e1665cf27b 100644 > --- a/grub-core/commands/cmp.c > +++ b/grub-core/commands/cmp.c > @@ -38,6 +38,7 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)), > grub_file_t file2 = 0; > char *buf1 = 0; > char *buf2 = 0; > + grub_err_t err = GRUB_ERR_TEST_FAILURE; > > if (argc != 2) > return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("two arguments expected")); > @@ -91,6 +92,7 @@ grub_cmd_cmp (grub_command_t cmd __attribute__ ((unused)), > > /* TRANSLATORS: it's always exactly 2 files. */ > grub_printf_ (N_("The files are identical.\n")); Did not we agree the cmp command should be quite by default? > + err = GRUB_ERR_NONE; > } > > cleanup: > @@ -102,7 +104,7 @@ cleanup: > if (file2) > grub_file_close (file2); > > - return grub_errno; > + return err; > } > > static grub_command_t cmd; Daniel