init: Add a configurable service directory
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-08-22 15:23:06 +02:00
parent 65834ff491
commit 33c1a9c92b
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -323,7 +323,7 @@ static void mount_shmfs()
if (chmod("/dev/shm", 01777) < 0) exit(255);
}
Result<int> sysinit()
Result<int> sysinit(StringView path)
{
if (getpid() != 1)
{
@ -358,7 +358,8 @@ Result<int> 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<int> sysinit()
}
}
Result<int> user_init()
Result<int> user_init(StringView path)
{
setpgid(0, 0);
@ -405,7 +406,8 @@ Result<int> 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<int> user_init()
Result<int> 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);
}