SystemServer: Add WorkingDirectory support

Services can now have their initial working directory
configured via `SystemServer.ini`.

This commit also configures Terminal's working directory
to be /home/anon
This commit is contained in:
Itamar 2020-03-16 22:21:02 +02:00 committed by Andreas Kling
parent 39c21f368a
commit bd9f14e27e
Notes: sideshowbarker 2024-07-19 08:16:05 +09:00
4 changed files with 15 additions and 0 deletions

View File

@ -70,3 +70,4 @@ User=anon
[Terminal]
User=anon
WorkingDirectory=/home/anon

View File

@ -25,6 +25,7 @@ describing how to launch and manage this service.
* `Socket` - a path to a socket to create on behalf of the service. For lazy services, SystemServer will actually watch the socket for new connection attempts. An open file descriptor to this socket will be passed as fd 3 to the service.
* `SocketPermissions` - (octal) file system permissions for the socket file. The default permissions are 0600.
* `User` - a name of the user to run the service as. This impacts what UID, GID (and extra GIDs) the service processes have. By default, services are run as root.
* `WorkingDirectory` - The working directory in which the service is spawned. By Default, services are spawned in the root (`"/"`) directory.
## Environment

View File

@ -188,6 +188,13 @@ void Service::spawn()
} else if (m_pid == 0) {
// We are the child.
if (!m_working_directory.is_null()) {
if (chdir(m_working_directory.characters()) < 0) {
perror("chdir");
ASSERT_NOT_REACHED();
}
}
struct sched_param p;
p.sched_priority = m_priority;
int rc = sched_setparam(0, &p);
@ -320,6 +327,8 @@ Service::Service(const Core::ConfigFile& config, const StringView& name)
m_socket_permissions = strtol(socket_permissions_string.characters(), nullptr, 8) & 04777;
setup_socket();
}
m_working_directory = config.read_entry(name, "WorkingDirectory");
}
void Service::save_to(JsonObject& json)
@ -352,4 +361,5 @@ void Service::save_to(JsonObject& json)
json.set("pid", nullptr);
json.set("restart_attempts", m_restart_attempts);
json.set("working_directory", m_working_directory);
}

View File

@ -81,6 +81,9 @@ private:
// times where it has exited unsuccessfully and too quickly.
int m_restart_attempts { 0 };
// The working directory in which to spawn the service
String m_working_directory;
void resolve_user();
void setup_socket();
void setup_notifier();