From b372f96ce6ef444fcd3401299da42de29000bdd4 Mon Sep 17 00:00:00 2001 From: pjht Date: Sun, 23 Jun 2024 14:53:46 -0500 Subject: [PATCH] Use syslog for logging and to wait for process initialization --- Cargo.lock | 28 ++++++++++++++++++++++++++++ Cargo.toml | 2 ++ src/main.rs | 37 ++++++++++++++++++++++++++----------- 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 11a40a9..7cf8d45 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -96,6 +96,8 @@ name = "init" version = "0.1.0" dependencies = [ "hexdump", + "syslog_msg_ipc", + "syslog_rpc", "tar-no-std", "vfs_rpc", ] @@ -272,6 +274,32 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "syslog_msg_ipc" +version = "0.1.0" +dependencies = [ + "parking_lot", + "postcard", + "syslog_structs", +] + +[[package]] +name = "syslog_rpc" +version = "0.1.0" +dependencies = [ + "parking_lot", + "postcard", + "serde", + "syslog_structs", +] + +[[package]] +name = "syslog_structs" +version = "0.1.0" +dependencies = [ + "serde", +] + [[package]] name = "tar-no-std" version = "0.3.1" diff --git a/Cargo.toml b/Cargo.toml index b41931b..3f5a549 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,8 @@ edition = "2021" [dependencies] hexdump = "0.1.2" +syslog_msg_ipc = { version = "0.1.0", path = "../syslog/syslog_msg_ipc" } +syslog_rpc = { version = "0.1.0", path = "../syslog/syslog_rpc" } tar-no-std = "0.3.1" vfs_rpc = { version = "0.1.0", path = "../vfs/vfs_rpc" } diff --git a/src/main.rs b/src/main.rs index 5edbf3c..f31338c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,28 +8,43 @@ use std::process::Command; use tar_no_std::TarArchiveRef; fn main() { + syslog_msg_ipc::register_callback(); let initrd = TarArchiveRef::new(get_initrd()).unwrap(); + let syslog_pid = run_initrd_proc(&initrd, "bin/syslog"); + let syslog_client = syslog_rpc::Client::new(syslog_pid); + syslog_client.subscribe_to_binary("devfs".to_string(), vec![0, 1]); + syslog_client.subscribe_to_binary("tarfs".to_string(), vec![0]); + syslog_client.send_text_message("init", "Started syslog").unwrap(); let vfs_pid = run_initrd_proc(&initrd, "bin/vfs"); - println!("[INIT] Started the VFS"); + syslog_client.send_text_message("init", "Started the VFS").unwrap(); run_initrd_proc(&initrd, "bin/devfs"); - println!("[INIT] Started the devfs"); - run_initrd_proc(&initrd, "bin/tarfs"); - println!("[INIT] Started the tar FS driver"); - run_initrd_proc(&initrd, "bin/initrd_driver"); - println!("[INIT] Started the initrd pseudodevice driver"); + syslog_client.send_text_message("init", "Started the devfs").unwrap(); + syslog_msg_ipc::get_syslog_msg(); let vfs_client = vfs_rpc::Client::new(vfs_pid); + vfs_client.mount(Path::new("/dummy"), "devfs", Path::new("/dev")).unwrap(); + syslog_client.send_text_message("init", "Mounted /dev").unwrap(); + run_initrd_proc(&initrd, "bin/tarfs"); + syslog_client.send_text_message("init", "Started the tar archive FS").unwrap(); loop { - if vfs_client.mount(Path::new("/dummy"), "devfs", Path::new("/dev")).is_ok() { + let msg = syslog_msg_ipc::get_syslog_msg(); + if msg.from == "tarfs" { break; } } - println!("[INIT] Mounted /dev"); + run_initrd_proc(&initrd, "bin/initrd_driver"); + syslog_client.send_text_message("init", "Started the initrd pseudodevice driver").unwrap(); loop { - if vfs_client.mount(Path::new("/dev/initrd"), "tarfs", Path::new("/")).is_ok() { - break; + let msg = syslog_msg_ipc::get_syslog_msg(); + if msg.from == "devfs" { + if let Some(binary) = msg.binary { + if binary.kind == 1 && std::str::from_utf8(binary.data.as_slice()).unwrap() == "initrd" { + break; + } + } } } - println!("[INIT] Mounted initrd as root"); + vfs_client.mount(Path::new("/dev/initrd"), "tarfs", Path::new("/")).unwrap(); + syslog_client.send_text_message("init", "Mounted the initrd as the root FS").unwrap(); Command::new("/bin/load_test").spawn().unwrap(); }