1 #![no_std] 2 #![no_main] 3 #![feature(slice_pattern)] 4 #![feature(fn_traits)] 5 6 #[cfg(target_os = "dragonos")] 7 extern crate drstd as std; 8 9 extern crate hashbrown; 10 11 mod contants; 12 mod error; 13 mod executor; 14 mod manager; 15 mod parse; 16 mod systemctl; 17 mod task; 18 mod time; 19 mod unit; 20 21 use std::{eprint, eprintln}; 22 23 use std::string::ToString; 24 use std::vec::Vec; 25 26 use error::ErrorFormat; 27 use executor::Executor; 28 use manager::timer_manager::TimerManager; 29 use manager::Manager; 30 use parse::UnitParser; 31 use systemctl::listener::Systemctl; 32 33 pub struct FileDescriptor(usize); 34 35 const DRAGON_REACH_UNIT_DIR: &'static str = "/etc/reach/system/"; 36 37 #[no_mangle] 38 fn main() { 39 // 初始化 40 Systemctl::init(); 41 42 let mut units_file_name = Vec::new(); 43 //读取目录里面的unit文件 44 if let Ok(entries) = std::fs::read_dir(DRAGON_REACH_UNIT_DIR) { 45 for entry in entries { 46 if let Ok(entry) = entry { 47 if let Ok(file_type) = entry.file_type() { 48 if file_type.is_file() { 49 let filename = entry.file_name(); 50 let filename = filename.to_str().unwrap(); 51 units_file_name.push(filename.to_string()); 52 } 53 } 54 } 55 } 56 } 57 58 //启动服务 59 for path in units_file_name { 60 let id = match UnitParser::from_path(&path) { 61 Ok(id) => id, 62 Err(e) => { 63 eprintln!("Err:{}", e.error_format()); 64 0 65 } 66 }; 67 68 if id != 0 { 69 if let Err(e) = Executor::exec(id) { 70 eprintln!("Err:{}", e.error_format()); 71 } 72 } 73 } 74 75 // 启动完服务后进入主循环 76 loop { 77 // 检查各服务运行状态 78 Manager::check_running_status(); 79 // 检查cmd进程状态 80 Manager::check_cmd_proc(); 81 // 检查计时器任务 82 TimerManager::check_timer(); 83 // 监听systemctl 84 Systemctl::ctl_listen(); 85 } 86 } 87