Use syslog for logging and to wait for process initialization
This commit is contained in:
parent
1a218a9978
commit
b372f96ce6
28
Cargo.lock
generated
28
Cargo.lock
generated
@ -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"
|
||||
|
@ -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" }
|
||||
|
||||
|
35
src/main.rs
35
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() {
|
||||
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();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user