From 50a92a833a92a941651800465dedcd5d268dc460 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 2 May 2023 09:57:51 -0400 Subject: [PATCH] app: Add a global `-q/--quiet` flag This replaces the need for `StandardOutput=null` in the automatic upgrade unit, and can also be used for custom upgrade units, such as that proposed in https://github.com/coreos/fedora-coreos-docs/pull/540 --- src/app/libmain.cxx | 10 ++++++ src/app/rpmostree-builtins.h | 2 ++ src/app/rpmostree-clientlib.cxx | 42 ++++++++++++++---------- src/daemon/rpm-ostreed-automatic.service | 3 +- 4 files changed, 37 insertions(+), 20 deletions(-) diff --git a/src/app/libmain.cxx b/src/app/libmain.cxx index 1ffa996334..60059238eb 100644 --- a/src/app/libmain.cxx +++ b/src/app/libmain.cxx @@ -128,6 +128,7 @@ static RpmOstreeCommand commands[] = { }; static gboolean opt_version; +static gboolean opt_quiet; static gboolean opt_force_peer; static char *opt_sysroot; static gchar **opt_install; @@ -135,6 +136,8 @@ static gchar **opt_uninstall; static GOptionEntry global_entries[] = { { "version", 0, 0, G_OPTION_ARG_NONE, &opt_version, "Print version information and exit", NULL }, + { "quiet", 'q', 0, G_OPTION_ARG_NONE, &opt_quiet, + "Avoid printing most informational messages", NULL }, { NULL } }; static GOptionEntry daemon_entries[] @@ -211,6 +214,13 @@ client_throw_non_ostree_host_error (GError **error) } /* namespace */ +// Returns TRUE if the global quiet flag was specified +bool +rpmostree_global_quiet (void) +{ + return opt_quiet; +} + gboolean rpmostree_option_context_parse (GOptionContext *context, const GOptionEntry *main_entries, int *argc, char ***argv, RpmOstreeCommandInvocation *invocation, diff --git a/src/app/rpmostree-builtins.h b/src/app/rpmostree-builtins.h index 1b4cc03e3f..43ef9ca6a8 100644 --- a/src/app/rpmostree-builtins.h +++ b/src/app/rpmostree-builtins.h @@ -63,6 +63,8 @@ BUILTINPROTO (initramfs_etc); #undef BUILTINPROTO +bool rpmostree_global_quiet (void); + gboolean rpmostree_option_context_parse (GOptionContext *context, const GOptionEntry *main_entries, int *argc, char ***argv, RpmOstreeCommandInvocation *invocation, diff --git a/src/app/rpmostree-clientlib.cxx b/src/app/rpmostree-clientlib.cxx index 7b2c046b4d..759e590119 100644 --- a/src/app/rpmostree-clientlib.cxx +++ b/src/app/rpmostree-clientlib.cxx @@ -326,6 +326,30 @@ on_transaction_progress (GDBusProxy *proxy, gchar *sender_name, gchar *signal_na g_debug ("txn progress %s", signal_name); + if (g_strcmp0 (signal_name, "Finished") == 0) + { + if (tp->error == NULL) + { + g_autofree char *error_message = NULL; + gboolean success = FALSE; + + g_variant_get (parameters, "(bs)", &success, &error_message); + + if (!success) + { + tp->error = g_dbus_error_new_for_dbus_error ( + "org.projectatomic.rpmostreed.Error.Failed", error_message); + } + } + + transaction_progress_end (tp); + return; + } + + // Everything else below here is just printing progress, which we suppress in quiet mode + if (rpmostree_global_quiet ()) + return; + if (g_strcmp0 (signal_name, "SignatureProgress") == 0) { /* We used to print the signature here, but doing so interferes with the @@ -390,24 +414,6 @@ on_transaction_progress (GDBusProxy *proxy, gchar *sender_name, gchar *signal_na else rpmostreecxx::console_progress_set_message (line.c_str ()); } - else if (g_strcmp0 (signal_name, "Finished") == 0) - { - if (tp->error == NULL) - { - g_autofree char *error_message = NULL; - gboolean success = FALSE; - - g_variant_get (parameters, "(bs)", &success, &error_message); - - if (!success) - { - tp->error = g_dbus_error_new_for_dbus_error ( - "org.projectatomic.rpmostreed.Error.Failed", error_message); - } - } - - transaction_progress_end (tp); - } } static void diff --git a/src/daemon/rpm-ostreed-automatic.service b/src/daemon/rpm-ostreed-automatic.service index 556314ac3a..e53e89c228 100644 --- a/src/daemon/rpm-ostreed-automatic.service +++ b/src/daemon/rpm-ostreed-automatic.service @@ -5,5 +5,4 @@ ConditionPathExists=/run/ostree-booted [Service] Type=simple -ExecStart=rpm-ostree upgrade --trigger-automatic-update-policy -StandardOutput=null +ExecStart=rpm-ostree upgrade --quiet --trigger-automatic-update-policy