From 33c1a9c92b8d94977ab48b7cc96b9c0c1962f6d1 Mon Sep 17 00:00:00 2001 From: apio Date: Tue, 22 Aug 2023 15:23:06 +0200 Subject: [PATCH] init: Add a configurable service directory --- apps/init.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/apps/init.cpp b/apps/init.cpp index 579a5eea..9b1f9178 100644 --- a/apps/init.cpp +++ b/apps/init.cpp @@ -323,7 +323,7 @@ static void mount_shmfs() if (chmod("/dev/shm", 01777) < 0) exit(255); } -Result sysinit() +Result sysinit(StringView path) { if (getpid() != 1) { @@ -358,7 +358,8 @@ Result sysinit() TRY(os::Security::pledge("stdio rpath wpath cpath proc exec id", nullptr)); - start_services("/etc/init"); + if (path.is_empty()) path = "/etc/init"; + start_services(path); while (1) { @@ -394,7 +395,7 @@ Result sysinit() } } -Result user_init() +Result user_init(StringView path) { setpgid(0, 0); @@ -405,7 +406,8 @@ Result user_init() TRY(os::Security::pledge("stdio rpath wpath cpath proc exec", nullptr)); - start_services("/etc/user"); + if (path.is_empty()) path = "/etc/user"; + start_services(path); TRY(os::Security::pledge("stdio rpath wpath proc exec", nullptr)); @@ -446,13 +448,16 @@ Result user_init() Result luna_main(int argc, char** argv) { bool user; + StringView service_path; os::ArgumentParser parser; parser.add_description("The init system for Luna."); parser.add_system_program_info("init"_sv); parser.add_switch_argument(user, 'u', "user"_sv, "initialize a user session instead of the system"); + parser.add_value_argument(service_path, 's', "service-path"_sv, + "change the default service path (/etc/init or /etc/user)"); parser.parse(argc, argv); - if (user) return user_init(); - return sysinit(); + if (user) return user_init(service_path); + return sysinit(service_path); }