From 855d1293ab9d610e2981ff2705067125d5223e10 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 28 Dec 2017 21:11:32 +0100 Subject: [PATCH] cli: Rework exit status processing We've had many bugs from internal helpers using `return EXIT_FAILURE` rather than `return FALSE`. The reason we need exit codes is to handle the `RPM_OSTREE_EXIT_UNCHANGED` case. I realized recently that we had the handy `RpmOstreeCommandInvocation` which we can use to signal back this special case. Then all of our functions otherwise are just normal `GError`. One minor wart here is the two cases of "usage error" versus "command invocation" in `main.c`, but IMO the general cleanup is well worth that. Closes: #1169 Approved by: jlebon --- src/app/main.c | 45 +++++++++---- src/app/rpmostree-builtin-cancel.c | 10 +-- src/app/rpmostree-builtin-cleanup.c | 16 ++--- src/app/rpmostree-builtin-compose.c | 2 +- src/app/rpmostree-builtin-container.c | 2 +- src/app/rpmostree-builtin-db.c | 2 +- src/app/rpmostree-builtin-deploy.c | 34 +++++----- src/app/rpmostree-builtin-ex.c | 2 +- src/app/rpmostree-builtin-initramfs.c | 18 +++--- src/app/rpmostree-builtin-kargs.c | 36 +++++------ src/app/rpmostree-builtin-livefs.c | 10 +-- src/app/rpmostree-builtin-override.c | 2 +- src/app/rpmostree-builtin-rebase.c | 14 ++--- src/app/rpmostree-builtin-refresh-md.c | 14 ++--- src/app/rpmostree-builtin-reload.c | 8 +-- src/app/rpmostree-builtin-rollback.c | 10 +-- src/app/rpmostree-builtin-start-daemon.c | 13 ++-- src/app/rpmostree-builtin-status.c | 16 ++--- src/app/rpmostree-builtin-types.h | 57 +++++++++++++++++ src/app/rpmostree-builtin-upgrade.c | 35 ++++++----- src/app/rpmostree-builtins.h | 31 +-------- src/app/rpmostree-compose-builtin-tree.c | 58 ++++++++--------- src/app/rpmostree-container-builtins.c | 70 ++++++++++----------- src/app/rpmostree-db-builtin-diff.c | 17 +++-- src/app/rpmostree-db-builtin-list.c | 6 +- src/app/rpmostree-db-builtin-version.c | 6 +- src/app/rpmostree-dbus-helpers.c | 17 +++-- src/app/rpmostree-dbus-helpers.h | 6 +- src/app/rpmostree-ex-builtin-commit2jigdo.c | 14 ++--- src/app/rpmostree-ex-builtin-jigdo2commit.c | 12 ++-- src/app/rpmostree-override-builtins.c | 24 +++---- src/app/rpmostree-pkg-builtins.c | 29 ++++----- 32 files changed, 345 insertions(+), 291 deletions(-) create mode 100644 src/app/rpmostree-builtin-types.h diff --git a/src/app/main.c b/src/app/main.c index 2a40abaaab..5b31e06575 100644 --- a/src/app/main.c +++ b/src/app/main.c @@ -340,15 +340,20 @@ rpmostree_handle_subcommand (int argc, char **argv, g_autofree char *help = g_option_context_get_help (context, FALSE, NULL); g_printerr ("%s", help); - return EXIT_FAILURE; + return FALSE; } g_autofree char *prgname = g_strdup_printf ("%s %s", g_get_prgname (), subcommand_name); g_set_prgname (prgname); - RpmOstreeCommandInvocation sub_invocation = { .command = subcommand }; - return subcommand->fn (argc, argv, &sub_invocation, cancellable, error); + /* We need a new sub-invocation with the new command, which also carries a new + * exit code, but we'll proxy the latter. */ + RpmOstreeCommandInvocation sub_invocation = { .command = subcommand, .exit_code = -1 }; + gboolean ret = subcommand->fn (argc, argv, &sub_invocation, cancellable, error); + /* Proxy the exit code */ + invocation->exit_code = sub_invocation.exit_code; + return ret; } int @@ -357,10 +362,15 @@ main (int argc, { GCancellable *cancellable = g_cancellable_new (); RpmOstreeCommand *command; - int exit_status = EXIT_SUCCESS; const char *command_name = NULL; g_autofree char *prgname = NULL; GError *local_error = NULL; + /* We can leave this function with an error status from both a command + * invocation, as well as an option processing failure. Keep an alias to the + * two places that hold status codes. + */ + int exit_status = EXIT_SUCCESS; + int *exit_statusp = &exit_status; /* avoid gvfs (http://bugzilla.gnome.org/show_bug.cgi?id=526454) */ g_setenv ("GIO_USE_VFS", "local", TRUE); @@ -409,16 +419,29 @@ main (int argc, help = g_option_context_get_help (context, FALSE, NULL); g_printerr ("%s", help); exit_status = EXIT_FAILURE; - goto out; } prgname = g_strdup_printf ("%s %s", g_get_prgname (), command_name); g_set_prgname (prgname); - { RpmOstreeCommandInvocation invocation = { .command = command }; - exit_status = command->fn (argc, argv, &invocation, cancellable, &local_error); - } + RpmOstreeCommandInvocation invocation = { .command = command, + .exit_code = -1 }; + exit_statusp = &(invocation.exit_code); + if (!command->fn (argc, argv, &invocation, cancellable, &local_error)) + { + if (invocation.exit_code == -1) + invocation.exit_code = EXIT_FAILURE; + g_assert (local_error); + goto out; + } + else + { + if (invocation.exit_code == -1) + invocation.exit_code = EXIT_SUCCESS; + else + g_assert (invocation.exit_code != EXIT_SUCCESS); + } out: if (local_error != NULL) @@ -434,13 +457,9 @@ main (int argc, g_dbus_error_strip_remote_error (local_error); g_printerr ("%serror: %s%s\n", prefix, suffix, local_error->message); g_error_free (local_error); - - /* Print a warning if the exit status indicates success when we - * actually had an error, so it gets reported and fixed quickly. */ - g_warn_if_fail (exit_status != EXIT_SUCCESS); } rpmostree_polkit_agent_close (); - return exit_status; + return *exit_statusp; } diff --git a/src/app/rpmostree-builtin-cancel.c b/src/app/rpmostree-builtin-cancel.c index cfcbfdc971..59b01df91e 100644 --- a/src/app/rpmostree-builtin-cancel.c +++ b/src/app/rpmostree-builtin-cancel.c @@ -56,7 +56,7 @@ on_active_txn_path_changed (GObject *object, g_main_context_wakeup (NULL); } -int +gboolean rpmostree_builtin_cancel (int argc, char **argv, RpmOstreeCommandInvocation *invocation, @@ -76,7 +76,7 @@ rpmostree_builtin_cancel (int argc, &sysroot_proxy, &peer_pid, error)) - return EXIT_FAILURE; + return FALSE; /* Keep track of the txn path we saw first, as well as checking if it changed @@ -86,7 +86,7 @@ rpmostree_builtin_cancel (int argc, glnx_unref_object RPMOSTreeTransaction *txn_proxy = NULL; if (!rpmostree_transaction_connect_active (sysroot_proxy, &txn_path, &txn_proxy, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (!txn_proxy) { /* Let's not make this an error; cancellation may race with completion. @@ -94,7 +94,7 @@ rpmostree_builtin_cancel (int argc, * "recently" but eh. */ g_print ("No active transaction.\n"); - return EXIT_SUCCESS; + return TRUE; } const char *title = rpmostree_transaction_get_title (txn_proxy); @@ -117,5 +117,5 @@ rpmostree_builtin_cancel (int argc, } g_print ("Cancelled.\n"); - return EXIT_SUCCESS; + return TRUE; } diff --git a/src/app/rpmostree-builtin-cleanup.c b/src/app/rpmostree-builtin-cleanup.c index c116619809..22eb23c9a0 100644 --- a/src/app/rpmostree-builtin-cleanup.c +++ b/src/app/rpmostree-builtin-cleanup.c @@ -45,7 +45,7 @@ static GOptionEntry option_entries[] = { { NULL } }; -int +gboolean rpmostree_builtin_cleanup (int argc, char **argv, RpmOstreeCommandInvocation *invocation, @@ -68,12 +68,12 @@ rpmostree_builtin_cleanup (int argc, &sysroot_proxy, &peer_pid, error)) - return EXIT_FAILURE; + return FALSE; if (argc < 1 || argc > 2) { rpmostree_usage_error (context, "Too few or too many arguments", error); - return EXIT_FAILURE; + return FALSE; } if (opt_base) @@ -87,27 +87,27 @@ rpmostree_builtin_cleanup (int argc, if (cleanup_types->len == 0) { glnx_throw (error, "At least one cleanup option must be specified"); - return EXIT_FAILURE; + return FALSE; } g_ptr_array_add (cleanup_types, NULL); if (!rpmostree_load_os_proxy (sysroot_proxy, opt_osname, cancellable, &os_proxy, error)) - return EXIT_FAILURE; + return FALSE; if (!rpmostree_os_call_cleanup_sync (os_proxy, (const char *const*)cleanup_types->pdata, &transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (!rpmostree_transaction_get_response_sync (sysroot_proxy, transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; - return EXIT_SUCCESS; + return TRUE; } diff --git a/src/app/rpmostree-builtin-compose.c b/src/app/rpmostree-builtin-compose.c index 896452af50..31a738ba72 100644 --- a/src/app/rpmostree-builtin-compose.c +++ b/src/app/rpmostree-builtin-compose.c @@ -44,7 +44,7 @@ static RpmOstreeCommand compose_subcommands[] = { { NULL, 0, NULL, NULL } }; -int +gboolean rpmostree_builtin_compose (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) diff --git a/src/app/rpmostree-builtin-container.c b/src/app/rpmostree-builtin-container.c index 33399d7812..5d07d7651e 100644 --- a/src/app/rpmostree-builtin-container.c +++ b/src/app/rpmostree-builtin-container.c @@ -34,7 +34,7 @@ static RpmOstreeCommand container_subcommands[] = { { NULL, 0, NULL, NULL } }; -int +gboolean rpmostree_builtin_container (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) diff --git a/src/app/rpmostree-builtin-db.c b/src/app/rpmostree-builtin-db.c index 2ae5b82464..3b8a6f8db4 100644 --- a/src/app/rpmostree-builtin-db.c +++ b/src/app/rpmostree-builtin-db.c @@ -90,7 +90,7 @@ rpmostree_db_option_context_parse (GOptionContext *context, return TRUE; } -int +gboolean rpmostree_builtin_db (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) diff --git a/src/app/rpmostree-builtin-deploy.c b/src/app/rpmostree-builtin-deploy.c index 3a0e219bef..4755834c8e 100644 --- a/src/app/rpmostree-builtin-deploy.c +++ b/src/app/rpmostree-builtin-deploy.c @@ -46,7 +46,7 @@ static GOptionEntry option_entries[] = { { NULL } }; -int +gboolean rpmostree_builtin_deploy (int argc, char **argv, RpmOstreeCommandInvocation *invocation, @@ -75,26 +75,26 @@ rpmostree_builtin_deploy (int argc, &sysroot_proxy, &peer_pid, error)) - return EXIT_FAILURE; + return FALSE; if (argc < 2) { rpmostree_usage_error (context, "REVISION must be specified", error); - return EXIT_FAILURE; + return FALSE; } if (opt_preview && (install_pkgs != NULL || uninstall_pkgs != NULL)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Cannot specify both --preview and --install/--uninstall"); - return EXIT_FAILURE; + return FALSE; } revision = argv[1]; if (!rpmostree_load_os_proxy (sysroot_proxy, opt_osname, cancellable, &os_proxy, error)) - return EXIT_FAILURE; + return FALSE; g_autoptr(GVariant) previous_deployment = rpmostree_os_dup_default_deployment (os_proxy); @@ -106,7 +106,7 @@ rpmostree_builtin_deploy (int argc, &transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; } else { @@ -136,7 +136,7 @@ rpmostree_builtin_deploy (int argc, &transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; } else { @@ -148,7 +148,7 @@ rpmostree_builtin_deploy (int argc, NULL, cancellable, error)) - return EXIT_FAILURE; + return FALSE; } } @@ -156,7 +156,7 @@ rpmostree_builtin_deploy (int argc, transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (opt_preview) { @@ -170,27 +170,33 @@ rpmostree_builtin_deploy (int argc, &details, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (g_variant_n_children (result) == 0) - return RPM_OSTREE_EXIT_UNCHANGED; + { + invocation->exit_code = RPM_OSTREE_EXIT_UNCHANGED; + return TRUE; + } rpmostree_print_package_diffs (result); } else if (!opt_reboot) { if (!rpmostree_has_new_default_deployment (os_proxy, previous_deployment)) - return RPM_OSTREE_EXIT_UNCHANGED; + { + invocation->exit_code = RPM_OSTREE_EXIT_UNCHANGED; + return TRUE; + } /* do diff without dbus: https://github.com/projectatomic/rpm-ostree/pull/116 */ const char *sysroot_path = rpmostree_sysroot_get_path (sysroot_proxy); if (!rpmostree_print_treepkg_diff_from_sysroot_path (sysroot_path, cancellable, error)) - return EXIT_FAILURE; + return FALSE; g_print ("Run \"systemctl reboot\" to start a reboot\n"); } - return EXIT_SUCCESS; + return TRUE; } diff --git a/src/app/rpmostree-builtin-ex.c b/src/app/rpmostree-builtin-ex.c index 09f1ba0178..44c20ff9b9 100644 --- a/src/app/rpmostree-builtin-ex.c +++ b/src/app/rpmostree-builtin-ex.c @@ -43,7 +43,7 @@ static GOptionEntry global_entries[] = { }; */ -int +gboolean rpmostree_builtin_ex (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) diff --git a/src/app/rpmostree-builtin-initramfs.c b/src/app/rpmostree-builtin-initramfs.c index 347947b463..4860832b2e 100644 --- a/src/app/rpmostree-builtin-initramfs.c +++ b/src/app/rpmostree-builtin-initramfs.c @@ -55,7 +55,7 @@ get_args_variant (void) return g_variant_dict_end (&dict); } -int +gboolean rpmostree_builtin_initramfs (int argc, char **argv, RpmOstreeCommandInvocation *invocation, @@ -75,12 +75,12 @@ rpmostree_builtin_initramfs (int argc, &sysroot_proxy, &peer_pid, error)) - return EXIT_FAILURE; + return FALSE; glnx_unref_object RPMOSTreeOS *os_proxy = NULL; if (!rpmostree_load_os_proxy (sysroot_proxy, opt_osname, cancellable, &os_proxy, error)) - return EXIT_FAILURE; + return FALSE; if (!(opt_enable || opt_disable)) { @@ -91,7 +91,7 @@ rpmostree_builtin_initramfs (int argc, { g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, "--reboot must be used with --enable or --disable"); - return EXIT_FAILURE; + return FALSE; } g_variant_iter_init (&iter, deployments); @@ -135,7 +135,7 @@ rpmostree_builtin_initramfs (int argc, { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Cannot simultaenously specify --enable and --disable"); - return EXIT_FAILURE; + return FALSE; } else { @@ -144,7 +144,7 @@ rpmostree_builtin_initramfs (int argc, { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Cannot simultaenously specify --disable and --arg"); - return EXIT_FAILURE; + return FALSE; } if (!opt_add_arg) opt_add_arg = empty_strv; @@ -157,16 +157,16 @@ rpmostree_builtin_initramfs (int argc, &transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (!rpmostree_transaction_get_response_sync (sysroot_proxy, transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; g_print ("Initramfs regeneration is now: %s\n", opt_enable ? "enabled" : "disabled"); } - return EXIT_SUCCESS; + return TRUE; } diff --git a/src/app/rpmostree-builtin-kargs.c b/src/app/rpmostree-builtin-kargs.c index b839795e62..636d924adf 100644 --- a/src/app/rpmostree-builtin-kargs.c +++ b/src/app/rpmostree-builtin-kargs.c @@ -188,7 +188,7 @@ rpmostree_ex_builtin_kargs (int argc, &sysroot_proxy, &peer_pid, error)) - return EXIT_FAILURE; + return FALSE; if (opt_editor && (opt_kernel_delete_strings || opt_kernel_replace_strings || opt_kernel_append_strings)) @@ -198,32 +198,32 @@ rpmostree_ex_builtin_kargs (int argc, */ g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Cannot specify --editor with --replace, --delete, or --append"); - return EXIT_FAILURE; + return FALSE; } if (opt_kernel_delete_strings && opt_kernel_replace_strings) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Cannot specify both --delete and --replace"); - return EXIT_FAILURE; + return FALSE; } if (opt_kernel_delete_strings && opt_kernel_append_strings) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Cannot specify both --delete and --append"); - return EXIT_FAILURE; + return FALSE; } if (opt_import_proc_cmdline && opt_deploy_index) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Cannot specify both --import-from-proc-cmdline and --deployid"); - return EXIT_FAILURE; + return FALSE; } if (opt_import_proc_cmdline && opt_osname) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Cannot specify both osname and --import-from-proc-cmdline"); - return EXIT_FAILURE; + return FALSE; } if (!(opt_kernel_delete_strings) && !(opt_kernel_append_strings) && !(opt_kernel_replace_strings) && !(opt_editor)) @@ -233,13 +233,13 @@ rpmostree_ex_builtin_kargs (int argc, { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Cannot reboot when kernel arguments not changed"); - return EXIT_FAILURE; + return FALSE; } glnx_unref_object RPMOSTreeOS *os_proxy = NULL; if (!rpmostree_load_os_proxy (sysroot_proxy, opt_osname, cancellable, &os_proxy, error)) - return EXIT_FAILURE; + return FALSE; /* The proc cmdline is the kernel args from booted deployment * if this option is not specified, we will default to find the first @@ -261,19 +261,19 @@ rpmostree_ex_builtin_kargs (int argc, &boot_config, cancellable, error)) - return EXIT_FAILURE; + return FALSE; /* We extract the existing kernel arguments from the boot configuration */ const char *old_kernel_arg_string = NULL; if (!g_variant_lookup (boot_config, "options", "&s", &old_kernel_arg_string)) - return EXIT_FAILURE; + return FALSE; if (display_kernel_args) { g_print ("The kernel arguments are:\n%s\n", old_kernel_arg_string); - return EXIT_SUCCESS; + return TRUE; } g_autofree char *transaction_address = NULL; @@ -291,7 +291,7 @@ rpmostree_ex_builtin_kargs (int argc, const char* current_kernel_arg_string = NULL; if (!kernel_arg_handle_editor (old_kernel_arg_string, ¤t_kernel_arg_string, cancellable, error)) - return EXIT_FAILURE; + return FALSE; gboolean out_changed = FALSE; /* Here we load the sysroot again, if the sysroot @@ -302,13 +302,13 @@ rpmostree_ex_builtin_kargs (int argc, &out_changed, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (out_changed) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Conflict: bootloader configuration changed. Saved kernel arguments: \n%s", current_kernel_arg_string); - return EXIT_FAILURE; + return FALSE; } /* We use the user defined kernel args as existing arguments here * and kept other strvs empty, because the existing kernel arguments @@ -323,7 +323,7 @@ rpmostree_ex_builtin_kargs (int argc, &transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; } else { @@ -347,16 +347,16 @@ rpmostree_ex_builtin_kargs (int argc, &transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; } if (!rpmostree_transaction_get_response_sync (sysroot_proxy, transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; g_print("Kernel arguments updated.\nRun \"systemctl reboot\" to start a reboot\n"); - return EXIT_SUCCESS; + return TRUE; } diff --git a/src/app/rpmostree-builtin-livefs.c b/src/app/rpmostree-builtin-livefs.c index a2d831d63a..7c676ff5a5 100644 --- a/src/app/rpmostree-builtin-livefs.c +++ b/src/app/rpmostree-builtin-livefs.c @@ -69,14 +69,14 @@ rpmostree_ex_builtin_livefs (int argc, &sysroot_proxy, &peer_pid, error)) - return EXIT_FAILURE; + return FALSE; glnx_unref_object RPMOSTreeOS *os_proxy = NULL; glnx_unref_object RPMOSTreeOSExperimental *osexperimental_proxy = NULL; if (!rpmostree_load_os_proxies (sysroot_proxy, NULL, cancellable, &os_proxy, &osexperimental_proxy, error)) - return EXIT_FAILURE; + return FALSE; g_autofree char *transaction_address = NULL; if (!rpmostree_osexperimental_call_live_fs_sync (osexperimental_proxy, @@ -84,13 +84,13 @@ rpmostree_ex_builtin_livefs (int argc, &transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (!rpmostree_transaction_get_response_sync (sysroot_proxy, transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; - return EXIT_SUCCESS; + return TRUE; } diff --git a/src/app/rpmostree-builtin-override.c b/src/app/rpmostree-builtin-override.c index 66f924cf15..4bf245c09f 100644 --- a/src/app/rpmostree-builtin-override.c +++ b/src/app/rpmostree-builtin-override.c @@ -36,7 +36,7 @@ static RpmOstreeCommand override_subcommands[] = { { NULL, 0, NULL, NULL } }; -int +gboolean rpmostree_builtin_override (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) diff --git a/src/app/rpmostree-builtin-rebase.c b/src/app/rpmostree-builtin-rebase.c index 37c96654d1..cf3372620a 100644 --- a/src/app/rpmostree-builtin-rebase.c +++ b/src/app/rpmostree-builtin-rebase.c @@ -49,7 +49,7 @@ static GOptionEntry option_entries[] = { { NULL } }; -int +gboolean rpmostree_builtin_rebase (int argc, char **argv, RpmOstreeCommandInvocation *invocation, @@ -81,17 +81,17 @@ rpmostree_builtin_rebase (int argc, &sysroot_proxy, &peer_pid, error)) - return EXIT_FAILURE; + return FALSE; if (argc > 3) { rpmostree_usage_error (context, "Too many arguments", error); - return EXIT_FAILURE; + return FALSE; } if (!rpmostree_load_os_proxy (sysroot_proxy, opt_osname, cancellable, &os_proxy, error)) - return EXIT_FAILURE; + return FALSE; if (argc < 2 && !(opt_branch || opt_remote)) { @@ -140,7 +140,7 @@ rpmostree_builtin_rebase (int argc, &transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; } else { @@ -163,10 +163,10 @@ rpmostree_builtin_rebase (int argc, NULL, cancellable, error)) - return EXIT_FAILURE; + return FALSE; } - return rpmostree_transaction_client_run (sysroot_proxy, os_proxy, + return rpmostree_transaction_client_run (invocation, sysroot_proxy, os_proxy, options, FALSE, transaction_address, previous_deployment, diff --git a/src/app/rpmostree-builtin-refresh-md.c b/src/app/rpmostree-builtin-refresh-md.c index 560125247f..09d4f96ce5 100644 --- a/src/app/rpmostree-builtin-refresh-md.c +++ b/src/app/rpmostree-builtin-refresh-md.c @@ -46,7 +46,7 @@ get_args_variant (void) return g_variant_dict_end (&dict); } -int +gboolean rpmostree_builtin_refresh_md (int argc, char **argv, RpmOstreeCommandInvocation *invocation, @@ -68,30 +68,30 @@ rpmostree_builtin_refresh_md (int argc, &sysroot_proxy, &peer_pid, error)) - return EXIT_FAILURE; + return FALSE; if (argc < 1 || argc > 2) { rpmostree_usage_error (context, "Too few or too many arguments", error); - return EXIT_FAILURE; + return FALSE; } if (!rpmostree_load_os_proxy (sysroot_proxy, opt_osname, cancellable, &os_proxy, error)) - return EXIT_FAILURE; + return FALSE; if (!rpmostree_os_call_refresh_md_sync (os_proxy, get_args_variant (), &transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (!rpmostree_transaction_get_response_sync (sysroot_proxy, transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; - return EXIT_SUCCESS; + return TRUE; } diff --git a/src/app/rpmostree-builtin-reload.c b/src/app/rpmostree-builtin-reload.c index 5de6d4c17e..2328d8f3cf 100644 --- a/src/app/rpmostree-builtin-reload.c +++ b/src/app/rpmostree-builtin-reload.c @@ -33,7 +33,7 @@ static GOptionEntry option_entries[] = { { NULL } }; -int +gboolean rpmostree_builtin_reload (int argc, char **argv, RpmOstreeCommandInvocation *invocation, @@ -53,10 +53,10 @@ rpmostree_builtin_reload (int argc, &sysroot_proxy, &peer_pid, error)) - return EXIT_FAILURE; + return FALSE; if (!rpmostree_sysroot_call_reload_config_sync (sysroot_proxy, cancellable, error)) - return EXIT_FAILURE; + return FALSE; - return EXIT_SUCCESS; + return TRUE; } diff --git a/src/app/rpmostree-builtin-rollback.c b/src/app/rpmostree-builtin-rollback.c index b229594036..96ca52a996 100644 --- a/src/app/rpmostree-builtin-rollback.c +++ b/src/app/rpmostree-builtin-rollback.c @@ -47,7 +47,7 @@ get_args_variant (void) return g_variant_dict_end (&dict); } -int +gboolean rpmostree_builtin_rollback (int argc, char **argv, RpmOstreeCommandInvocation *invocation, @@ -69,11 +69,11 @@ rpmostree_builtin_rollback (int argc, &sysroot_proxy, &peer_pid, error)) - return EXIT_FAILURE; + return FALSE; if (!rpmostree_load_os_proxy (sysroot_proxy, NULL, cancellable, &os_proxy, error)) - return EXIT_FAILURE; + return FALSE; g_autoptr(GVariant) previous_deployment = rpmostree_os_dup_default_deployment (os_proxy); /* really, rollback only supports the "reboot" option; all others are ignored */ @@ -92,9 +92,9 @@ rpmostree_builtin_rollback (int argc, &transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; - return rpmostree_transaction_client_run (sysroot_proxy, os_proxy, + return rpmostree_transaction_client_run (invocation, sysroot_proxy, os_proxy, options, FALSE, transaction_address, previous_deployment, diff --git a/src/app/rpmostree-builtin-start-daemon.c b/src/app/rpmostree-builtin-start-daemon.c index 522e2cf428..ff6dc317e8 100644 --- a/src/app/rpmostree-builtin-start-daemon.c +++ b/src/app/rpmostree-builtin-start-daemon.c @@ -288,8 +288,7 @@ connect_to_peer (int fd, GError **error) return TRUE; } - -int +gboolean rpmostree_builtin_start_daemon (int argc, char **argv, RpmOstreeCommandInvocation *invocation, @@ -300,7 +299,7 @@ rpmostree_builtin_start_daemon (int argc, g_option_context_add_main_entries (opt_context, opt_entries, NULL); if (!g_option_context_parse (opt_context, &argc, &argv, error)) - return EXIT_FAILURE; + return FALSE; if (opt_debug) { @@ -339,15 +338,15 @@ rpmostree_builtin_start_daemon (int argc, /* Get an explicit ref to the bus so we can use it later */ bus = g_bus_get_sync (bus_type, NULL, error); if (!bus) - return EXIT_FAILURE; + return FALSE; if (!start_daemon (bus, error)) - return EXIT_FAILURE; + return FALSE; (void) g_bus_own_name_on_connection (bus, DBUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, on_name_acquired, on_name_lost, NULL, NULL); } else if (!connect_to_peer (service_dbus_fd, error)) - return EXIT_FAILURE; + return FALSE; state_transition (APPSTATE_RUNNING); @@ -386,5 +385,5 @@ rpmostree_builtin_start_daemon (int argc, while (appstate == APPSTATE_FLUSHING) g_main_context_iteration (mainctx, TRUE); - return EXIT_SUCCESS; + return TRUE; } diff --git a/src/app/rpmostree-builtin-status.c b/src/app/rpmostree-builtin-status.c index 38c6026dae..0be85417bd 100644 --- a/src/app/rpmostree-builtin-status.c +++ b/src/app/rpmostree-builtin-status.c @@ -654,7 +654,7 @@ status_generic (RPMOSTreeSysroot *sysroot_proxy, return TRUE; } -int +gboolean rpmostree_builtin_status (int argc, char **argv, RpmOstreeCommandInvocation *invocation, @@ -676,18 +676,18 @@ rpmostree_builtin_status (int argc, &sysroot_proxy, &peer_pid, error)) - return EXIT_FAILURE; + return FALSE; if (opt_json && opt_jsonpath) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Cannot specify both --json and --jsonpath"); - return EXIT_FAILURE; + return FALSE; } if (!rpmostree_load_os_proxy (sysroot_proxy, NULL, cancellable, &os_proxy, error)) - return EXIT_FAILURE; + return FALSE; deployments = rpmostree_sysroot_dup_deployments (sysroot_proxy); @@ -716,7 +716,7 @@ rpmostree_builtin_status (int argc, if (!result) { g_prefix_error (error, "While compiling jsonpath: "); - return EXIT_FAILURE; + return FALSE; } json_generator_set_root (generator, result); json_node_free (result); @@ -727,14 +727,14 @@ rpmostree_builtin_status (int argc, glnx_unref_object GOutputStream *stdout_gio = g_unix_output_stream_new (1, FALSE); if (json_generator_to_stream (generator, stdout_gio, NULL, error) <= 0 || (error != NULL && *error != NULL)) - return EXIT_FAILURE; + return FALSE; } else { if (!status_generic (sysroot_proxy, os_proxy, deployments, cancellable, error)) - return EXIT_FAILURE; + return FALSE; } - return EXIT_SUCCESS; + return TRUE; } diff --git a/src/app/rpmostree-builtin-types.h b/src/app/rpmostree-builtin-types.h new file mode 100644 index 0000000000..9d346f3352 --- /dev/null +++ b/src/app/rpmostree-builtin-types.h @@ -0,0 +1,57 @@ +/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- + * + * Copyright (C) 2017 Colin Walters + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#pragma once + +#include "ostree.h" + +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, + RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT = 1 << 1, + RPM_OSTREE_BUILTIN_FLAG_HIDDEN = 1 << 2, + RPM_OSTREE_BUILTIN_FLAG_SUPPORTS_PKG_INSTALLS = 1 << 3, +} RpmOstreeBuiltinFlags; + +typedef struct RpmOstreeCommand RpmOstreeCommand; +typedef struct RpmOstreeCommandInvocation RpmOstreeCommandInvocation; + +struct RpmOstreeCommand { + const char *name; + RpmOstreeBuiltinFlags flags; + const char *description; /* a short decription to describe the functionality */ + int (*fn) (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); +}; + +/* @command: Passed from core cmdline parsing to cmds + * @exit_code: Set by commands; default -1 meaning "if GError is set exit 1, otherwise 0" + */ +struct RpmOstreeCommandInvocation { + RpmOstreeCommand *command; + int exit_code; +}; +G_END_DECLS + diff --git a/src/app/rpmostree-builtin-upgrade.c b/src/app/rpmostree-builtin-upgrade.c index 107d221af2..f6e705c72d 100644 --- a/src/app/rpmostree-builtin-upgrade.c +++ b/src/app/rpmostree-builtin-upgrade.c @@ -54,7 +54,7 @@ static GOptionEntry option_entries[] = { { NULL } }; -int +gboolean rpmostree_builtin_upgrade (int argc, char **argv, RpmOstreeCommandInvocation *invocation, @@ -79,27 +79,27 @@ rpmostree_builtin_upgrade (int argc, &sysroot_proxy, &peer_pid, error)) - return EXIT_FAILURE; + return FALSE; if (opt_reboot && opt_preview) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Cannot specify both --reboot and --preview"); - return EXIT_FAILURE; + return FALSE; } if (opt_reboot && opt_check) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Cannot specify both --reboot and --check"); - return EXIT_FAILURE; + return FALSE; } if (opt_preview && (install_pkgs != NULL || uninstall_pkgs != NULL)) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT, "Cannot specify both --preview and --install/--uninstall"); - return EXIT_FAILURE; + return FALSE; } /* If both --check and --preview were passed, --preview overrides. */ @@ -108,7 +108,7 @@ rpmostree_builtin_upgrade (int argc, if (!rpmostree_load_os_proxy (sysroot_proxy, opt_osname, cancellable, &os_proxy, error)) - return EXIT_FAILURE; + return FALSE; g_autoptr(GVariant) previous_deployment = rpmostree_os_dup_default_deployment (os_proxy); @@ -118,7 +118,7 @@ rpmostree_builtin_upgrade (int argc, &transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; } else { @@ -147,7 +147,7 @@ rpmostree_builtin_upgrade (int argc, &transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; } else { @@ -158,7 +158,7 @@ rpmostree_builtin_upgrade (int argc, NULL, cancellable, error)) - return EXIT_FAILURE; + return FALSE; } } @@ -166,7 +166,7 @@ rpmostree_builtin_upgrade (int argc, transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (opt_preview || opt_check) { @@ -179,10 +179,13 @@ rpmostree_builtin_upgrade (int argc, &details, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (g_variant_n_children (result) == 0) - return RPM_OSTREE_EXIT_UNCHANGED; + { + invocation->exit_code = RPM_OSTREE_EXIT_UNCHANGED; + return TRUE; + } if (!opt_check) rpmostree_print_package_diffs (result); @@ -192,8 +195,8 @@ rpmostree_builtin_upgrade (int argc, if (!rpmostree_has_new_default_deployment (os_proxy, previous_deployment)) { if (opt_upgrade_unchanged_exit_77) - return RPM_OSTREE_EXIT_UNCHANGED; - return EXIT_SUCCESS; + invocation->exit_code = RPM_OSTREE_EXIT_UNCHANGED; + return TRUE; } /* do diff without dbus: https://github.com/projectatomic/rpm-ostree/pull/116 */ @@ -201,10 +204,10 @@ rpmostree_builtin_upgrade (int argc, if (!rpmostree_print_treepkg_diff_from_sysroot_path (sysroot_path, cancellable, error)) - return EXIT_FAILURE; + return FALSE; g_print ("Run \"systemctl reboot\" to start a reboot\n"); } - return EXIT_SUCCESS; + return TRUE; } diff --git a/src/app/rpmostree-builtins.h b/src/app/rpmostree-builtins.h index a607f76172..eeebb4096d 100644 --- a/src/app/rpmostree-builtins.h +++ b/src/app/rpmostree-builtins.h @@ -21,40 +21,11 @@ #pragma once #include "ostree.h" +#include "rpmostree-builtin-types.h" #include "rpmostree-dbus-helpers.h" 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, - RPM_OSTREE_BUILTIN_FLAG_REQUIRES_ROOT = 1 << 1, - RPM_OSTREE_BUILTIN_FLAG_HIDDEN = 1 << 2, - RPM_OSTREE_BUILTIN_FLAG_SUPPORTS_PKG_INSTALLS = 1 << 3, -} RpmOstreeBuiltinFlags; - -typedef struct RpmOstreeCommand RpmOstreeCommand; -typedef struct RpmOstreeCommandInvocation RpmOstreeCommandInvocation; - -struct RpmOstreeCommand { - const char *name; - RpmOstreeBuiltinFlags flags; - const char *description; /* a short decription to describe the functionality */ - int (*fn) (int argc, char **argv, RpmOstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error); -}; - -/* Currently, this has just the command (which is mostly there for the - * name/flags), but in the future if we want to add something new we won't need - * to touch every prototype. - */ -struct RpmOstreeCommandInvocation { - RpmOstreeCommand *command; -}; - #define BUILTINPROTO(name) gboolean rpmostree_builtin_ ## name (int argc, char **argv, \ RpmOstreeCommandInvocation *invocation, \ GCancellable *cancellable, GError **error) diff --git a/src/app/rpmostree-compose-builtin-tree.c b/src/app/rpmostree-compose-builtin-tree.c index 5d03a1cde2..3720afc10c 100644 --- a/src/app/rpmostree-compose-builtin-tree.c +++ b/src/app/rpmostree-compose-builtin-tree.c @@ -1247,24 +1247,24 @@ rpmostree_compose_builtin_install (int argc, cancellable, NULL, NULL, NULL, NULL, error)) - return EXIT_FAILURE; + return FALSE; if (argc != 3) { rpmostree_usage_error (context, "TREEFILE and DESTDIR required", error); - return EXIT_FAILURE; + return FALSE; } if (!opt_repo) { rpmostree_usage_error (context, "--repo must be specified", error); - return EXIT_FAILURE; + return FALSE; } if (opt_workdir) { rpmostree_usage_error (context, "--workdir is ignored with install-root", error); - return EXIT_FAILURE; + return FALSE; } const char *treefile_path = argv[1]; @@ -1274,13 +1274,13 @@ rpmostree_compose_builtin_install (int argc, g_autoptr(RpmOstreeTreeComposeContext) self = NULL; if (!rpm_ostree_compose_context_new (treefile_path, &self, cancellable, error)) - return EXIT_FAILURE; + return FALSE; gboolean changed; if (!impl_install_tree (self, &changed, cancellable, error)) - return EXIT_FAILURE; + return FALSE; g_print ("rootfs: %s/rootfs\n", destdir); - return EXIT_SUCCESS; + return TRUE; } int @@ -1298,12 +1298,12 @@ rpmostree_compose_builtin_postprocess (int argc, cancellable, NULL, NULL, NULL, NULL, error)) - return EXIT_FAILURE; + return FALSE; if (argc < 2 || argc > 3) { rpmostree_usage_error (context, "ROOTFS must be specified", error); - return EXIT_FAILURE; + return FALSE; } const char *rootfs_path = argv[1]; @@ -1319,7 +1319,7 @@ rpmostree_compose_builtin_postprocess (int argc, { treefile_parser = json_parser_new (); if (!json_parser_load_from_file (treefile_parser, treefile_path, error)) - return EXIT_FAILURE; + return FALSE; JsonNode *treefile_rootval = json_parser_get_root (treefile_parser); if (!JSON_NODE_HOLDS_OBJECT (treefile_rootval)) @@ -1329,13 +1329,13 @@ rpmostree_compose_builtin_postprocess (int argc, glnx_fd_close int rootfs_dfd = -1; if (!glnx_opendirat (AT_FDCWD, rootfs_path, TRUE, &rootfs_dfd, error)) - return EXIT_FAILURE; + return FALSE; if (!rpmostree_rootfs_postprocess_common (rootfs_dfd, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (!rpmostree_postprocess_final (rootfs_dfd, treefile, opt_ex_unified_core, cancellable, error)) - return EXIT_FAILURE; - return EXIT_SUCCESS; + return FALSE; + return TRUE; } int @@ -1355,18 +1355,18 @@ rpmostree_compose_builtin_commit (int argc, cancellable, NULL, NULL, NULL, NULL, error)) - return EXIT_FAILURE; + return FALSE; if (argc < 2) { rpmostree_usage_error (context, "TREEFILE must be specified", error); - return EXIT_FAILURE; + return FALSE; } if (!opt_repo) { rpmostree_usage_error (context, "--repo must be specified", error); - return EXIT_FAILURE; + return FALSE; } const char *treefile_path = argv[1]; @@ -1374,12 +1374,12 @@ rpmostree_compose_builtin_commit (int argc, g_autoptr(RpmOstreeTreeComposeContext) self = NULL; if (!rpm_ostree_compose_context_new (treefile_path, &self, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (!glnx_opendirat (AT_FDCWD, rootfs_path, TRUE, &self->rootfs_dfd, error)) - return EXIT_FAILURE; + return FALSE; if (!impl_commit_tree (self, cancellable, error)) - return EXIT_FAILURE; - return EXIT_SUCCESS; + return FALSE; + return TRUE; } int @@ -1401,38 +1401,38 @@ rpmostree_compose_builtin_tree (int argc, cancellable, NULL, NULL, NULL, NULL, error)) - return EXIT_FAILURE; + return FALSE; if (argc < 2) { rpmostree_usage_error (context, "TREEFILE must be specified", error); - return EXIT_FAILURE; + return FALSE; } if (!opt_repo) { rpmostree_usage_error (context, "--repo must be specified", error); - return EXIT_FAILURE; + return FALSE; } const char *treefile_path = argv[1]; g_autoptr(RpmOstreeTreeComposeContext) self = NULL; if (!rpm_ostree_compose_context_new (treefile_path, &self, cancellable, error)) - return EXIT_FAILURE; + return FALSE; gboolean changed; if (!impl_install_tree (self, &changed, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (changed) { /* Do the ostree commit */ if (!impl_commit_tree (self, cancellable, error)) - return EXIT_FAILURE; + return FALSE; /* Finally process the --touch-if-changed option */ if (!process_touch_if_changed (error)) - return EXIT_FAILURE; + return FALSE; } - return EXIT_SUCCESS; + return TRUE; } diff --git a/src/app/rpmostree-container-builtins.c b/src/app/rpmostree-container-builtins.c index ad6c05b8f4..f0ac69150f 100644 --- a/src/app/rpmostree-container-builtins.c +++ b/src/app/rpmostree-container-builtins.c @@ -142,16 +142,16 @@ rpmostree_container_builtin_init (int argc, cancellable, NULL, NULL, NULL, NULL, error)) - return EXIT_FAILURE; + return FALSE; if (!roc_context_init_core (rocctx, error)) - return EXIT_FAILURE; + return FALSE; static const char* const directories[] = { "repo", "rpmmd.repos.d", "cache/rpm-md", "roots", "tmp" }; for (guint i = 0; i < G_N_ELEMENTS (directories); i++) { if (!glnx_shutil_mkdir_p_at (rocctx->userroot_dfd, directories[i], 0755, cancellable, error)) - return EXIT_FAILURE; + return FALSE; } rocctx->repo = ostree_repo_create_at (rocctx->userroot_dfd, "repo", @@ -160,7 +160,7 @@ rpmostree_container_builtin_init (int argc, if (!rocctx->repo) return FALSE; - return EXIT_SUCCESS; + return TRUE; } /* @@ -243,29 +243,29 @@ rpmostree_container_builtin_assemble (int argc, cancellable, NULL, NULL, NULL, NULL, error)) - return EXIT_FAILURE; + return FALSE; if (argc < 1) { rpmostree_usage_error (context, "SPEC must be specified", error); - return EXIT_FAILURE; + return FALSE; } const char *specpath = argv[1]; g_autoptr(RpmOstreeTreespec) treespec = rpmostree_treespec_new_from_path (specpath, error); if (!treespec) - return EXIT_FAILURE; + return FALSE; const char *name = rpmostree_treespec_get_ref (treespec); if (name == NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Missing ref in treespec"); - return EXIT_FAILURE; + return FALSE; } if (!roc_context_init (rocctx, error)) - return EXIT_FAILURE; + return FALSE; const char *target_rootdir = glnx_strjoina (name, ".0"); @@ -273,17 +273,17 @@ rpmostree_container_builtin_assemble (int argc, AT_SYMLINK_NOFOLLOW, error)) { glnx_set_error_from_errno (error); - return EXIT_FAILURE; + return FALSE; } if (errno == 0) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Tree %s already exists", target_rootdir); - return EXIT_FAILURE; + return FALSE; } if (!roc_context_prepare_for_root (rocctx, treespec, cancellable, error)) - return EXIT_FAILURE; + return FALSE; DnfContext *dnfctx = rpmostree_context_get_dnf (rocctx->ctx); if (opt_cache_only) @@ -291,13 +291,13 @@ rpmostree_container_builtin_assemble (int argc, /* --- Resolving dependencies --- */ if (!rpmostree_context_prepare (rocctx->ctx, cancellable, error)) - return EXIT_FAILURE; + return FALSE; rpmostree_print_transaction (rpmostree_context_get_dnf (rocctx->ctx)); g_autofree char *commit = NULL; if (!download_rpms_and_assemble_commit (rocctx, &commit, cancellable, error)) - return EXIT_FAILURE; + return FALSE; g_print ("Checking out %s @ %s...\n", name, commit); { OstreeRepoCheckoutAtOptions opts = { OSTREE_REPO_CHECKOUT_MODE_USER, @@ -307,22 +307,22 @@ rpmostree_container_builtin_assemble (int argc, * management with whatever is running in the root. */ if (!glnx_shutil_rm_rf_at (rocctx->roots_dfd, target_rootdir, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (!ostree_repo_checkout_at (rocctx->repo, &opts, rocctx->roots_dfd, target_rootdir, commit, cancellable, error)) - return EXIT_FAILURE; + return FALSE; } g_print ("Checking out %s @ %s...done\n", name, commit); if (!symlink_at_replace (target_rootdir, rocctx->roots_dfd, name, cancellable, error)) - return EXIT_FAILURE; + return FALSE; g_print ("Creating current symlink...done\n"); - return EXIT_SUCCESS; + return TRUE; } #define APP_VERSION_REGEXP ".+\\.([01])" @@ -380,29 +380,29 @@ rpmostree_container_builtin_upgrade (int argc, char **argv, cancellable, NULL, NULL, NULL, NULL, error)) - return EXIT_FAILURE; + return FALSE; if (argc < 1) { rpmostree_usage_error (context, "NAME must be specified", error); - return EXIT_FAILURE; + return FALSE; } const char *name = argv[1]; if (!roc_context_init (rocctx, error)) - return EXIT_FAILURE; + return FALSE; g_autofree char *target_current_root = glnx_readlinkat_malloc (rocctx->roots_dfd, name, cancellable, error); if (!target_current_root) { g_prefix_error (error, "Reading app link %s: ", name); - return EXIT_FAILURE; + return FALSE; } guint current_version = 2; if (!parse_app_version (target_current_root, ¤t_version, error)) - return EXIT_FAILURE; + return FALSE; g_assert_cmpuint (current_version, <, 2); g_autofree char *commit_checksum = NULL; @@ -410,12 +410,12 @@ rpmostree_container_builtin_upgrade (int argc, char **argv, g_autoptr(GVariant) metadata = NULL; g_autoptr(RpmOstreeTreespec) treespec = NULL; { if (!ostree_repo_resolve_rev (rocctx->repo, name, FALSE, &commit_checksum, error)) - return EXIT_FAILURE; + return FALSE; g_autoptr(GVariant) commit = NULL; if (!ostree_repo_load_variant (rocctx->repo, OSTREE_OBJECT_TYPE_COMMIT, commit_checksum, &commit, error)) - return EXIT_FAILURE; + return FALSE; metadata = g_variant_get_child_value (commit, 0); g_autoptr(GVariantDict) metadata_dict = g_variant_dict_new (metadata); @@ -424,14 +424,14 @@ rpmostree_container_builtin_upgrade (int argc, char **argv, _rpmostree_vardict_lookup_value_required (metadata_dict, "rpmostree.spec", (GVariantType*)"a{sv}", error); if (!spec_v) - return EXIT_FAILURE; + return FALSE; treespec = rpmostree_treespec_new (spec_v); g_autoptr(GVariant) previous_sha512_v = _rpmostree_vardict_lookup_value_required (metadata_dict, "rpmostree.state-sha512", (GVariantType*)"s", error); if (!previous_sha512_v) - return EXIT_FAILURE; + return FALSE; previous_state_sha512 = g_variant_dup_string (previous_sha512_v, NULL); } @@ -444,29 +444,29 @@ rpmostree_container_builtin_upgrade (int argc, char **argv, target_new_root = glnx_strjoina (name, ".1"); if (!roc_context_prepare_for_root (rocctx, treespec, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (!rpmostree_context_prepare (rocctx->ctx, cancellable, error)) - return EXIT_FAILURE; + return FALSE; rpmostree_print_transaction (rpmostree_context_get_dnf (rocctx->ctx)); { g_autofree char *new_state_sha512 = NULL; if (!rpmostree_context_get_state_sha512 (rocctx->ctx, &new_state_sha512, error)) - return EXIT_FAILURE; + return FALSE; if (strcmp (new_state_sha512, previous_state_sha512) == 0) { g_print ("No changes in inputs to %s (%s)\n", name, commit_checksum); /* Note early return */ - return EXIT_SUCCESS; + return TRUE; } } g_autofree char *new_commit_checksum = NULL; if (!download_rpms_and_assemble_commit (rocctx, &new_commit_checksum, cancellable, error)) - return EXIT_FAILURE; + return FALSE; g_print ("Checking out %s @ %s...\n", name, new_commit_checksum); @@ -475,16 +475,16 @@ rpmostree_container_builtin_upgrade (int argc, char **argv, if (!ostree_repo_checkout_at (rocctx->repo, &opts, rocctx->roots_dfd, target_new_root, new_commit_checksum, cancellable, error)) - return EXIT_FAILURE; + return FALSE; } g_print ("Checking out %s @ %s...done\n", name, new_commit_checksum); if (!symlink_at_replace (target_new_root, rocctx->roots_dfd, name, cancellable, error)) - return EXIT_FAILURE; + return FALSE; g_print ("Creating current symlink...done\n"); - return EXIT_SUCCESS; + return TRUE; } diff --git a/src/app/rpmostree-db-builtin-diff.c b/src/app/rpmostree-db-builtin-diff.c index 4b72e24997..5ef0ceef3d 100644 --- a/src/app/rpmostree-db-builtin-diff.c +++ b/src/app/rpmostree-db-builtin-diff.c @@ -44,25 +44,25 @@ rpmostree_db_builtin_diff (int argc, char **argv, g_autoptr(OstreeRepo) repo = NULL; if (!rpmostree_db_option_context_parse (context, option_entries, &argc, &argv, invocation, &repo, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (argc != 3) { g_autofree char *message = g_strdup_printf ("\"%s\" takes exactly 2 arguments", g_get_prgname ()); rpmostree_usage_error (context, message, error); - return EXIT_FAILURE; + return FALSE; } const char *old_ref = argv[1]; g_autofree char *old_checksum = NULL; if (!ostree_repo_resolve_rev (repo, old_ref, FALSE, &old_checksum, error)) - return EXIT_FAILURE; + return FALSE; const char *new_ref = argv[2]; g_autofree char *new_checksum = NULL; if (!ostree_repo_resolve_rev (repo, new_ref, FALSE, &new_checksum, error)) - return EXIT_FAILURE; + return FALSE; if (!g_str_equal (old_ref, old_checksum)) printf ("ostree diff commit old: %s (%s)\n", old_ref, old_checksum); @@ -96,19 +96,16 @@ rpmostree_db_builtin_diff (int argc, char **argv, { if (!rpm_ostree_db_diff (repo, old_ref, new_ref, &removed, &added, &modified_old, &modified_new, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (g_str_equal (opt_format, "diff")) rpmostree_diff_print (removed, added, modified_old, modified_new); else if (g_str_equal (opt_format, "block")) rpmostree_diff_print_formatted (removed, added, modified_old, modified_new); else - { - glnx_throw (error, "Format argument is invalid, pick one of: diff, block"); - return EXIT_FAILURE; - } + return glnx_throw (error, "Format argument is invalid, pick one of: diff, block"); } - return EXIT_SUCCESS; + return TRUE; } diff --git a/src/app/rpmostree-db-builtin-list.c b/src/app/rpmostree-db-builtin-list.c index d630e38a73..ff80005292 100644 --- a/src/app/rpmostree-db-builtin-list.c +++ b/src/app/rpmostree-db-builtin-list.c @@ -89,7 +89,7 @@ rpmostree_db_builtin_list (int argc, char **argv, g_autoptr(OstreeRepo) repo = NULL; if (!rpmostree_db_option_context_parse (context, option_entries, &argc, &argv, invocation, &repo, cancellable, error)) - return EXIT_FAILURE; + return FALSE; /* Iterate over all arguments. When we see the first argument which * appears to be an OSTree commit, take all other arguments to be @@ -119,8 +119,8 @@ rpmostree_db_builtin_list (int argc, char **argv, } if (!_builtin_db_list (repo, revs, patterns, cancellable, error)) - return EXIT_FAILURE; + return FALSE; - return EXIT_SUCCESS; + return TRUE; } diff --git a/src/app/rpmostree-db-builtin-version.c b/src/app/rpmostree-db-builtin-version.c index 63b48cb22f..ec23eb4a82 100644 --- a/src/app/rpmostree-db-builtin-version.c +++ b/src/app/rpmostree-db-builtin-version.c @@ -95,7 +95,7 @@ rpmostree_db_builtin_version (int argc, char **argv, if (!rpmostree_db_option_context_parse (context, db_version_entries, &argc, &argv, invocation, &repo, cancellable, error)) - return EXIT_FAILURE; + return FALSE; g_autoptr(GPtrArray) revs = g_ptr_array_new (); @@ -103,8 +103,8 @@ rpmostree_db_builtin_version (int argc, char **argv, g_ptr_array_add (revs, argv[ii]); if (!_builtin_db_version (repo, revs, cancellable, error)) - return EXIT_FAILURE; + return FALSE; - return EXIT_SUCCESS; + return TRUE; } diff --git a/src/app/rpmostree-dbus-helpers.c b/src/app/rpmostree-dbus-helpers.c index f0de7a4af5..e4a431878d 100644 --- a/src/app/rpmostree-dbus-helpers.c +++ b/src/app/rpmostree-dbus-helpers.c @@ -781,11 +781,10 @@ rpmostree_transaction_get_response_sync (RPMOSTreeSysroot *sysroot_proxy, /* Handles client-side processing for most command line tools * after a transaction has been started. Wraps invocation * of rpmostree_transaction_get_response_sync(). - * - * Returns: A Unix exit code (normally 0 or 1, may be 77 if exit_unchanged_77 is enabled) */ -int -rpmostree_transaction_client_run (RPMOSTreeSysroot *sysroot_proxy, +gboolean +rpmostree_transaction_client_run (RpmOstreeCommandInvocation *invocation, + RPMOSTreeSysroot *sysroot_proxy, RPMOSTreeOS *os_proxy, GVariant *options, gboolean exit_unchanged_77, @@ -797,7 +796,7 @@ rpmostree_transaction_client_run (RPMOSTreeSysroot *sysroot_proxy, /* Wait for the txn to complete */ if (!rpmostree_transaction_get_response_sync (sysroot_proxy, transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; /* Process the result of the txn and our options */ @@ -817,8 +816,8 @@ rpmostree_transaction_client_run (RPMOSTreeSysroot *sysroot_proxy, if (!rpmostree_has_new_default_deployment (os_proxy, previous_deployment)) { if (exit_unchanged_77) - return RPM_OSTREE_EXIT_UNCHANGED; - return EXIT_SUCCESS; + invocation->exit_code = RPM_OSTREE_EXIT_UNCHANGED; + return TRUE; } else { @@ -827,13 +826,13 @@ rpmostree_transaction_client_run (RPMOSTreeSysroot *sysroot_proxy, if (!rpmostree_print_treepkg_diff_from_sysroot_path (sysroot_path, cancellable, error)) - return EXIT_FAILURE; + return FALSE; } g_print ("Run \"systemctl reboot\" to start a reboot\n"); } - return EXIT_SUCCESS; + return TRUE; } void diff --git a/src/app/rpmostree-dbus-helpers.h b/src/app/rpmostree-dbus-helpers.h index be17bcf91d..2c537f5c0a 100644 --- a/src/app/rpmostree-dbus-helpers.h +++ b/src/app/rpmostree-dbus-helpers.h @@ -23,6 +23,7 @@ #include #include "rpm-ostreed-generated.h" +#include "rpmostree-builtin-types.h" #include #include @@ -71,8 +72,9 @@ rpmostree_transaction_get_response_sync (RPMOSTreeSysroot *sysroot_proxy, GCancellable *cancellable, GError **error); -int /* Returns an exit status */ -rpmostree_transaction_client_run (RPMOSTreeSysroot *sysroot_proxy, +gboolean +rpmostree_transaction_client_run (RpmOstreeCommandInvocation *invocation, + RPMOSTreeSysroot *sysroot_proxy, RPMOSTreeOS *os_proxy, GVariant *options, gboolean exit_unchanged_77, diff --git a/src/app/rpmostree-ex-builtin-commit2jigdo.c b/src/app/rpmostree-ex-builtin-commit2jigdo.c index 081cb587b8..991b205927 100644 --- a/src/app/rpmostree-ex-builtin-commit2jigdo.c +++ b/src/app/rpmostree-ex-builtin-commit2jigdo.c @@ -67,18 +67,18 @@ rpmostree_ex_builtin_commit2jigdo (int argc, cancellable, NULL, NULL, NULL, NULL, error)) - return EXIT_FAILURE; + return FALSE; if (argc != 4) { rpmostree_usage_error (context, "REV OIRPM-SPEC OUTPUTDIR are required", error); - return EXIT_FAILURE; + return FALSE; } if (!(opt_repo && opt_pkgcache_repo)) { rpmostree_usage_error (context, "--repo and --pkgcache-repo must be specified", error); - return EXIT_FAILURE; + return FALSE; } const char *rev = argv[1]; @@ -89,13 +89,13 @@ rpmostree_ex_builtin_commit2jigdo (int argc, g_autoptr(OstreeRepo) repo = ostree_repo_open_at (AT_FDCWD, opt_repo, cancellable, error); if (!repo) - return EXIT_FAILURE; + return FALSE; g_autoptr(OstreeRepo) pkgcache_repo = ostree_repo_open_at (AT_FDCWD, opt_pkgcache_repo, cancellable, error); if (!pkgcache_repo) - return EXIT_FAILURE; + return FALSE; if (!rpmostree_commit2jigdo (repo, pkgcache_repo, rev, oirpm_spec, outputdir, cancellable, error)) - return EXIT_FAILURE; + return FALSE; - return EXIT_SUCCESS; + return TRUE; } diff --git a/src/app/rpmostree-ex-builtin-jigdo2commit.c b/src/app/rpmostree-ex-builtin-jigdo2commit.c index a1c34d1af7..0e395532ab 100644 --- a/src/app/rpmostree-ex-builtin-jigdo2commit.c +++ b/src/app/rpmostree-ex-builtin-jigdo2commit.c @@ -149,27 +149,27 @@ rpmostree_ex_builtin_jigdo2commit (int argc, cancellable, NULL, NULL, NULL, NULL, error)) - return EXIT_FAILURE; + return FALSE; if (argc != 2) { rpmostree_usage_error (context, "REPOID:OIRPM-NAME is required", error); - return EXIT_FAILURE; + return FALSE; } if (!opt_repo) { rpmostree_usage_error (context, "--repo must be specified", error); - return EXIT_FAILURE; + return FALSE; } const char *oirpm = argv[1]; g_autoptr(RpmOstreeJigdo2CommitContext) self = NULL; if (!rpm_ostree_jigdo2commit_context_new (&self, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (!impl_jigdo2commit (self, oirpm, cancellable, error)) - return EXIT_FAILURE; + return FALSE; - return EXIT_SUCCESS; + return TRUE; } diff --git a/src/app/rpmostree-override-builtins.c b/src/app/rpmostree-override-builtins.c index 86cc964ff1..2094401554 100644 --- a/src/app/rpmostree-override-builtins.c +++ b/src/app/rpmostree-override-builtins.c @@ -55,7 +55,7 @@ handle_override (RPMOSTreeSysroot *sysroot_proxy, glnx_unref_object RPMOSTreeOS *os_proxy = NULL; if (!rpmostree_load_os_proxy (sysroot_proxy, opt_osname, cancellable, &os_proxy, error)) - return EXIT_FAILURE; + return FALSE; /* Perform uninstalls offline; users don't expect the "auto-update" behaviour here. But * note we might still need to fetch pkgs in the local replacement case (e.g. the @@ -85,13 +85,13 @@ handle_override (RPMOSTreeSysroot *sysroot_proxy, &transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (!rpmostree_transaction_get_response_sync (sysroot_proxy, transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; if (opt_dry_run) { @@ -104,12 +104,12 @@ handle_override (RPMOSTreeSysroot *sysroot_proxy, if (!rpmostree_print_treepkg_diff_from_sysroot_path (sysroot_path, cancellable, error)) - return EXIT_FAILURE; + return FALSE; g_print ("Run \"systemctl reboot\" to start a reboot\n"); } - return EXIT_SUCCESS; + return TRUE; } gboolean @@ -134,13 +134,13 @@ rpmostree_override_builtin_replace (int argc, char **argv, &sysroot_proxy, &peer_pid, error)) - return EXIT_FAILURE; + return FALSE; if (argc < 2) { rpmostree_usage_error (context, "At least one PACKAGE must be specified", error); - return EXIT_FAILURE; + return FALSE; } /* shift to first pkgspec and ensure it's a proper strv (previous parsing @@ -175,13 +175,13 @@ rpmostree_override_builtin_remove (int argc, char **argv, &sysroot_proxy, &peer_pid, error)) - return EXIT_FAILURE; + return FALSE; if (argc < 2) { rpmostree_usage_error (context, "At least one PACKAGE must be specified", error); - return EXIT_FAILURE; + return FALSE; } /* shift to first pkgspec and ensure it's a proper strv (previous parsing @@ -218,19 +218,19 @@ rpmostree_override_builtin_reset (int argc, char **argv, &sysroot_proxy, &peer_pid, error)) - return EXIT_FAILURE; + return FALSE; if (argc < 2 && !opt_reset_all) { rpmostree_usage_error (context, "At least one PACKAGE must be specified", error); - return EXIT_FAILURE; + return FALSE; } else if (opt_reset_all && argc >= 2) { rpmostree_usage_error (context, "Cannot specify PACKAGEs with --all", error); - return EXIT_FAILURE; + return FALSE; } /* shift to first pkgspec and ensure it's a proper strv (previous parsing diff --git a/src/app/rpmostree-pkg-builtins.c b/src/app/rpmostree-pkg-builtins.c index fed75d49a6..2fe0450d0b 100644 --- a/src/app/rpmostree-pkg-builtins.c +++ b/src/app/rpmostree-pkg-builtins.c @@ -56,8 +56,9 @@ static GOptionEntry install_option_entry[] = { { NULL } }; -static int -pkg_change (RPMOSTreeSysroot *sysroot_proxy, +static gboolean +pkg_change (RpmOstreeCommandInvocation *invocation, + RPMOSTreeSysroot *sysroot_proxy, const char *const* packages_to_add, const char *const* packages_to_remove, GCancellable *cancellable, @@ -73,7 +74,7 @@ pkg_change (RPMOSTreeSysroot *sysroot_proxy, glnx_unref_object RPMOSTreeOS *os_proxy = NULL; if (!rpmostree_load_os_proxy (sysroot_proxy, opt_osname, cancellable, &os_proxy, error)) - return EXIT_FAILURE; + return FALSE; g_autoptr(GVariant) previous_deployment = rpmostree_os_dup_default_deployment (os_proxy); g_autoptr(GVariant) options = @@ -106,7 +107,7 @@ pkg_change (RPMOSTreeSysroot *sysroot_proxy, &transaction_address, cancellable, error)) - return EXIT_FAILURE; + return FALSE; } else { @@ -119,17 +120,17 @@ pkg_change (RPMOSTreeSysroot *sysroot_proxy, NULL, cancellable, error)) - return EXIT_FAILURE; + return FALSE; } - return rpmostree_transaction_client_run (sysroot_proxy, os_proxy, + return rpmostree_transaction_client_run (invocation, sysroot_proxy, os_proxy, options, FALSE, transaction_address, previous_deployment, cancellable, error); } -int +gboolean rpmostree_builtin_install (int argc, char **argv, RpmOstreeCommandInvocation *invocation, @@ -153,12 +154,12 @@ rpmostree_builtin_install (int argc, &sysroot_proxy, &peer_pid, error)) - return EXIT_FAILURE; + return FALSE; if (argc < 2) { rpmostree_usage_error (context, "At least one PACKAGE must be specified", error); - return EXIT_FAILURE; + return FALSE; } /* shift to first pkgspec and ensure it's a proper strv (previous parsing @@ -166,13 +167,13 @@ rpmostree_builtin_install (int argc, argv++; argc--; argv[argc] = NULL; - return pkg_change (sysroot_proxy, + return pkg_change (invocation, sysroot_proxy, (const char *const*)argv, (const char *const*)opt_uninstall, cancellable, error); } -int +gboolean rpmostree_builtin_uninstall (int argc, char **argv, RpmOstreeCommandInvocation *invocation, @@ -196,12 +197,12 @@ rpmostree_builtin_uninstall (int argc, &sysroot_proxy, &peer_pid, error)) - return EXIT_FAILURE; + return FALSE; if (argc < 2) { rpmostree_usage_error (context, "At least one PACKAGE must be specified", error); - return EXIT_FAILURE; + return FALSE; } /* shift to first pkgspec and ensure it's a proper strv (previous parsing @@ -214,7 +215,7 @@ rpmostree_builtin_uninstall (int argc, if (!opt_install) opt_cache_only = TRUE; - return pkg_change (sysroot_proxy, + return pkg_change (invocation, sysroot_proxy, (const char *const*)opt_install, (const char *const*)argv, cancellable, error);