From 1c01141e0c375a4cb64695d08abb2835cd91843b Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Mon, 2 Nov 2015 16:54:00 -0500 Subject: [PATCH] app: Define a special exit code for no changes (77) Used by upgrade and deploy to allow scripts to test for changes. --- man/rpm-ostree.xml | 12 +++++++++ src/app/rpmostree-builtin-deploy.c | 14 ++++++++++- src/app/rpmostree-builtin-upgrade.c | 38 ++++++++++++++++------------- src/app/rpmostree-builtins.h | 4 +++ 4 files changed, 50 insertions(+), 18 deletions(-) diff --git a/man/rpm-ostree.xml b/man/rpm-ostree.xml index 695a0aa8..532668be 100644 --- a/man/rpm-ostree.xml +++ b/man/rpm-ostree.xml @@ -103,6 +103,12 @@ Boston, MA 02111-1307, USA. any changes to take effect. + + In addition to exit status 0 for success and 1 for error, this + command also uses exit status 77 to indicate that no upgrade is + available. + + --reboot or -r to initiate a reboot after upgrade is prepared. @@ -162,6 +168,12 @@ Boston, MA 02111-1307, USA. its SHA256 checksum, or by its "version" metadata value. + + In addition to exit status 0 for success and 1 for error, this + command also uses exit status 77 to indicate that no deployment + change occurred. + + or to initiate a reboot after the downloaded tree is prepared. diff --git a/src/app/rpmostree-builtin-deploy.c b/src/app/rpmostree-builtin-deploy.c index f5f392d1..bd25ab5f 100644 --- a/src/app/rpmostree-builtin-deploy.c +++ b/src/app/rpmostree-builtin-deploy.c @@ -145,12 +145,24 @@ rpmostree_builtin_deploy (int argc, error)) goto out; + if (g_variant_n_children (result) == 0) + { + exit_status = RPM_OSTREE_EXIT_UNCHANGED; + goto out; + } + rpmostree_print_package_diffs (result); } - else if (!opt_reboot && default_deployment != NULL) + else if (!opt_reboot) { const char *sysroot_path; + if (default_deployment == NULL) + { + exit_status = RPM_OSTREE_EXIT_UNCHANGED; + goto out; + } + sysroot_path = rpmostree_sysroot_get_path (sysroot_proxy); if (!rpmostree_print_treepkg_diff_from_sysroot_path (sysroot_path, diff --git a/src/app/rpmostree-builtin-upgrade.c b/src/app/rpmostree-builtin-upgrade.c index 80cf0166..7a46920a 100644 --- a/src/app/rpmostree-builtin-upgrade.c +++ b/src/app/rpmostree-builtin-upgrade.c @@ -141,28 +141,32 @@ rpmostree_builtin_upgrade (int argc, error)) goto out; - rpmostree_print_package_diffs (result); - } - else - { - /* nothing changed */ - if (default_deployment == NULL) + if (g_variant_n_children (result) == 0) { + exit_status = RPM_OSTREE_EXIT_UNCHANGED; goto out; } - if (!opt_reboot) + + rpmostree_print_package_diffs (result); + } + else if (!opt_reboot) + { + const char *sysroot_path; + + if (default_deployment == NULL) { - const char *sysroot_path; - - sysroot_path = rpmostree_sysroot_get_path (sysroot_proxy); - - if (!rpmostree_print_treepkg_diff_from_sysroot_path (sysroot_path, - cancellable, - error)) - goto out; - - g_print ("Run \"systemctl reboot\" to start a reboot\n"); + exit_status = RPM_OSTREE_EXIT_UNCHANGED; + goto out; } + + sysroot_path = rpmostree_sysroot_get_path (sysroot_proxy); + + if (!rpmostree_print_treepkg_diff_from_sysroot_path (sysroot_path, + cancellable, + error)) + goto out; + + g_print ("Run \"systemctl reboot\" to start a reboot\n"); } exit_status = EXIT_SUCCESS; diff --git a/src/app/rpmostree-builtins.h b/src/app/rpmostree-builtins.h index 95df63cc..faf770e0 100644 --- a/src/app/rpmostree-builtins.h +++ b/src/app/rpmostree-builtins.h @@ -25,6 +25,10 @@ G_BEGIN_DECLS +/* Exit code for no change after pulling commits. + * Use alongside EXIT_SUCCESS and EXIT_FAILURE. */ +#define RPM_OSTREE_EXIT_UNCHANGED (77) + typedef enum { RPM_OSTREE_BUILTIN_FLAG_NONE = 0, RPM_OSTREE_BUILTIN_FLAG_LOCAL_CMD = 1 << 0