xref: /DragonReach/src/main.rs (revision e5a8055aa517085cf10def70e7fddab4ec87fd13)
1*e5a8055aSGnoCiYeH // #![no_std]
2*e5a8055aSGnoCiYeH // #![no_main]
3*e5a8055aSGnoCiYeH #![feature(slice_pattern)]
4*e5a8055aSGnoCiYeH 
5f206f17aSGnoCiYeH use cfg_if::cfg_if;
621fc724cSGnoCiYeH 
7f206f17aSGnoCiYeH cfg_if!{
8f206f17aSGnoCiYeH     if #[cfg(target_os = "dragonos")]{
9f206f17aSGnoCiYeH         extern crate drstd;
10f206f17aSGnoCiYeH         use drstd as std;
114e851715SGnoCiYeH         use std::print;
124e851715SGnoCiYeH         use std::println;
13*e5a8055aSGnoCiYeH         use std::rc::Arc;
144e851715SGnoCiYeH         use unit::service::ServiceUnit;
15f206f17aSGnoCiYeH     }
16f206f17aSGnoCiYeH }
17f206f17aSGnoCiYeH 
18f206f17aSGnoCiYeH extern crate hashbrown;
194e851715SGnoCiYeH 
2021fc724cSGnoCiYeH mod contants;
214e851715SGnoCiYeH mod error;
224e851715SGnoCiYeH mod parse;
234e851715SGnoCiYeH mod task;
2421fc724cSGnoCiYeH mod unit;
25*e5a8055aSGnoCiYeH mod manager;
26*e5a8055aSGnoCiYeH mod executor;
2721fc724cSGnoCiYeH 
284e851715SGnoCiYeH use crate::unit::service;
2921fc724cSGnoCiYeH 
304e851715SGnoCiYeH use self::unit::Unit;
314e851715SGnoCiYeH 
324e851715SGnoCiYeH pub struct FileDescriptor(usize);
334e851715SGnoCiYeH 
34f206f17aSGnoCiYeH #[cfg(target_os = "dragonos")]
35f206f17aSGnoCiYeH #[no_mangle]
364e851715SGnoCiYeH fn main() {
37f206f17aSGnoCiYeH     use unit::service::ServiceUnit;
38f206f17aSGnoCiYeH 
39f206f17aSGnoCiYeH     let service = match ServiceUnit::from_path("/bin/test.service"){
40f206f17aSGnoCiYeH         Ok(service) => service,
41f206f17aSGnoCiYeH         Err(e) => {
42f206f17aSGnoCiYeH             println!("Error:{}",e.error_format());
43f206f17aSGnoCiYeH             return;
444e851715SGnoCiYeH         }
45f206f17aSGnoCiYeH     };
46f206f17aSGnoCiYeH     let service = service.as_ref();
47f206f17aSGnoCiYeH     println!("parse_result:");
48f206f17aSGnoCiYeH     println!("Description:{:?}", service.unit_base().unit_part().description());
49f206f17aSGnoCiYeH     println!("Documentation:{:?}",service.unit_base().unit_part().documentation());
50f206f17aSGnoCiYeH     println!("ServiceType:{:?}",service.service_part().service_type());
51f206f17aSGnoCiYeH     println!("ExecStrat:{:?}",service.service_part().exec_start());
52f206f17aSGnoCiYeH     println!("WorkingDirectory:{:?}",service.service_part().working_directory());
53f206f17aSGnoCiYeH     println!("Environment:{:?}",service.service_part().environment());
54f206f17aSGnoCiYeH     println!("Restart:{:?}",service.service_part().restart());
55f206f17aSGnoCiYeH     println!("RestartSec:{:?}",service.service_part().restart_sec());
56f206f17aSGnoCiYeH     println!("User:{:?}",service.service_part().user());
57f206f17aSGnoCiYeH     println!("Group:{:?}",service.service_part().group());
58f206f17aSGnoCiYeH     println!("TimeoutStartSec:{:?}",service.service_part().timeout_start_sec());
59f206f17aSGnoCiYeH     println!("TimeoutStopSec:{:?}",service.service_part().timeout_stop_sec());
60f206f17aSGnoCiYeH }
61f206f17aSGnoCiYeH 
62f206f17aSGnoCiYeH #[cfg(not(target_os = "dragonos"))]
63f206f17aSGnoCiYeH fn main() {
64*e5a8055aSGnoCiYeH     use std::{process::Command, sync::Arc};
65*e5a8055aSGnoCiYeH 
66f206f17aSGnoCiYeH     use unit::service::ServiceUnit;
67f206f17aSGnoCiYeH 
68*e5a8055aSGnoCiYeH     use crate::{executor::Executor, error::ErrorFormat};
69*e5a8055aSGnoCiYeH 
70f206f17aSGnoCiYeH     let service = match ServiceUnit::from_path("/home/heyicong/DragonReach/parse_test/test.service"){
71f206f17aSGnoCiYeH         Ok(service) => service,
72f206f17aSGnoCiYeH         Err(e) => {
73f206f17aSGnoCiYeH             println!("Error:{}",e.error_format());
74f206f17aSGnoCiYeH             return;
75f206f17aSGnoCiYeH         }
76f206f17aSGnoCiYeH     };
77f206f17aSGnoCiYeH 
78*e5a8055aSGnoCiYeH     let unit: Arc<dyn Unit> = service.clone();
79*e5a8055aSGnoCiYeH     println!("unit: {:?}",unit.unit_type());
80*e5a8055aSGnoCiYeH     println!("unit: {:?}",unit.unit_base().unit_part().description());
81*e5a8055aSGnoCiYeH     if let Err(e) = Executor::exec(&unit) {
82*e5a8055aSGnoCiYeH         println!("Error:{}",e.error_format());
83*e5a8055aSGnoCiYeH         return;
84*e5a8055aSGnoCiYeH     }
8521fc724cSGnoCiYeH }
86