git: 7f3c3606465f - main - Parse /kboot.conf

From: Warner Losh <imp_at_FreeBSD.org>
Date: Tue, 14 Mar 2023 02:46:51 UTC
The branch main has been updated by imp:

URL: https://cgit.FreeBSD.org/src/commit/?id=7f3c3606465f36040bacd85e1f9443ae6b5ca39a

commit 7f3c3606465f36040bacd85e1f9443ae6b5ca39a
Author:     Warner Losh <imp@FreeBSD.org>
AuthorDate: 2023-03-14 02:33:35 +0000
Commit:     Warner Losh <imp@FreeBSD.org>
CommitDate: 2023-03-14 02:45:50 +0000

    Parse /kboot.conf
    
    If there's a kboot.conf, prase it after the command line args are
    parsed. It's not always easy to get all the right command line args
    depending on the environment. Allow an escape hatch. While we can't do
    everything one might like in this file, we can do enough.
    
    Sponsored by:           Netflix
---
 stand/kboot/main.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/stand/kboot/main.c b/stand/kboot/main.c
index 849ad46add6c..3895f7e76773 100644
--- a/stand/kboot/main.c
+++ b/stand/kboot/main.c
@@ -195,6 +195,31 @@ has_acpi(void)
 	return rsdp != 0;
 }
 
+static void
+parse_file(const char *fn)
+{
+	struct stat st;
+	int fd = -1;
+	char *env = NULL;
+
+	if (stat(fn, &st) != 0)
+		return;
+	fd = open(fn, O_RDONLY);
+	if (fd == -1)
+		return;
+	env = malloc(st.st_size + 1);
+	if (env == NULL)
+		goto out;
+	if (read(fd, env, st.st_size) != st.st_size)
+		goto out;
+	env[st.st_size] = '\0';
+	boot_parse_cmdline(env);
+out:
+	free(env);
+	close(fd);
+}
+
+
 int
 main(int argc, const char **argv)
 {
@@ -221,6 +246,8 @@ main(int argc, const char **argv)
 	/* Parse the command line args -- ignoring for now the console selection */
 	parse_args(argc, argv);
 
+	parse_file("host:/kboot.conf");
+
 	/*
 	 * Set up console.
 	 */