[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[hurd] 17/28: boot: Add a default boot script.
From: |
Samuel Thibault |
Subject: |
[hurd] 17/28: boot: Add a default boot script. |
Date: |
Wed, 16 Nov 2016 08:30:27 +0000 |
This is an automated email from the git hooks/post-receive script.
sthibault pushed a commit to branch upstream
in repository hurd.
commit db94feece63e18364dd2c9228a6ef3452fe22cc2
Author: Justus Winter <address@hidden>
Date: Thu Oct 27 11:50:46 2016 +0200
boot: Add a default boot script.
* boot/boot.c (OPT_BOOT_SCRIPT): New macro.
(options): Add flag '--boot-script'.
(args_doc): Do not expect the script as positional argument.
(parse_opt): Handle new flag, do not expect the script as positional
argument.
(read_boot_script): New function.
(default_boot_script): New variable containing a boot script capable
of booting contemporary Hurd systems.
(main): Use the new function to read the boot script, or fall back to
using the builtin one.
---
boot/boot.c | 138 +++++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 90 insertions(+), 48 deletions(-)
diff --git a/boot/boot.c b/boot/boot.c
index 1cc94bc..244988a 100644
--- a/boot/boot.c
+++ b/boot/boot.c
@@ -217,9 +217,12 @@ void * msg_thread (void *);
const char *argp_program_version = STANDARD_HURD_VERSION (boot);
#define OPT_PRIVILEGED -1
+#define OPT_BOOT_SCRIPT -2
static struct argp_option options[] =
{
+ { "boot-script", OPT_BOOT_SCRIPT, "BOOT-SCRIPT", 0,
+ "boot script to execute" },
{ "boot-root", 'D', "DIR", 0,
"Root of a directory tree in which to find files specified in BOOT-SCRIPT"
},
{ "single-user", 's', 0, 0,
@@ -236,7 +239,7 @@ static struct argp_option options[] =
"Allow the subhurd to access privileged kernel ports"},
{ 0 }
};
-static char args_doc[] = "BOOT-SCRIPT";
+static char args_doc[] = "";
static char doc[] = "Boot a second hurd";
struct dev_map
@@ -309,13 +312,13 @@ parse_opt (int key, char *arg, struct argp_state *state)
want_privileged = 1;
break;
- case ARGP_KEY_ARG:
- if (state->arg_num == 0)
- bootscript = arg;
- else
- return ARGP_ERR_UNKNOWN;
+ case OPT_BOOT_SCRIPT:
+ bootscript = arg;
break;
+ case ARGP_KEY_ARG:
+ return ARGP_ERR_UNKNOWN;
+
case ARGP_KEY_INIT:
state->child_inputs[0] = state->input; break;
@@ -373,6 +376,82 @@ allocate_pseudo_ports (void)
return 0;
}
+void
+read_boot_script (char **buffer, size_t *length)
+{
+ char *p, *buf;
+ static const char filemsg[] = "Can't open boot script\n";
+ static const char memmsg[] = "Not enough memory\n";
+ int i, fd;
+ size_t amt, len;
+
+ fd = open (bootscript, O_RDONLY, 0);
+ if (fd < 0)
+ {
+ write (2, filemsg, sizeof (filemsg));
+ host_exit (1);
+ }
+ p = buf = malloc (500);
+ if (!buf)
+ {
+ write (2, memmsg, sizeof (memmsg));
+ host_exit (1);
+ }
+ len = 500;
+ amt = 0;
+ while (1)
+ {
+ i = read (fd, p, len - (p - buf));
+ if (i <= 0)
+ break;
+ p += i;
+ amt += i;
+ if (p == buf + len)
+ {
+ char *newbuf;
+
+ len += 500;
+ newbuf = realloc (buf, len);
+ if (!newbuf)
+ {
+ write (2, memmsg, sizeof (memmsg));
+ host_exit (1);
+ }
+ p = newbuf + (p - buf);
+ buf = newbuf;
+ }
+ }
+
+ close (fd);
+ *buffer = buf;
+ *length = amt;
+}
+
+
+/* Boot script file for booting contemporary GNU Hurd systems. Each
+ line specifies a file to be loaded by the boot loader (the first
+ word), and actions to be done with it. */
+const char *default_boot_script =
+ /* First, the bootstrap filesystem. It needs several ports as
+ arguments, as well as the user flags from the boot loader. */
+ "/hurd/ext2fs.static"
+ " --readonly"
+ " --multiboot-command-line=${kernel-command-line}"
+ " --host-priv-port=${host-port}"
+ " --device-master-port=${device-port}"
+ " --exec-server-task=${exec-task}"
+ " -T device ${root-device} $(task-create) $(task-resume)"
+ "\n"
+
+ /* Now the exec server; to load the dynamically-linked exec server
+ program, we have the boot loader in fact load and run ld.so,
+ which in turn loads and runs /hurd/exec. This task is created,
+ and its task port saved in ${exec-task} to be passed to the fs
+ above, but it is left suspended; the fs will resume the exec task
+ once it is ready. */
+ "/lib/ld.so /hurd/exec $(exec-task=task-create)"
+ "\n";
+
int
main (int argc, char **argv, char **envp)
@@ -380,7 +459,6 @@ main (int argc, char **argv, char **envp)
error_t err;
mach_port_t foo;
char *buf = 0;
- int i, len;
pthread_t pthread_id;
char *root_store_name;
const struct argp_child kids[] = { { &store_argp }, { 0 }};
@@ -532,46 +610,12 @@ main (int argc, char **argv, char **envp)
/* Parse the boot script. */
{
char *p, *line;
- static const char filemsg[] = "Can't open boot script\n";
- static const char memmsg[] = "Not enough memory\n";
- int amt, fd, err;
+ size_t amt;
+ if (bootscript)
+ read_boot_script (&buf, &amt);
+ else
+ buf = strdup (default_boot_script), amt = strlen (default_boot_script);
- fd = open (bootscript, O_RDONLY, 0);
- if (fd < 0)
- {
- write (2, filemsg, sizeof (filemsg));
- host_exit (1);
- }
- p = buf = malloc (500);
- if (!buf)
- {
- write (2, memmsg, sizeof (memmsg));
- host_exit (1);
- }
- len = 500;
- amt = 0;
- while (1)
- {
- i = read (fd, p, len - (p - buf));
- if (i <= 0)
- break;
- p += i;
- amt += i;
- if (p == buf + len)
- {
- char *newbuf;
-
- len += 500;
- newbuf = realloc (buf, len);
- if (!newbuf)
- {
- write (2, memmsg, sizeof (memmsg));
- host_exit (1);
- }
- p = newbuf + (p - buf);
- buf = newbuf;
- }
- }
line = p = buf;
while (1)
{
@@ -611,8 +655,6 @@ main (int argc, char **argv, char **envp)
/* The boot script has now been parsed into internal data structures.
Now execute its directives. */
{
- int err;
-
err = boot_script_exec ();
if (err)
{
--
Alioth's /usr/local/bin/git-commit-notice on
/srv/git.debian.org/git/pkg-hurd/hurd.git
- [hurd] 03/28: Fix typo, (continued)
- [hurd] 03/28: Fix typo, Samuel Thibault, 2016/11/16
- [hurd] 12/28: boot: Use the smallest possible name when inserting rights., Samuel Thibault, 2016/11/16
- [hurd] 15/28: boot: restore terminal state on exit, Samuel Thibault, 2016/11/16
- [hurd] 18/28: boot: Tidy up the argument parser., Samuel Thibault, 2016/11/16
- [hurd] 24/28: eth-multiplexer: Avoid local definitions., Samuel Thibault, 2016/11/16
- [hurd] 28/28: libpager: fix returning error on data_unlock, Samuel Thibault, 2016/11/16
- [hurd] 08/28: proc: Fix new task notifications., Samuel Thibault, 2016/11/16
- [hurd] 19/28: Adjust to the fixed new task notifications., Samuel Thibault, 2016/11/16
- [hurd] 22/28: eth-multiplexer: Fix packet delivery., Samuel Thibault, 2016/11/16
- [hurd] 16/28: boot: Allow unprivileged users to boot Subhurds., Samuel Thibault, 2016/11/16
- [hurd] 17/28: boot: Add a default boot script.,
Samuel Thibault <=
- [hurd] 10/28: Add missing spinlock initializers, Samuel Thibault, 2016/11/16
- [hurd] 23/28: eth-multiplexer: Fix retrieving status of virtual interfaces., Samuel Thibault, 2016/11/16
- [hurd] 26/28: boot: Improve device pass-through., Samuel Thibault, 2016/11/16
- [hurd] 25/28: eth-multiplexer: Generate stable ethernet addresses., Samuel Thibault, 2016/11/16
- [hurd] 05/28: Mark library stubs as weak, Samuel Thibault, 2016/11/16
- [hurd] 13/28: boot: Quote arguments containing spaces., Samuel Thibault, 2016/11/16
- [hurd] 09/28: boot: Remove hacks for running boot on UX., Samuel Thibault, 2016/11/16
- [hurd] 27/28: mach-defpager: Fix daemonization., Samuel Thibault, 2016/11/16
- [hurd] 07/28: libdiskfs: Factorize code for last hard reference being released, Samuel Thibault, 2016/11/16
- [hurd] 14/28: boot: Move bootscript callbacks., Samuel Thibault, 2016/11/16