forked from pool/grub2
67 lines
1.7 KiB
Diff
67 lines
1.7 KiB
Diff
|
From: Michael Chang <mchang@suse.com>
|
||
|
Subject: add loader_cmdline_append environment variable
|
||
|
|
||
|
Add loader_cmdline_append environment variable that appends it's
|
||
|
value to the loader's command line. We can use this variable to
|
||
|
assign values determined at run time. It will take effect on any
|
||
|
subsidiary configs loaded using configfile as well.
|
||
|
|
||
|
By means of this variable, we can, for example, set rootflags=
|
||
|
according to the selected btrfs snapshots and tell linux kernel's
|
||
|
btrfs module to mount the snapshot by the subvolume name or id.
|
||
|
|
||
|
Signed-off-by: Michael Chang <mchang@suse.com>
|
||
|
---
|
||
|
grub-core/lib/cmdline.c | 21 +++++++++++++++++++++
|
||
|
1 file changed, 21 insertions(+)
|
||
|
|
||
|
diff --git a/grub-core/lib/cmdline.c b/grub-core/lib/cmdline.c
|
||
|
index a702e64..c5be945 100644
|
||
|
--- a/grub-core/lib/cmdline.c
|
||
|
+++ b/grub-core/lib/cmdline.c
|
||
|
@@ -19,6 +19,8 @@
|
||
|
|
||
|
#include <grub/lib/cmdline.h>
|
||
|
#include <grub/misc.h>
|
||
|
+#include <grub/mm.h>
|
||
|
+#include <grub/env.h>
|
||
|
|
||
|
static unsigned int check_arg (char *c, int *has_space)
|
||
|
{
|
||
|
@@ -65,6 +67,8 @@ int grub_create_loader_cmdline (int argc, char *argv[], char *buf,
|
||
|
int i, space;
|
||
|
unsigned int arg_size;
|
||
|
char *c;
|
||
|
+ const char *append = NULL;
|
||
|
+ grub_size_t append_size = 0;
|
||
|
|
||
|
for (i = 0; i < argc; i++)
|
||
|
{
|
||
|
@@ -95,6 +99,23 @@ int grub_create_loader_cmdline (int argc, char *argv[], char *buf,
|
||
|
*buf++ = ' ';
|
||
|
}
|
||
|
|
||
|
+ append = grub_env_get ("loader_cmdline_append");
|
||
|
+
|
||
|
+ if (append)
|
||
|
+ append_size = grub_strlen (append);
|
||
|
+
|
||
|
+ if (append_size)
|
||
|
+ {
|
||
|
+ append_size++;
|
||
|
+ if (size >= append_size)
|
||
|
+ {
|
||
|
+ grub_strcpy (buf, append);
|
||
|
+ buf += append_size;
|
||
|
+ size -= append_size;
|
||
|
+ i++;
|
||
|
+ }
|
||
|
+ }
|
||
|
+
|
||
|
/* Replace last space with null. */
|
||
|
if (i)
|
||
|
buf--;
|
||
|
--
|
||
|
1.8.1.4
|
||
|
|