From 420e5f706a301ae857f23f8e00c9c3b04d3fde02 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Tue, 19 Feb 2013 11:02:33 -0500 Subject: [PATCH] admin: Use /sysroot/ostree automatically When booted inside an ostree system, we want /sysroot/ostree, not just /ostree by default. --- src/ostree/ot-admin-builtin-run-triggers.c | 16 +------- src/ostree/ot-admin-functions.c | 45 +++++++++------------- src/ostree/ot-admin-functions.h | 6 +-- src/ostree/ot-builtin-admin.c | 13 ++++++- 4 files changed, 33 insertions(+), 47 deletions(-) diff --git a/src/ostree/ot-admin-builtin-run-triggers.c b/src/ostree/ot-admin-builtin-run-triggers.c index 9adbf0f0..3c3df5d3 100644 --- a/src/ostree/ot-admin-builtin-run-triggers.c +++ b/src/ostree/ot-admin-builtin-run-triggers.c @@ -48,21 +48,7 @@ ot_admin_builtin_run_triggers (int argc, char **argv, OtAdminBuiltinOpts *admin_ if (!g_option_context_parse (context, &argc, &argv, error)) goto out; - if (argc >= 2) - { - rootdir = g_file_new_for_path (argv[1]); - } - else - { - if (!ot_admin_get_sysroot_from_proc_cmdline (&rootdir, cancellable, error)) - goto out; - if (rootdir == NULL) - { - g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, - "No ostree= kernel argument found"); - goto out; - } - } + rootdir = g_file_new_for_path (argv[1]); if (!ostree_run_triggers_in_root (rootdir, cancellable, error)) goto out; diff --git a/src/ostree/ot-admin-functions.c b/src/ostree/ot-admin-functions.c index e6903bb2..6cc4ff0f 100644 --- a/src/ostree/ot-admin-functions.c +++ b/src/ostree/ot-admin-functions.c @@ -182,39 +182,30 @@ ot_admin_get_previous_deployment (GFile *ostree_dir, } gboolean -ot_admin_get_sysroot_from_proc_cmdline (GFile **out_deploy_target, - GCancellable *cancellable, - GError **error) +ot_admin_get_default_ostree_dir (GFile **out_ostree_dir, + GCancellable *cancellable, + GError **error) { gboolean ret = FALSE; - gs_unref_object GFile *proc_cmdline = g_file_new_for_path ("/proc/cmdline"); - gs_unref_object GFile *ret_deploy_target = NULL; - gs_free char *contents = NULL; - gsize contents_len; - char **cmdline_argv = NULL; - char **iter; + gs_unref_object GFile *possible_ostree_dir = NULL; + gs_unref_object GFile *ret_ostree_dir = NULL; - if (!g_file_load_contents (proc_cmdline, cancellable, &contents, &contents_len, NULL, - error)) - goto out; - - cmdline_argv = g_strsplit (contents, " ", -1); - - for (iter = cmdline_argv; *iter; iter++) + if (ret_ostree_dir == NULL) { - const char *arg = *iter; - if (strncmp (arg, "ostree=", 7) == 0) - { - gs_free char *subpath = g_strdup (arg + 7); - gs_unref_object GFile *deploydir = g_file_new_for_path ("/sysroot/ostree/deploy"); - ret_deploy_target = g_file_resolve_relative_path (deploydir, subpath); - break; - } + g_clear_object (&possible_ostree_dir); + possible_ostree_dir = g_file_new_for_path ("/sysroot/ostree"); + if (g_file_query_exists (possible_ostree_dir, NULL)) + ret_ostree_dir = g_object_ref (possible_ostree_dir); + } + if (ret_ostree_dir == NULL) + { + g_clear_object (&possible_ostree_dir); + possible_ostree_dir = g_file_new_for_path ("/ostree"); + if (g_file_query_exists (possible_ostree_dir, NULL)) + ret_ostree_dir = g_object_ref (possible_ostree_dir); } ret = TRUE; - ot_transfer_out_value (out_deploy_target, &ret_deploy_target); - out: - g_strfreev (cmdline_argv); + ot_transfer_out_value (out_ostree_dir, &ret_ostree_dir); return ret; } diff --git a/src/ostree/ot-admin-functions.h b/src/ostree/ot-admin-functions.h index 766a3e38..c189b242 100644 --- a/src/ostree/ot-admin-functions.h +++ b/src/ostree/ot-admin-functions.h @@ -42,9 +42,9 @@ gboolean ot_admin_get_previous_deployment (GFile *ostree_dir, GCancellable *cancellable, GError **error); -gboolean ot_admin_get_sysroot_from_proc_cmdline (GFile **out_deploy_target, - GCancellable *cancellable, - GError **error); +gboolean ot_admin_get_default_ostree_dir (GFile **out_ostree_dir, + GCancellable *cancellable, + GError **error); G_END_DECLS diff --git a/src/ostree/ot-builtin-admin.c b/src/ostree/ot-builtin-admin.c index 1f236476..c8f60fb3 100644 --- a/src/ostree/ot-builtin-admin.c +++ b/src/ostree/ot-builtin-admin.c @@ -24,13 +24,14 @@ #include "ot-builtins.h" #include "ot-admin-builtins.h" +#include "ot-admin-functions.h" #include "ot-main.h" #include "ostree.h" #include "ostree-repo-file.h" #include -static char *opt_ostree_dir = "/ostree"; +static char *opt_ostree_dir = NULL; static char *opt_boot_dir = "/boot"; static GOptionEntry options[] = { @@ -116,7 +117,15 @@ ostree_builtin_admin (int argc, char **argv, GFile *repo_path, GError **error) goto out; } - ostree_dir = g_file_new_for_path (opt_ostree_dir); + if (opt_ostree_dir != NULL) + { + ostree_dir = g_file_new_for_path (opt_ostree_dir); + } + else + { + if (!ot_admin_get_default_ostree_dir (&ostree_dir, cancellable, error)) + goto out; + } boot_dir = g_file_new_for_path (opt_boot_dir); ostree_prep_builtin_argv (subcommand_name, argc-2, argv+2, &subcmd_argc, &subcmd_argv);