grub2: Show output when run in systemd by default
authorColin Walters <walters@verbum.org>
Thu, 29 Aug 2024 18:19:03 +0000 (14:19 -0400)
committerColin Walters <walters@verbum.org>
Tue, 3 Sep 2024 12:55:35 +0000 (08:55 -0400)
xref https://github.com/coreos/rpm-ostree/issues/5071

Hiding errors by default is painful. At least as of
recently in Fedora it looks like the command is nice
and quiet by default, I only see

```
Generating grub configuration file ...
Adding boot menu entry for UEFI Firmware Settings ...
done
```

Signed-off-by: Colin Walters <walters@verbum.org>
src/libostree/ostree-bootloader-grub2.c
src/libostree/ostree-repo-commit.c

index cbe7605d0ff7100a4b136a52d4a286ce7295b0cd..e15fb9b6591bd6856c1f759437a6547c0feb8e77 100644 (file)
@@ -22,9 +22,9 @@
 #include "otutil.h"
 #include <gio/gfiledescriptorbased.h>
 #include <gio/gunixoutputstream.h>
-#include <sys/mount.h>
-
+#include <stdbool.h>
 #include <string.h>
+#include <sys/mount.h>
 
 // Written by bootupd
 #define BOOTUPD_CONFIG "boot/bootupd-state.json"
@@ -419,7 +419,15 @@ _ostree_bootloader_grub2_write_config (OstreeBootloader *bootloader, int bootver
   grub_argv[2] = gs_file_get_path_cached (new_config_path);
 
   GSpawnFlags grub_spawnflags = G_SPAWN_SEARCH_PATH;
-  if (!g_getenv ("OSTREE_DEBUG_GRUB2"))
+  const bool running_in_systemd = getenv ("INVOCATION_ID") != NULL;
+  const bool debug_grub2 = g_getenv ("OSTREE_DEBUG_GRUB2");
+  /* If we're running in systemd (as part of `ostree-finalize-staged.service`)
+   * then we do want to gather output from the binary so that if something fails
+   * we can debug it.
+   *
+   * We also have an opt-in variable to display errors.
+   */
+  if (!(running_in_systemd || debug_grub2))
     grub_spawnflags |= G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL;
   cdata.root = grub2_mkconfig_chroot;
   g_autofree char *bootversion_str = g_strdup_printf ("%u", (guint)bootversion);
index 22d575fe7d7796592ae159d919361a73fc5b6332..0ee97288d7f7b14b718ead11a8f34a53d08cacc2 100644 (file)
@@ -820,7 +820,8 @@ _try_clone_from_payload_link (OstreeRepo *self, OstreeRepo *dest_repo, const cha
                            loose_path_buf, (unsigned long long)expected_len,
                            (unsigned long long)size);
 
-      snprintf (target_checksum, sizeof (target_checksum), "%.2s%.62s", target_buf + _OSTREE_PAYLOAD_LINK_PREFIX_LEN,
+      snprintf (target_checksum, sizeof (target_checksum), "%.2s%.62s",
+                target_buf + _OSTREE_PAYLOAD_LINK_PREFIX_LEN,
                 target_buf + _OSTREE_PAYLOAD_LINK_PREFIX_LEN + 3);
 
       _ostree_loose_path (loose_path_target_buf, target_checksum, OSTREE_OBJECT_TYPE_FILE,