mirror of
https://github.com/ostreedev/ostree.git
synced 2025-03-14 04:59:00 +03:00
admin: Add new run-triggers command
In some cases we want the ability to run triggers independently of checking out a tree. For example, due to kernel limitations which impact the gnome-ostree build system, we may need to run triggers on first boot via systemd. Secondarily, if the user installs a system extension which adds a new shared library to /usr/lib for example, the system will need to run the triggers again. Also, I think I want to take triggers out of the core and put them in ostree admin anyways.
This commit is contained in:
parent
3832544ac4
commit
0ab1f78ec8
@ -55,6 +55,7 @@ ostree_SOURCES += \
|
||||
src/ostree/ot-admin-builtin-pull-deploy.c \
|
||||
src/ostree/ot-admin-builtin-os-init.c \
|
||||
src/ostree/ot-admin-builtin-install.c \
|
||||
src/ostree/ot-admin-builtin-run-triggers.c \
|
||||
src/ostree/ot-admin-builtin-upgrade.c \
|
||||
src/ostree/ot-admin-builtin-update-kernel.c \
|
||||
src/ostree/ot-admin-builtins.h \
|
||||
|
75
src/ostree/ot-admin-builtin-run-triggers.c
Normal file
75
src/ostree/ot-admin-builtin-run-triggers.c
Normal file
@ -0,0 +1,75 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
||||
*
|
||||
* Copyright (C) 2012 Colin Walters <walters@verbum.org>
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* Author: Colin Walters <walters@verbum.org>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "ot-admin-builtins.h"
|
||||
#include "ot-admin-functions.h"
|
||||
#include "ostree.h"
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <glib/gi18n.h>
|
||||
|
||||
static GOptionEntry options[] = {
|
||||
{ NULL }
|
||||
};
|
||||
|
||||
gboolean
|
||||
ot_admin_builtin_run_triggers (int argc, char **argv, GFile *ostree_dir, GError **error)
|
||||
{
|
||||
GOptionContext *context;
|
||||
gboolean ret = FALSE;
|
||||
ot_lobj GFile *rootdir = NULL;
|
||||
__attribute__((unused)) GCancellable *cancellable = NULL;
|
||||
|
||||
context = g_option_context_new ("[ROOT] - Run triggers (regenerate caches, etc.)");
|
||||
g_option_context_add_main_entries (context, options, NULL);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
if (!ostree_run_triggers_in_root (rootdir, cancellable, error))
|
||||
goto out;
|
||||
|
||||
ret = TRUE;
|
||||
out:
|
||||
if (context)
|
||||
g_option_context_free (context);
|
||||
return ret;
|
||||
}
|
@ -34,6 +34,7 @@ gboolean ot_admin_builtin_deploy (int argc, char **argv, GFile *ostree_dir, GErr
|
||||
gboolean ot_admin_builtin_prune (int argc, char **argv, GFile *ostree_dir, GError **error);
|
||||
gboolean ot_admin_builtin_pull_deploy (int argc, char **argv, GFile *ostree_dir, GError **error);
|
||||
gboolean ot_admin_builtin_diff (int argc, char **argv, GFile *ostree_dir, GError **error);
|
||||
gboolean ot_admin_builtin_run_triggers (int argc, char **argv, GFile *ostree_dir, GError **error);
|
||||
gboolean ot_admin_builtin_update_kernel (int argc, char **argv, GFile *ostree_dir, GError **error);
|
||||
gboolean ot_admin_builtin_upgrade (int argc, char **argv, GFile *ostree_dir, GError **error);
|
||||
|
||||
|
@ -180,3 +180,41 @@ ot_admin_get_previous_deployment (GFile *ostree_dir,
|
||||
return query_symlink_target_allow_noent (previous_path, out_deployment,
|
||||
cancellable, error);
|
||||
}
|
||||
|
||||
gboolean
|
||||
ot_admin_get_sysroot_from_proc_cmdline (GFile **out_deploy_target,
|
||||
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;
|
||||
|
||||
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++)
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
ret = TRUE;
|
||||
ot_transfer_out_value (out_deploy_target, &ret_deploy_target);
|
||||
out:
|
||||
g_strfreev (cmdline_argv);
|
||||
return ret;
|
||||
}
|
||||
|
@ -42,6 +42,10 @@ 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);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif
|
||||
|
@ -52,6 +52,7 @@ static OstreeAdminCommand admin_subcommands[] = {
|
||||
{ "prune", ot_admin_builtin_prune },
|
||||
{ "update-kernel", ot_admin_builtin_update_kernel },
|
||||
{ "config-diff", ot_admin_builtin_diff },
|
||||
{ "run-triggers", ot_admin_builtin_run_triggers },
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user