From 0540879959c5a5517f72b88a8b76bba5ae1847a8 Mon Sep 17 00:00:00 2001 From: apio Date: Sat, 3 Jun 2023 11:34:53 +0200 Subject: [PATCH] init+initrd: Create /tmp and mount it on boot --- apps/init.cpp | 20 +++++++++++++++++++- initrd/etc/init/00-tmpfs | 3 +++ initrd/etc/init/{00-motd => 01-motd} | 0 initrd/sbin/mount-tmpfs | 3 +++ 4 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 initrd/etc/init/00-tmpfs rename initrd/etc/init/{00-motd => 01-motd} (100%) create mode 100644 initrd/sbin/mount-tmpfs diff --git a/apps/init.cpp b/apps/init.cpp index 786c5305..640f0332 100644 --- a/apps/init.cpp +++ b/apps/init.cpp @@ -149,10 +149,28 @@ static Result load_service(const os::Path& path) if (parts[0].view() == "Command") { + if (!service.command.is_empty()) + { + fprintf(g_init_log, "[init] 'Command' cannot be specified after 'Script' has already been set! (%s)\n", + line.chars()); + return {}; + } service.command = move(parts[1]); continue; } + if (parts[0].view() == "Script") + { + if (!service.command.is_empty()) + { + fprintf(g_init_log, "[init] 'Script' cannot be specified after 'Command' has already been set! (%s)\n", + line.chars()); + return {}; + } + service.command = TRY(String::format("/bin/sh -- %s"_sv, parts[1].chars())); + continue; + } + if (parts[0].view() == "Restart") { if (parts[1].view() == "true" || parts[1].view().to_uint().value_or(0) == 1) @@ -210,7 +228,7 @@ static Result load_service(const os::Path& path) if (service.command.is_empty()) { - fprintf(g_init_log, "[init] service file is missing 'Command' entry, aborting!\n"); + fprintf(g_init_log, "[init] service file is missing 'Command' or 'Script' entry, aborting!\n"); return {}; } diff --git a/initrd/etc/init/00-tmpfs b/initrd/etc/init/00-tmpfs new file mode 100644 index 00000000..551f141e --- /dev/null +++ b/initrd/etc/init/00-tmpfs @@ -0,0 +1,3 @@ +Name=tmpfs +Script=/sbin/mount-tmpfs +Wait=true diff --git a/initrd/etc/init/00-motd b/initrd/etc/init/01-motd similarity index 100% rename from initrd/etc/init/00-motd rename to initrd/etc/init/01-motd diff --git a/initrd/sbin/mount-tmpfs b/initrd/sbin/mount-tmpfs new file mode 100644 index 00000000..46a3740c --- /dev/null +++ b/initrd/sbin/mount-tmpfs @@ -0,0 +1,3 @@ +mkdir -p /tmp +mount -t tmpfs /tmp +chmod 1777 /tmp