[Yellowstone] Use the file api to load the init file.

This commit is contained in:
Drew Galbraith 2023-11-22 16:58:13 -08:00
parent 86ce0a68a3
commit 8ceab2ad23
6 changed files with 23 additions and 27 deletions

View file

@ -1,5 +1,6 @@
#include <glacier/string/str_format.h>
#include <glacier/string/str_split.h>
#include <mammoth/file/file.h>
#include <mammoth/proc/process.h>
#include <mammoth/util/debug.h>
#include <mammoth/util/init.h>
@ -36,29 +37,19 @@ uint64_t main(uint64_t port_cap) {
dbgln("VFS Available.");
auto vfs_client = server->GetVFSClient();
OpenFileRequest request;
request.set_path("/init.txt");
OpenFileResponse response;
check(vfs_client->OpenFile(request, response));
mmth::File init_file = mmth::File::Open("/init.txt");
mmth::OwnedMemoryRegion filemem =
mmth::OwnedMemoryRegion::FromCapability(response.memory());
glcr::String file(reinterpret_cast<const char*>(filemem.vaddr()),
response.size());
glcr::Vector<glcr::StringView> files = glcr::StrSplit(file, '\n');
glcr::Vector<glcr::StringView> files =
glcr::StrSplit(init_file.as_str(), '\n');
for (uint64_t i = 0; i < files.size(); i++) {
if (!files[i].empty()) {
dbgln("Starting {}", files[i]);
OpenFileRequest req;
req.set_path(glcr::StrFormat("/bin/{}", files[i]));
OpenFileResponse resp;
check(vfs_client->OpenFile(req, resp));
mmth::File binary =
mmth::File::Open(glcr::StrFormat("/bin/{}", files[i]));
ASSIGN_OR_RETURN(YellowstoneClient client3, server->CreateClient());
check(SpawnProcess(resp.memory(), client3.Capability()));
check(mmth::SpawnProcessFromElfRegion((uint64_t)binary.raw_ptr(),
client3.Capability()));
}
}

View file

@ -2,6 +2,7 @@
#include <denali/denali.yunq.client.h>
#include <glacier/string/string.h>
#include <mammoth/file/file.h>
#include <mammoth/util/debug.h>
#include <mammoth/util/init.h>
#include <mammoth/util/memory_region.h>
@ -100,7 +101,7 @@ glcr::ErrorCode YellowstoneServer::HandleRegisterEndpoint(
} else if (req.endpoint_name() == "victoriafalls") {
// FIXME: Probably make a separate copy for use within yellowstone vs
// transmit to other processes.
vfs_client_ = glcr::MakeShared<VFSClient>(req.endpoint_capability());
mmth::SetVfsCap(req.endpoint_capability());
has_victoriafalls_semaphore_.Signal();
} else {
dbgln("[WARN] Got endpoint cap type: {}", req.endpoint_name().cstr());
@ -125,7 +126,3 @@ void YellowstoneServer::WaitDenaliRegistered() { has_denali_semaphore_.Wait(); }
void YellowstoneServer::WaitVictoriaFallsRegistered() {
has_victoriafalls_semaphore_.Wait();
}
glcr::SharedPtr<VFSClient> YellowstoneServer::GetVFSClient() {
return vfs_client_;
}

View file

@ -26,8 +26,6 @@ class YellowstoneServer : public YellowstoneServerBase {
void WaitDenaliRegistered();
void WaitVictoriaFallsRegistered();
glcr::SharedPtr<VFSClient> GetVFSClient();
private:
glcr::HashMap<glcr::String, z_cap_t> endpoint_map_;