From 46e1db392d59e6956d705037feaf6c64b8a15a16 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 14 Jun 2022 09:50:07 -0400 Subject: [PATCH 1/3] cli/os-init: Port to C99 style General background cleanup; motivated by a recent PR which was using pre-C99 code as a base. --- src/ostree/ot-admin-builtin-os-init.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/ostree/ot-admin-builtin-os-init.c b/src/ostree/ot-admin-builtin-os-init.c index cb1ec66d..05311532 100644 --- a/src/ostree/ot-admin-builtin-os-init.c +++ b/src/ostree/ot-admin-builtin-os-init.c @@ -35,35 +35,29 @@ static GOptionEntry options[] = { gboolean ot_admin_builtin_os_init (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; + g_autoptr(GOptionContext) context = g_option_context_new ("OSNAME"); + g_autoptr(OstreeSysroot) sysroot = NULL; - gboolean ret = FALSE; - const char *osname = NULL; - - context = g_option_context_new ("OSNAME"); - if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER | OSTREE_ADMIN_BUILTIN_FLAG_UNLOCKED, invocation, &sysroot, cancellable, error)) - goto out; + return FALSE; if (!ostree_sysroot_ensure_initialized (sysroot, cancellable, error)) - goto out; + return FALSE; if (argc < 2) { ot_util_usage_error (context, "OSNAME must be specified", error); - goto out; + return FALSE; } - osname = argv[1]; + const char *osname = argv[1]; if (!ostree_sysroot_init_osname (sysroot, osname, cancellable, error)) - goto out; + return FALSE; g_print ("ostree/deploy/%s initialized as OSTree root\n", osname); - ret = TRUE; - out: - return ret; + return TRUE; } From 588b07e5542106eb3baef046f7858b9c6f56736f Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 14 Jun 2022 09:50:07 -0400 Subject: [PATCH 2/3] cli/undeploy: Port to C99 style General background cleanup. --- src/ostree/ot-admin-builtin-undeploy.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/ostree/ot-admin-builtin-undeploy.c b/src/ostree/ot-admin-builtin-undeploy.c index 41155689..c079c83f 100644 --- a/src/ostree/ot-admin-builtin-undeploy.c +++ b/src/ostree/ot-admin-builtin-undeploy.c @@ -34,15 +34,9 @@ static GOptionEntry options[] = { gboolean ot_admin_builtin_undeploy (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { - g_autoptr(GOptionContext) context = NULL; + g_autoptr(GOptionContext) context = g_option_context_new ("INDEX"); + g_autoptr(OstreeSysroot) sysroot = NULL; - const char *deploy_index_str; - int deploy_index; - g_autoptr(GPtrArray) current_deployments = NULL; - g_autoptr(OstreeDeployment) target_deployment = NULL; - - context = g_option_context_new ("INDEX"); - if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, invocation, &sysroot, cancellable, error)) @@ -54,12 +48,13 @@ ot_admin_builtin_undeploy (int argc, char **argv, OstreeCommandInvocation *invoc return FALSE; } - current_deployments = ostree_sysroot_get_deployments (sysroot); + g_autoptr(GPtrArray) current_deployments = ostree_sysroot_get_deployments (sysroot); - deploy_index_str = argv[1]; - deploy_index = atoi (deploy_index_str); + const char *deploy_index_str = argv[1]; + int deploy_index = atoi (deploy_index_str); - target_deployment = ot_admin_get_indexed_deployment (sysroot, deploy_index, error); + g_autoptr(OstreeDeployment) target_deployment = + ot_admin_get_indexed_deployment (sysroot, deploy_index, error); if (!target_deployment) return FALSE; From 4e356d0e8fde00ec8b283f0ec946fcdd1b833aa6 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 14 Jun 2022 09:50:07 -0400 Subject: [PATCH 3/3] cli/unlock: Port to C99 style General background cleanup. --- src/ostree/ot-admin-builtin-unlock.c | 29 +++++++++++----------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/ostree/ot-admin-builtin-unlock.c b/src/ostree/ot-admin-builtin-unlock.c index 800c0744..f438a13e 100644 --- a/src/ostree/ot-admin-builtin-unlock.c +++ b/src/ostree/ot-admin-builtin-unlock.c @@ -40,33 +40,28 @@ static GOptionEntry options[] = { gboolean ot_admin_builtin_unlock (int argc, char **argv, OstreeCommandInvocation *invocation, GCancellable *cancellable, GError **error) { - gboolean ret = FALSE; - g_autoptr(GOptionContext) context = NULL; + g_autoptr(GOptionContext) context = g_option_context_new (""); + g_autoptr(OstreeSysroot) sysroot = NULL; - OstreeDeployment *booted_deployment = NULL; - OstreeDeploymentUnlockedState target_state; - - context = g_option_context_new (""); - if (!ostree_admin_option_context_parse (context, options, &argc, &argv, OSTREE_ADMIN_BUILTIN_FLAG_SUPERUSER, invocation, &sysroot, cancellable, error)) - goto out; + return FALSE; if (argc > 1) { ot_util_usage_error (context, "This command takes no extra arguments", error); - goto out; + return FALSE; } - booted_deployment = ostree_sysroot_require_booted_deployment (sysroot, error); + OstreeDeployment *booted_deployment = ostree_sysroot_require_booted_deployment (sysroot, error); if (!booted_deployment) - goto out; + return FALSE; + OstreeDeploymentUnlockedState target_state; if (opt_hotfix && opt_transient) { - glnx_throw (error, "Cannot specify both --hotfix and --transient"); - goto out; + return glnx_throw (error, "Cannot specify both --hotfix and --transient"); } else if (opt_hotfix) target_state = OSTREE_DEPLOYMENT_UNLOCKED_HOTFIX; @@ -77,8 +72,8 @@ ot_admin_builtin_unlock (int argc, char **argv, OstreeCommandInvocation *invocat if (!ostree_sysroot_deployment_unlock (sysroot, booted_deployment, target_state, cancellable, error)) - goto out; - + return FALSE; + switch (target_state) { case OSTREE_DEPLOYMENT_UNLOCKED_NONE: @@ -99,7 +94,5 @@ ot_admin_builtin_unlock (int argc, char **argv, OstreeCommandInvocation *invocat break; } - ret = TRUE; - out: - return ret; + return TRUE; }