[ostree] admin: Add new run-triggers command



commit 0ab1f78ec81b36ee02650f85ce806a894dc03a53
Author: Colin Walters <walters verbum org>
Date:   Sat Dec 22 13:43:44 2012 -0500

    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.

 Makefile-ostree.am                         |    1 +
 src/ostree/ot-admin-builtin-run-triggers.c |   75 ++++++++++++++++++++++++++++
 src/ostree/ot-admin-builtins.h             |    1 +
 src/ostree/ot-admin-functions.c            |   38 ++++++++++++++
 src/ostree/ot-admin-functions.h            |    4 ++
 src/ostree/ot-builtin-admin.c              |    1 +
 6 files changed, 120 insertions(+), 0 deletions(-)
---
diff --git a/Makefile-ostree.am b/Makefile-ostree.am
index 0066765..bc5bba5 100644
--- a/Makefile-ostree.am
+++ b/Makefile-ostree.am
@@ -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 \
diff --git a/src/ostree/ot-admin-builtin-run-triggers.c b/src/ostree/ot-admin-builtin-run-triggers.c
new file mode 100644
index 0000000..7c146cd
--- /dev/null
+++ b/src/ostree/ot-admin-builtin-run-triggers.c
@@ -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;
+}
diff --git a/src/ostree/ot-admin-builtins.h b/src/ostree/ot-admin-builtins.h
index 2d535f0..d6decd4 100644
--- a/src/ostree/ot-admin-builtins.h
+++ b/src/ostree/ot-admin-builtins.h
@@ -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);
 
diff --git a/src/ostree/ot-admin-functions.c b/src/ostree/ot-admin-functions.c
index 7623062..e6903bb 100644
--- a/src/ostree/ot-admin-functions.c
+++ b/src/ostree/ot-admin-functions.c
@@ -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;
+}
diff --git a/src/ostree/ot-admin-functions.h b/src/ostree/ot-admin-functions.h
index 3c21ad1..766a3e3 100644
--- a/src/ostree/ot-admin-functions.h
+++ b/src/ostree/ot-admin-functions.h
@@ -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
diff --git a/src/ostree/ot-builtin-admin.c b/src/ostree/ot-builtin-admin.c
index e80ac03..831e80c 100644
--- a/src/ostree/ot-builtin-admin.c
+++ b/src/ostree/ot-builtin-admin.c
@@ -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 }
 };
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]