blob: 4f87a40af82ed96b479c89eaf9bbeb0cd56cf493 [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
17mod payload_config;
18mod signature;
19
20use android_logger::Config;
21use log::{info, Level};
22use payload_config::{Task, VmPayloadConfig};
23use std::io;
24use std::process::Command;
25
26const LOG_TAG: &str = "MicrodroidManager";
27
28fn 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
46fn 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}