mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 08:27:45 +00:00
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:
parent
39c21f368a
commit
bd9f14e27e
4 changed files with 15 additions and 0 deletions
|
@ -70,3 +70,4 @@ User=anon
|
||||||
|
|
||||||
[Terminal]
|
[Terminal]
|
||||||
User=anon
|
User=anon
|
||||||
|
WorkingDirectory=/home/anon
|
||||||
|
|
|
@ -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.
|
* `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.
|
* `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.
|
* `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
|
## Environment
|
||||||
|
|
||||||
|
|
|
@ -188,6 +188,13 @@ void Service::spawn()
|
||||||
} else if (m_pid == 0) {
|
} else if (m_pid == 0) {
|
||||||
// We are the child.
|
// 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;
|
struct sched_param p;
|
||||||
p.sched_priority = m_priority;
|
p.sched_priority = m_priority;
|
||||||
int rc = sched_setparam(0, &p);
|
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;
|
m_socket_permissions = strtol(socket_permissions_string.characters(), nullptr, 8) & 04777;
|
||||||
setup_socket();
|
setup_socket();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_working_directory = config.read_entry(name, "WorkingDirectory");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Service::save_to(JsonObject& json)
|
void Service::save_to(JsonObject& json)
|
||||||
|
@ -352,4 +361,5 @@ void Service::save_to(JsonObject& json)
|
||||||
json.set("pid", nullptr);
|
json.set("pid", nullptr);
|
||||||
|
|
||||||
json.set("restart_attempts", m_restart_attempts);
|
json.set("restart_attempts", m_restart_attempts);
|
||||||
|
json.set("working_directory", m_working_directory);
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,9 @@ private:
|
||||||
// times where it has exited unsuccessfully and too quickly.
|
// times where it has exited unsuccessfully and too quickly.
|
||||||
int m_restart_attempts { 0 };
|
int m_restart_attempts { 0 };
|
||||||
|
|
||||||
|
// The working directory in which to spawn the service
|
||||||
|
String m_working_directory;
|
||||||
|
|
||||||
void resolve_user();
|
void resolve_user();
|
||||||
void setup_socket();
|
void setup_socket();
|
||||||
void setup_notifier();
|
void setup_notifier();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue