Use syslog for logging and to wait for process initialization

This commit is contained in:
pjht 2024-06-23 14:53:46 -05:00
parent 1a218a9978
commit b372f96ce6
Signed by: pjht
GPG Key ID: 7B5F6AFBEC7EE78E
3 changed files with 56 additions and 11 deletions

28
Cargo.lock generated
View File

@ -96,6 +96,8 @@ name = "init"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"hexdump", "hexdump",
"syslog_msg_ipc",
"syslog_rpc",
"tar-no-std", "tar-no-std",
"vfs_rpc", "vfs_rpc",
] ]
@ -272,6 +274,32 @@ dependencies = [
"unicode-ident", "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]] [[package]]
name = "tar-no-std" name = "tar-no-std"
version = "0.3.1" version = "0.3.1"

View File

@ -7,6 +7,8 @@ edition = "2021"
[dependencies] [dependencies]
hexdump = "0.1.2" 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" tar-no-std = "0.3.1"
vfs_rpc = { version = "0.1.0", path = "../vfs/vfs_rpc" } vfs_rpc = { version = "0.1.0", path = "../vfs/vfs_rpc" }

View File

@ -8,28 +8,43 @@ use std::process::Command;
use tar_no_std::TarArchiveRef; use tar_no_std::TarArchiveRef;
fn main() { fn main() {
syslog_msg_ipc::register_callback();
let initrd = TarArchiveRef::new(get_initrd()).unwrap(); 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"); 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"); run_initrd_proc(&initrd, "bin/devfs");
println!("[INIT] Started the devfs"); syslog_client.send_text_message("init", "Started the devfs").unwrap();
run_initrd_proc(&initrd, "bin/tarfs"); syslog_msg_ipc::get_syslog_msg();
println!("[INIT] Started the tar FS driver");
run_initrd_proc(&initrd, "bin/initrd_driver");
println!("[INIT] Started the initrd pseudodevice driver");
let vfs_client = vfs_rpc::Client::new(vfs_pid); 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 { 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; 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 { loop {
if vfs_client.mount(Path::new("/dev/initrd"), "tarfs", Path::new("/")).is_ok() { 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; 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(); Command::new("/bin/load_test").spawn().unwrap();
} }