admin: Use /sysroot/ostree automatically
When booted inside an ostree system, we want /sysroot/ostree, not just /ostree by default.
This commit is contained in:
parent
c9f56564a3
commit
420e5f706a
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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 <glib/gi18n.h>
|
||||
|
||||
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);
|
||||
|
|
|
|||
Loading…
Reference in New Issue