Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f96019f6 authored by Sonny Sasaka's avatar Sonny Sasaka
Browse files

Floss: Add debug flag to btmanagerd

Adds -d/--debug flag to btmanagerd, also uses the `clap` crate to make
it easier to add more command line flags in the future.

Bug: 228905413
Tag: #floss
Test: Ran `./btmanagerd --systemd --debug`

Change-Id: Ib8b58c41a3086254ce35aa1e36fd9bd19e31ba12
parent 4afb69b0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ num-traits = "0.2"
bt_common = { path = "../../common" }

# external deps
clap = "2.33.3"
dbus = "0.9.2"
dbus-tokio = "0.7.3"
dbus-crossroads = "0.4.0"
+20 −8
Original line number Diff line number Diff line
@@ -3,6 +3,9 @@
// apply certain linker flags (which is applied to the library but not the binary).
// Please keep main.rs logic light and write the heavy logic in the manager_service library instead.

extern crate clap;

use clap::{App, Arg};
use dbus::channel::MatchingReceiver;
use dbus::message::MatchRule;
use dbus_crossroads::Crossroads;
@@ -18,6 +21,14 @@ use syslog::{BasicLogger, Facility, Formatter3164};

#[tokio::main]
pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let matches = App::new("Bluetooth Manager")
        .arg(Arg::with_name("systemd").long("systemd").help("If btadapterd uses systemd init"))
        .arg(Arg::with_name("debug").long("debug").short("d").help("Enables debug level logs"))
        .get_matches();

    let is_debug = matches.is_present("debug");
    let is_systemd = matches.is_present("systemd");

    let formatter = Formatter3164 {
        facility: Facility::LOG_USER,
        hostname: None,
@@ -26,8 +37,13 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
    };

    let logger = syslog::unix(formatter).expect("could not connect to syslog");
    let _ = log::set_boxed_logger(Box::new(BasicLogger::new(logger)))
        .map(|()| log::set_max_level(config_util::get_log_level().unwrap_or(LevelFilter::Info)));
    let _ = log::set_boxed_logger(Box::new(BasicLogger::new(logger))).map(|()| {
        log::set_max_level(config_util::get_log_level().unwrap_or(if is_debug {
            LevelFilter::Debug
        } else {
            LevelFilter::Info
        }))
    });

    // Initialize config util
    config_util::fix_config_file_format();
@@ -41,12 +57,8 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
    conn.set_signal_match_mode(true);

    // Determine whether to use upstart or systemd
    let args: Vec<String> = std::env::args().collect();
    let invoker = if args.len() > 1 {
        match &args[1][0..] {
            "--systemd" | "-s" => state_machine::Invoker::SystemdInvoker,
            _ => state_machine::Invoker::UpstartInvoker,
        }
    let invoker = if is_systemd {
        state_machine::Invoker::SystemdInvoker
    } else {
        state_machine::Invoker::UpstartInvoker
    };