blob: 1ab17d54322cdbefbf4e1266eab7584b7f857019 [file] [log] [blame]
Jooyung Han347d9f22021-05-28 00:05:14 +09001// 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
Jooyung Hanf48ceb42021-06-01 18:00:04 +090017mod ioutil;
Jooyung Han74573482021-06-08 17:10:21 +090018mod metadata;
Jooyung Han347d9f22021-05-28 00:05:14 +090019mod payload_config;
Jooyung Han347d9f22021-05-28 00:05:14 +090020
21use android_logger::Config;
22use log::{info, Level};
23use payload_config::{Task, VmPayloadConfig};
24use std::io;
Jooyung Hanf48ceb42021-06-01 18:00:04 +090025use std::path::Path;
26use std::process::{Command, Stdio};
Jooyung Han347d9f22021-05-28 00:05:14 +090027
28const LOG_TAG: &str = "MicrodroidManager";
29
30fn main() -> io::Result<()> {
31 android_logger::init_once(Config::default().with_tag(LOG_TAG).with_min_level(Level::Debug));
32
33 info!("started.");
34
Jooyung Han74573482021-06-08 17:10:21 +090035 let metadata = metadata::load()?;
36 if !metadata.payload_config_path.is_empty() {
37 let config = VmPayloadConfig::load_from(Path::new(&metadata.payload_config_path))?;
Jooyung Han347d9f22021-05-28 00:05:14 +090038 if let Some(main_task) = &config.task {
39 exec(main_task)?;
40 }
41 }
42
43 Ok(())
44}
45
46/// executes a task
47/// TODO(jooyung): fork a child process
48fn exec(task: &Task) -> io::Result<()> {
49 info!("executing main task {} {:?}...", task.command, task.args);
Jooyung Hanf48ceb42021-06-01 18:00:04 +090050 let exit_status =
51 Command::new(&task.command).args(&task.args).stdout(Stdio::inherit()).status()?;
Jooyung Han347d9f22021-05-28 00:05:14 +090052 info!("exit with {}", &exit_status);
53 Ok(())
54}