init: Read and launch service files in order using sort()
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-05-02 20:55:41 +02:00
parent 3628464284
commit d9b7e8edc0
Signed by: apio
GPG Key ID: B8A7D06E42258954
5 changed files with 14 additions and 1 deletions

View File

@ -1,6 +1,7 @@
#include <errno.h>
#include <fcntl.h>
#include <luna/PathParser.h>
#include <luna/Sort.h>
#include <luna/String.h>
#include <luna/Vector.h>
#include <os/Directory.h>
@ -239,6 +240,7 @@ static Result<void> 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)
{

3
initrd/etc/init/00-motd Normal file
View File

@ -0,0 +1,3 @@
Name=motd
Command=/bin/cat /etc/motd
Wait=true

View File

@ -1 +1,2 @@
Hello, world!
Welcome to the Luna system!
Have a look around, you can run 'ls /bin' to list available commands.

View File

@ -65,6 +65,8 @@ class String
static Result<String> from_cstring(const char* str);
static Result<String> 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;

View File

@ -180,3 +180,8 @@ Result<String> String::join(const Vector<String>& vec, StringView delim)
return sb.string();
}
int String::compare(const String* a, const String* b)
{
return strcmp(a->chars(), b->chars());
}