mirror of
https://github.com/ostreedev/ostree.git
synced 2025-08-25 13:49:24 +03:00
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
This commit is contained in:
@ -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>
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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:
|
||||
|
Reference in New Issue
Block a user