blob: 46c8f8cc849867cfacfde0568344afe925355a87 [file] [log] [blame]
Alan Stokes9e2c5d52021-07-21 11:29:10 +01001/*
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Victor Hsieh9ebf7ee2021-09-03 16:14:14 -070017//! A tool to start a standalone compsvc server that serves over RPC binder.
Alan Stokes9e2c5d52021-07-21 11:29:10 +010018
19mod common;
Victor Hsieh51789de2021-08-06 16:50:49 -070020mod compilation;
Victor Hsieha64194b2021-08-06 17:43:36 -070021mod compos_key_service;
Alan Stokes9e2c5d52021-07-21 11:29:10 +010022mod compsvc;
Victor Hsieh9ed27182021-08-25 15:52:42 -070023mod fsverity;
Alan Stokes7ec4e7f2021-07-21 11:29:10 +010024mod signer;
Alan Stokes9e2c5d52021-07-21 11:29:10 +010025
Victor Hsieh9ebf7ee2021-09-03 16:14:14 -070026use crate::common::VSOCK_PORT;
27use anyhow::{bail, Result};
Alan Stokes9e2c5d52021-07-21 11:29:10 +010028use binder::unstable_api::AsNative;
Alan Stokes9e2c5d52021-07-21 11:29:10 +010029use log::debug;
30
Alan Stokes9e2c5d52021-07-21 11:29:10 +010031fn main() -> Result<()> {
32 android_logger::init_once(
33 android_logger::Config::default().with_tag("compsvc").with_min_level(log::Level::Debug),
34 );
35
Victor Hsieh9ebf7ee2021-09-03 16:14:14 -070036 let mut service = compsvc::new_binder()?.as_binder();
37 debug!("compsvc is starting as a rpc service.");
38 // SAFETY: Service ownership is transferring to the server and won't be valid afterward.
39 // Plus the binder objects are threadsafe.
40 let retval = unsafe {
41 binder_rpc_unstable_bindgen::RunRpcServer(
42 service.as_native_mut() as *mut binder_rpc_unstable_bindgen::AIBinder,
43 VSOCK_PORT,
44 )
45 };
46 if retval {
47 debug!("RPC server has shut down gracefully");
48 Ok(())
Alan Stokes9e2c5d52021-07-21 11:29:10 +010049 } else {
Victor Hsieh9ebf7ee2021-09-03 16:14:14 -070050 bail!("Premature termination of RPC server");
Alan Stokes9e2c5d52021-07-21 11:29:10 +010051 }
52}