init: Add support for WorkingDirectory keys
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
apio 2023-09-25 19:26:05 +02:00
parent 7ff5096083
commit 5626083aad
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 11 additions and 0 deletions

View File

@ -34,6 +34,7 @@ struct Service
String standard_output; String standard_output;
String standard_error; String standard_error;
String standard_input; String standard_input;
String working_directory;
Option<uid_t> user {}; Option<uid_t> user {};
Option<gid_t> group {}; Option<gid_t> group {};
bool wait { false }; bool wait { false };
@ -85,6 +86,8 @@ static Result<void> service_child(const Service& service, SharedPtr<os::File> ou
if (error) dup2(error->fd(), STDERR_FILENO); if (error) dup2(error->fd(), STDERR_FILENO);
if (input) dup2(input->fd(), STDIN_FILENO); if (input) dup2(input->fd(), STDIN_FILENO);
if (!service.working_directory.is_empty()) chdir(service.working_directory.chars());
if (service.user.has_value()) if (service.user.has_value())
{ {
setgid(service.group.value()); setgid(service.group.value());
@ -240,6 +243,12 @@ static Result<void> load_service(const os::Path& path)
continue; continue;
} }
if (parts[0].view() == "WorkingDirectory")
{
service.working_directory = move(parts[1]);
continue;
}
if (g_is_system && parts[0].view() == "User") if (g_is_system && parts[0].view() == "User")
{ {
auto* pw = getpwnam(parts[1].chars()); auto* pw = getpwnam(parts[1].chars());

View File

@ -1,4 +1,5 @@
Name=taskbar Name=taskbar
Description=Start the taskbar. Description=Start the taskbar.
Command=/usr/bin/taskbar Command=/usr/bin/taskbar
WorkingDirectory=/home/selene
Restart=true Restart=true

View File

@ -1,3 +1,4 @@
Name=terminal Name=terminal
Description=Start the terminal. Description=Start the terminal.
WorkingDirectory=/home/selene
Command=/usr/bin/terminal Command=/usr/bin/terminal