blob: 9855b53bc3879e50e01b8f44a5420533c7bb5e0e [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
Victor Hsieh51789de2021-08-06 16:50:49 -070019mod compilation;
Victor Hsieha64194b2021-08-06 17:43:36 -070020mod compos_key_service;
Alan Stokes9e2c5d52021-07-21 11:29:10 +010021mod compsvc;
Victor Hsieh9ed27182021-08-25 15:52:42 -070022mod fsverity;
Alan Stokes7ec4e7f2021-07-21 11:29:10 +010023mod signer;
Alan Stokes9e2c5d52021-07-21 11:29:10 +010024
Victor Hsieh9ebf7ee2021-09-03 16:14:14 -070025use anyhow::{bail, Result};
Alan Stokes9e2c5d52021-07-21 11:29:10 +010026use binder::unstable_api::AsNative;
Alan Stokes17fd36a2021-09-06 17:22:37 +010027use compos_common::COMPOS_VSOCK_PORT;
Alan Stokes9e2c5d52021-07-21 11:29:10 +010028use log::debug;
29
Alan Stokes9e2c5d52021-07-21 11:29:10 +010030fn main() -> Result<()> {
31 android_logger::init_once(
32 android_logger::Config::default().with_tag("compsvc").with_min_level(log::Level::Debug),
33 );
34
Victor Hsieh9ebf7ee2021-09-03 16:14:14 -070035 let mut service = compsvc::new_binder()?.as_binder();
36 debug!("compsvc is starting as a rpc service.");
37 // SAFETY: Service ownership is transferring to the server and won't be valid afterward.
38 // Plus the binder objects are threadsafe.
39 let retval = unsafe {
40 binder_rpc_unstable_bindgen::RunRpcServer(
41 service.as_native_mut() as *mut binder_rpc_unstable_bindgen::AIBinder,
Alan Stokes17fd36a2021-09-06 17:22:37 +010042 COMPOS_VSOCK_PORT,
Victor Hsieh9ebf7ee2021-09-03 16:14:14 -070043 )
44 };
45 if retval {
46 debug!("RPC server has shut down gracefully");
47 Ok(())
Alan Stokes9e2c5d52021-07-21 11:29:10 +010048 } else {
Victor Hsieh9ebf7ee2021-09-03 16:14:14 -070049 bail!("Premature termination of RPC server");
Alan Stokes9e2c5d52021-07-21 11:29:10 +010050 }
51}