Jooyung Han | 347d9f2 | 2021-05-28 00:05:14 +0900 | [diff] [blame^] | 1 | // Copyright 2021, The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | //! Microdroid Manager |
| 16 | |
| 17 | mod payload_config; |
| 18 | mod signature; |
| 19 | |
| 20 | use android_logger::Config; |
| 21 | use log::{info, Level}; |
| 22 | use payload_config::{Task, VmPayloadConfig}; |
| 23 | use std::io; |
| 24 | use std::process::Command; |
| 25 | |
| 26 | const LOG_TAG: &str = "MicrodroidManager"; |
| 27 | |
| 28 | fn main() -> io::Result<()> { |
| 29 | android_logger::init_once(Config::default().with_tag(LOG_TAG).with_min_level(Level::Debug)); |
| 30 | |
| 31 | info!("started."); |
| 32 | |
| 33 | let signature = signature::load()?; |
| 34 | if !signature.payload_config_path.is_empty() { |
| 35 | let config = VmPayloadConfig::load_from(&signature.payload_config_path)?; |
| 36 | if let Some(main_task) = &config.task { |
| 37 | exec(main_task)?; |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | Ok(()) |
| 42 | } |
| 43 | |
| 44 | /// executes a task |
| 45 | /// TODO(jooyung): fork a child process |
| 46 | fn exec(task: &Task) -> io::Result<()> { |
| 47 | info!("executing main task {} {:?}...", task.command, task.args); |
| 48 | let exit_status = Command::new(&task.command).args(&task.args).status()?; |
| 49 | info!("exit with {}", &exit_status); |
| 50 | Ok(()) |
| 51 | } |