[ostree/wip/anaconda: 4/6] libostree: Add ostree_sysroot_deployment_set_kargs()



commit 4309b49866917dbb86773efabcc4f21ab8446d28
Author: Colin Walters <walters verbum org>
Date:   Mon Mar 17 19:24:10 2014 -0400

    libostree: Add ostree_sysroot_deployment_set_kargs()
    
    It turns out people sometimes want to be able to change the kernel
    arguments.  Add a convenient API to do so for the current deployment.
    
    This will be used by Anaconda.

 src/libostree/ostree-sysroot-deploy.c |   52 +++++++++++++++++++++++++++++++++
 src/libostree/ostree-sysroot.c        |    1 -
 src/libostree/ostree-sysroot.h        |    6 ++++
 3 files changed, 58 insertions(+), 1 deletions(-)
---
diff --git a/src/libostree/ostree-sysroot-deploy.c b/src/libostree/ostree-sysroot-deploy.c
index 7fa193c..e2d6f05 100644
--- a/src/libostree/ostree-sysroot-deploy.c
+++ b/src/libostree/ostree-sysroot-deploy.c
@@ -1437,3 +1437,55 @@ ostree_sysroot_deploy_tree (OstreeSysroot     *self,
   return ret;
 }
 
+/**
+ * ostree_sysroot_deployment_set_kargs:
+ * @self: Sysroot
+ * @deployment: A deployment
+ * @new_kargs: (array zero-terminated=1) (element-type utf8): Replace deployment's kernel arguments
+ * @cancellable: Cancellable
+ * @error: Error
+ *
+ * Entirely replace the kernel arguments of @deployment with the
+ * values in @new_kargs.
+ */
+gboolean
+ostree_sysroot_deployment_set_kargs (OstreeSysroot     *self,
+                                     OstreeDeployment  *deployment,
+                                     char             **new_kargs,
+                                     GCancellable      *cancellable,
+                                     GError           **error)
+{
+  gboolean ret = FALSE;
+  guint i;
+  gs_unref_ptrarray GPtrArray *new_deployments = g_ptr_array_new_with_free_func (g_object_unref);
+  gs_unref_object OstreeDeployment *new_deployment = NULL;
+  __attribute__((cleanup(_ostree_kernel_args_cleanup))) OstreeKernelArgs *kargs = NULL;
+  gs_free char *new_options = NULL;
+  OstreeBootconfigParser *new_bootconfig;
+
+  new_deployment = ostree_deployment_clone (deployment);
+  new_bootconfig = ostree_deployment_get_bootconfig (new_deployment);
+
+  kargs = _ostree_kernel_args_new ();
+  _ostree_kernel_args_append_argv (kargs, new_kargs);
+  new_options = _ostree_kernel_args_to_string (kargs);
+  ostree_bootconfig_parser_set (new_bootconfig, "options", new_options);
+
+  for (i = 0; i < self->deployments->len; i++)
+    {
+      OstreeDeployment *cur = self->deployments->pdata[i];
+      if (cur == deployment)
+        g_ptr_array_add (new_deployments, g_object_ref (new_deployment));
+      else
+        g_ptr_array_add (new_deployments, g_object_ref (cur));
+    }
+
+  if (!ostree_sysroot_write_deployments (self, new_deployments,
+                                         cancellable, error))
+    goto out;
+
+  ret = TRUE;
+ out:
+  return ret;
+}
+
diff --git a/src/libostree/ostree-sysroot.c b/src/libostree/ostree-sysroot.c
index fcbd3dc..70186a5 100644
--- a/src/libostree/ostree-sysroot.c
+++ b/src/libostree/ostree-sysroot.c
@@ -1029,4 +1029,3 @@ ostree_sysroot_origin_new_from_refspec (OstreeSysroot  *sysroot,
   g_key_file_set_string (ret, "origin", "refspec", refspec);
   return ret;
 }
-
diff --git a/src/libostree/ostree-sysroot.h b/src/libostree/ostree-sysroot.h
index fbf3dff..ec4513b 100644
--- a/src/libostree/ostree-sysroot.h
+++ b/src/libostree/ostree-sysroot.h
@@ -66,6 +66,12 @@ gboolean ostree_sysroot_get_repo (OstreeSysroot         *self,
                                   GCancellable          *cancellable,
                                   GError               **error);
 
+gboolean ostree_sysroot_deployment_set_kargs (OstreeSysroot     *self,
+                                              OstreeDeployment  *deployment,
+                                              char             **new_kargs,
+                                              GCancellable      *cancellable,
+                                              GError           **error);
+
 gboolean ostree_sysroot_write_deployments (OstreeSysroot     *self,
                                            GPtrArray         *new_deployments,
                                            GCancellable      *cancellable,


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