summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen W. Taylor <otaylor@fishsoup.net>2014-09-23 11:16:53 -0400
committerOwen W. Taylor <otaylor@fishsoup.net>2014-09-26 10:40:37 -0400
commit262cba09c0bfdcd5f13dea63369b451d817d871f (patch)
tree4b33a9b1ab514071698de6849eb9f4cf6ac5ee79
parentedf9cf5a7f0a44895cc3fc0918b427283d129b25 (diff)
downloadostree-262cba09c0bfdcd5f13dea63369b451d817d871f.tar.gz
ostree admin instutil set-kargs: make more flexible
Add command line arguments: --import-proc-cmdline: import values from /proc/cmdline --merge: import current values --replace=ARG=VALUE: replace value --append=ARG=VALUE: append a new argument Extra command line arguments are treated like --append=, which gives backwards compatibility. https://bugzilla.gnome.org/show_bug.cgi?id=731051
-rw-r--r--doc/ostree-admin-instutil.xml7
-rw-r--r--src/libostree/ostree-kernel-args.c24
-rw-r--r--src/libostree/ostree-kernel-args.h4
-rw-r--r--src/ostree/ot-admin-builtin-deploy.c14
-rw-r--r--src/ostree/ot-admin-instutil-builtin-set-kargs.c59
5 files changed, 84 insertions, 24 deletions
diff --git a/doc/ostree-admin-instutil.xml b/doc/ostree-admin-instutil.xml
index 349ced2d..3481384f 100644
--- a/doc/ostree-admin-instutil.xml
+++ b/doc/ostree-admin-instutil.xml
@@ -75,10 +75,13 @@ Boston, MA 02111-1307, USA.
</varlistentry>
<varlistentry>
- <term><command>set-kargs</command></term>
+ <term><command>set-kargs <arg choice="opt">--merge</arg> <arg choice="opt">--import-proc-cmdline</arg> <arg choice="opt">--append=ARG</arg> <arg choice="opt">--replace=ARG</arg> <arg choice="opt">MORE_APPEND_ARGS</arg></command></term>
<listitem><para>
- Replace the kernel arguments of the default deployment.
+ Replace the kernel arguments of the default deployment. The new arguments are based
+ on an empty list (the default), the current options (--merge), or the arguments
+ of the loaded kernel (--import-proc-cmdline), and new options either are added to the
+ end (--append=ARG) or replace existing arguments of the same name (--replace=ARG).
</para></listitem>
</varlistentry>
</variablelist>
diff --git a/src/libostree/ostree-kernel-args.c b/src/libostree/ostree-kernel-args.c
index f31932ed..524b9cdd 100644
--- a/src/libostree/ostree-kernel-args.c
+++ b/src/libostree/ostree-kernel-args.c
@@ -21,6 +21,7 @@
#include "config.h"
#include "ostree-kernel-args.h"
+#include "libgsystem.h"
#include <string.h>
@@ -156,6 +157,29 @@ _ostree_kernel_args_append_argv (OstreeKernelArgs *kargs,
}
}
+gboolean
+_ostree_kernel_args_append_proc_cmdline (OstreeKernelArgs *kargs,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gs_unref_object GFile *proc_cmdline_path = g_file_new_for_path ("/proc/cmdline");
+ gs_free char *proc_cmdline = NULL;
+ gsize proc_cmdline_len = 0;
+ gs_strfreev char **proc_cmdline_args = NULL;
+
+ if (!g_file_load_contents (proc_cmdline_path, cancellable,
+ &proc_cmdline, &proc_cmdline_len,
+ NULL, error))
+ return FALSE;
+
+ g_strchomp (proc_cmdline);
+
+ proc_cmdline_args = g_strsplit (proc_cmdline, " ", -1);
+ _ostree_kernel_args_append_argv (kargs, proc_cmdline_args);
+
+ return TRUE;
+}
+
void
_ostree_kernel_args_parse_append (OstreeKernelArgs *kargs,
const char *options)
diff --git a/src/libostree/ostree-kernel-args.h b/src/libostree/ostree-kernel-args.h
index 89d4fc9f..30170e99 100644
--- a/src/libostree/ostree-kernel-args.h
+++ b/src/libostree/ostree-kernel-args.h
@@ -40,6 +40,10 @@ void _ostree_kernel_args_append (OstreeKernelArgs *kargs,
void _ostree_kernel_args_append_argv (OstreeKernelArgs *kargs,
char **argv);
+gboolean _ostree_kernel_args_append_proc_cmdline (OstreeKernelArgs *kargs,
+ GCancellable *cancellable,
+ GError **error);
+
void _ostree_kernel_args_parse_append (OstreeKernelArgs *kargs,
const char *options);
diff --git a/src/ostree/ot-admin-builtin-deploy.c b/src/ostree/ot-admin-builtin-deploy.c
index a209c26f..d255f8b8 100644
--- a/src/ostree/ot-admin-builtin-deploy.c
+++ b/src/ostree/ot-admin-builtin-deploy.c
@@ -130,20 +130,8 @@ ot_admin_builtin_deploy (int argc, char **argv, OstreeSysroot *sysroot, GCancell
*/
if (opt_kernel_proc_cmdline)
{
- gs_unref_object GFile *proc_cmdline_path = g_file_new_for_path ("/proc/cmdline");
- gs_free char *proc_cmdline = NULL;
- gsize proc_cmdline_len = 0;
- gs_strfreev char **proc_cmdline_args = NULL;
-
- if (!g_file_load_contents (proc_cmdline_path, cancellable,
- &proc_cmdline, &proc_cmdline_len,
- NULL, error))
+ if (!_ostree_kernel_args_append_proc_cmdline (kargs, cancellable, error))
goto out;
-
- g_strchomp (proc_cmdline);
-
- proc_cmdline_args = g_strsplit (proc_cmdline, " ", -1);
- _ostree_kernel_args_append_argv (kargs, proc_cmdline_args);
}
else if (merge_deployment)
{
diff --git a/src/ostree/ot-admin-instutil-builtin-set-kargs.c b/src/ostree/ot-admin-instutil-builtin-set-kargs.c
index 6264a04e..214e4661 100644
--- a/src/ostree/ot-admin-instutil-builtin-set-kargs.c
+++ b/src/ostree/ot-admin-instutil-builtin-set-kargs.c
@@ -27,7 +27,18 @@
#include "otutil.h"
+#include "../libostree/ostree-kernel-args.h"
+
+static gboolean opt_proc_cmdline;
+static gboolean opt_merge;
+static char **opt_replace;
+static char **opt_append;
+
static GOptionEntry options[] = {
+ { "import-proc-cmdline", 0, 0, G_OPTION_ARG_NONE, &opt_proc_cmdline, "Import current /proc/cmdline", NULL },
+ { "merge", 0, 0, G_OPTION_ARG_NONE, &opt_merge, "Merge with previous command line", NULL },
+ { "replace", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_replace, "Set kernel argument, like root=/dev/sda1; this overrides any earlier argument with the same name", "KEY=VALUE" },
+ { "append", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_append, "Append kernel argument; useful with e.g. console= that can be used multiple times", "KEY=VALUE" },
{ NULL }
};
@@ -39,7 +50,7 @@ ot_admin_instutil_builtin_set_kargs (int argc, char **argv, OstreeSysroot *sysro
gs_unref_ptrarray GPtrArray *deployments = NULL;
OstreeDeployment *first_deployment = NULL;
GOptionContext *context = NULL;
- gs_unref_ptrarray GPtrArray *new_kargs = NULL;
+ __attribute__((cleanup(_ostree_kernel_args_cleanup))) OstreeKernelArgs *kargs = NULL;
context = g_option_context_new ("ARGS - set new kernel command line arguments");
@@ -60,15 +71,45 @@ ot_admin_instutil_builtin_set_kargs (int argc, char **argv, OstreeSysroot *sysro
}
first_deployment = deployments->pdata[0];
- new_kargs = g_ptr_array_new ();
+ kargs = _ostree_kernel_args_new ();
+
+ /* If they want the current kernel's args, they very likely don't
+ * want the ones from the merge.
+ */
+ if (opt_proc_cmdline)
+ {
+ if (!_ostree_kernel_args_append_proc_cmdline (kargs, cancellable, error))
+ goto out;
+ }
+ else if (opt_merge)
+ {
+ OstreeBootconfigParser *bootconfig = ostree_deployment_get_bootconfig (first_deployment);
+ gs_strfreev char **previous_args = g_strsplit (ostree_bootconfig_parser_get (bootconfig, "options"), " ", -1);
+
+ _ostree_kernel_args_append_argv (kargs, previous_args);
+ }
+
+ if (opt_replace)
+ {
+ _ostree_kernel_args_replace_argv (kargs, opt_replace);
+ }
+
+ if (opt_append)
+ {
+ _ostree_kernel_args_append_argv (kargs, opt_append);
+ }
+
for (i = 1; i < argc; i++)
- g_ptr_array_add (new_kargs, argv[i]);
- g_ptr_array_add (new_kargs, NULL);
-
- if (!ostree_sysroot_deployment_set_kargs (sysroot, first_deployment,
- (char**)new_kargs->pdata,
- cancellable, error))
- goto out;
+ _ostree_kernel_args_append (kargs, argv[i]);
+
+ {
+ gs_strfreev char **kargs_strv = _ostree_kernel_args_to_strv (kargs);
+
+ if (!ostree_sysroot_deployment_set_kargs (sysroot, first_deployment,
+ kargs_strv,
+ cancellable, error))
+ goto out;
+ }
ret = TRUE;
out: