]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bootctl: fix boolean logic in id128 comparisons 36372/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 14 Feb 2025 08:50:28 +0000 (09:50 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 14 Mar 2025 11:21:45 +0000 (12:21 +0100)
There were too many levels of negation there. Add a comment to explain the
reasoning at a high level.

src/bootctl/bootctl-status.c

index a15075e1c9033c11298029425b1e687392ce7444..5a67d7fc51eef133c7e853ad625ffb4e3be6b95c 100644 (file)
@@ -487,9 +487,12 @@ int verb_status(int argc, char *argv[], void *userdata) {
                         (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE_STR("LoaderDeviceURL"), &loader_url);
 
                         if (!sd_id128_is_null(loader_partition_uuid)) {
-                                if (!sd_id128_is_null(esp_uuid) && !sd_id128_equal(esp_uuid, loader_partition_uuid))
-                                        printf("WARNING: The boot loader reports a different partition UUID than the detected ESP ("SD_ID128_UUID_FORMAT_STR" vs. "SD_ID128_UUID_FORMAT_STR")!\n",
-                                               SD_ID128_FORMAT_VAL(loader_partition_uuid), SD_ID128_FORMAT_VAL(esp_uuid));
+                                /* If we know esp_uuid and loader_partition_uuid is not equal to it, print a warning. */
+                                if (!sd_id128_is_null(esp_uuid) && !sd_id128_equal(loader_partition_uuid, esp_uuid))
+                                        printf("WARNING: The boot loader reports a different partition UUID than the detected ESP "
+                                               "("SD_ID128_UUID_FORMAT_STR" vs. "SD_ID128_UUID_FORMAT_STR")!\n",
+                                               SD_ID128_FORMAT_VAL(loader_partition_uuid),
+                                               SD_ID128_FORMAT_VAL(esp_uuid));
 
                                 printf("    Partition: /dev/disk/by-partuuid/" SD_ID128_UUID_FORMAT_STR "\n",
                                        SD_ID128_FORMAT_VAL(loader_partition_uuid));
@@ -525,10 +528,15 @@ int verb_status(int argc, char *argv[], void *userdata) {
                         (void) efi_get_variable_string_and_warn(EFI_LOADER_VARIABLE_STR("StubDeviceURL"), &stub_url);
 
                         if (!sd_id128_is_null(stub_partition_uuid)) {
-                                if (!(!sd_id128_is_null(esp_uuid) && sd_id128_equal(esp_uuid, stub_partition_uuid)) &&
-                                    !(!sd_id128_is_null(xbootldr_uuid) && sd_id128_equal(xbootldr_uuid, stub_partition_uuid)))
-                                        printf("WARNING: The stub loader reports a different UUID than the detected ESP or XBOOTDLR partition ("SD_ID128_UUID_FORMAT_STR" vs. "SD_ID128_UUID_FORMAT_STR"/"SD_ID128_UUID_FORMAT_STR")!\n",
-                                               SD_ID128_FORMAT_VAL(stub_partition_uuid), SD_ID128_FORMAT_VAL(esp_uuid), SD_ID128_FORMAT_VAL(xbootldr_uuid));
+                                /* _If_ we know both esp_uuid and xbootldr_uuid and stub_partition_uuid is not equal
+                                 * to _either_ of them, print a warning. */
+                                if (!sd_id128_is_null(esp_uuid) && !sd_id128_equal(stub_partition_uuid, esp_uuid) &&
+                                    !sd_id128_is_null(xbootldr_uuid) && !sd_id128_equal(stub_partition_uuid, xbootldr_uuid))
+                                        printf("WARNING: The stub loader reports a different UUID than the detected ESP and XBOOTDLR partitions "
+                                               "("SD_ID128_UUID_FORMAT_STR" vs. "SD_ID128_UUID_FORMAT_STR"/"SD_ID128_UUID_FORMAT_STR")!\n",
+                                               SD_ID128_FORMAT_VAL(stub_partition_uuid),
+                                               SD_ID128_FORMAT_VAL(esp_uuid),
+                                               SD_ID128_FORMAT_VAL(xbootldr_uuid));
 
                                 printf("    Partition: /dev/disk/by-partuuid/" SD_ID128_UUID_FORMAT_STR "\n",
                                        SD_ID128_FORMAT_VAL(stub_partition_uuid));