From d9b7e8edc0335eff6709b3d7de3d7dcc27830778 Mon Sep 17 00:00:00 2001 From: apio Date: Tue, 2 May 2023 20:55:41 +0200 Subject: [PATCH] init: Read and launch service files in order using sort() --- apps/init.cpp | 2 ++ initrd/etc/init/00-motd | 3 +++ initrd/etc/motd | 3 ++- libluna/include/luna/String.h | 2 ++ libluna/src/String.cpp | 5 +++++ 5 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 initrd/etc/init/00-motd diff --git a/apps/init.cpp b/apps/init.cpp index 521f92e3..716fa3ed 100644 --- a/apps/init.cpp +++ b/apps/init.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -239,6 +240,7 @@ static Result load_services() auto dir = TRY(os::Directory::open("/etc/init")); auto services = TRY(dir->list(os::Directory::Filter::ParentAndBase)); + sort(services.begin(), services.end(), String::compare); for (const auto& entry : services) { diff --git a/initrd/etc/init/00-motd b/initrd/etc/init/00-motd new file mode 100644 index 00000000..4b231bf4 --- /dev/null +++ b/initrd/etc/init/00-motd @@ -0,0 +1,3 @@ +Name=motd +Command=/bin/cat /etc/motd +Wait=true diff --git a/initrd/etc/motd b/initrd/etc/motd index af5626b4..6cbafbf4 100644 --- a/initrd/etc/motd +++ b/initrd/etc/motd @@ -1 +1,2 @@ -Hello, world! +Welcome to the Luna system! +Have a look around, you can run 'ls /bin' to list available commands. diff --git a/libluna/include/luna/String.h b/libluna/include/luna/String.h index bb0a2ba4..b9832d2a 100644 --- a/libluna/include/luna/String.h +++ b/libluna/include/luna/String.h @@ -65,6 +65,8 @@ class String static Result from_cstring(const char* str); static Result from_string_view(StringView str); + static int compare(const String* a, const String* b); + const char* chars() const { return m_inline ? m_inline_storage : m_string; diff --git a/libluna/src/String.cpp b/libluna/src/String.cpp index 602e0ea9..81a4c48e 100644 --- a/libluna/src/String.cpp +++ b/libluna/src/String.cpp @@ -180,3 +180,8 @@ Result String::join(const Vector& vec, StringView delim) return sb.string(); } + +int String::compare(const String* a, const String* b) +{ + return strcmp(a->chars(), b->chars()); +}