From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1oljw8-0005a4-Py for mharc-grub-devel@gnu.org; Fri, 21 Oct 2022 00:47:12 -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 1oljw7-0005Zq-8p for grub-devel@gnu.org; Fri, 21 Oct 2022 00:47:11 -0400 Received: from mail-ua1-x933.google.com ([2607:f8b0:4864:20::933]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oljw5-0001wj-7J for grub-devel@gnu.org; Fri, 21 Oct 2022 00:47:10 -0400 Received: by mail-ua1-x933.google.com with SMTP id e22so1907862uar.5 for ; Thu, 20 Oct 2022 21:47:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficientek-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=r8St0bpQF2bx8OoMYEMMRJKvWKfeA5EkyCz9oIz+/m0=; b=GGhYCJwXoIRyODi7mKFAMFivXI1/nm3v3E0zYokfx6Cu6zSkJBJrHunESYN+zLl3wt nK8U/e9eB1m1QDdglriTvTikTCO//+dtOaBfrRT9L93/mRrI4h7XTmkcnsFZKuiCrz6Q bhJQ2+FJtfSRkUud71k0le3RWetb/xnljFg0U8L/dLM4CWYfvXBXZvzBfMhmWtxs98nr UXXyKWYuni6k1CAudLAYtf9L2EwpzQ3PD5smCscEKn1C8dmFeZEkfKD7rddExpC3Z0vl 5kVXMAqbm3N3zgSLARfZIYA/AEwCL7RHzipN8Z0xE3NZ5VaxsCFLxw/8Mvmf62Srin0z Hv8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=r8St0bpQF2bx8OoMYEMMRJKvWKfeA5EkyCz9oIz+/m0=; b=KmJmCHFfvEjlnN1nQ2m6AA0K7C2tNy1OG4QI4+05a3+hwV2iLWdDXITnc9SxHlJwm7 CMElXXbZePmbHmhP6QwwNCjhxezvduNez04Z617InnqzxAUE6Cl9zUzteM9iCX28Mt+A u6OTjDJBcL6MrPnpMYPZfyeUBCgxful8G5PzLgYdarrSyO3Rn8NlkNGD3d9Yy2cKuNgu eV/YuTlklAJMXTqINSHXllI6Iieq4Yi1kTZufp10SjIMILSU3k8z8d6fgzt/3Xsj3h38 1A9ZT5IXKj96z1Kg7lXbMmqhg3imcV/G7wVrc4mSco2kALEzcf6MOALC64R9tUzl40RC iRxA== X-Gm-Message-State: ACrzQf2FQcQSc/Cj8eRVZqrI2NXnVXmfpIxqZ+GesjpVWt60OGsYpAL5 002IWKSBI/9wW0R4rc4ARXmyh+b//LzGfg== X-Google-Smtp-Source: AMsMyM5nfyBIpvW93e1deuRQaGw7xj6ND7av96QvcGBVrQEKKwvqhqYKC8ltiMDezy5nBZcZuwoGMQ== X-Received: by 2002:ab0:136d:0:b0:3b3:da15:c7de with SMTP id h42-20020ab0136d000000b003b3da15c7demr11437301uae.25.1666327627246; Thu, 20 Oct 2022 21:47:07 -0700 (PDT) Received: from localhost.localdomain ([37.218.244.251]) by smtp.gmail.com with ESMTPSA id z6-20020a67f546000000b003aa0000fe1fsm91129vsn.5.2022.10.20.21.47.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 21:47:06 -0700 (PDT) From: Glenn Washburn To: grub-devel@gnu.org, Daniel Kiper Cc: Li Gen , Glenn Washburn Subject: [PATCH v2] cmp: Only return success when both files have the same contents Date: Thu, 20 Oct 2022 23:46:26 -0500 Message-Id: <20221021044626.1926827-1-development@efficientek.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::933; envelope-from=development@efficientek.com; helo=mail-ua1-x933.google.com 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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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 04:47:11 -0000 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. @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")); + 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; -- 2.34.1