Skip to content

Commit

Permalink
🔧 Support --session (default), and --system
Browse files Browse the repository at this point in the history
  • Loading branch information
jokeyrhyme committed Dec 14, 2024
1 parent 655afec commit 008ab64
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/bin/busd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@ extern crate busd;
#[cfg(unix)]
use std::{fs::File, io::Write, os::fd::FromRawFd};

use busd::bus;

use anyhow::Result;
use clap::Parser;
#[cfg(unix)]
use tokio::{select, signal::unix::SignalKind};
use tracing::error;
#[cfg(unix)]
use tracing::{info, warn};
use zbus::Address;

use busd::{bus, config::BusType};

/// A simple D-Bus broker.
#[derive(Parser, Debug)]
#[clap(author, version, about, long_about = None)]
struct Args {
/// The address to listen on.
/// Takes precedence over any `<listen>` element in the configuration file.
#[clap(short = 'a', long, value_parser)]
address: Option<String>,

Expand All @@ -36,6 +38,17 @@ struct Args {
#[cfg(unix)]
#[clap(long)]
ready_fd: Option<i32>,

/// Equivalent to `--address unix:tmpdir=$XDG_RUNTIME_DIR`
/// and --config /usr/share/dbus-1/session.conf`.
/// This is the default if `--system` is absent.
#[clap(long)]
session: bool,

/// Equivalent to `--address unix:path=/run/dbus/system_bus_socket`
/// and `--config /usr/share/dbus-1/system.conf`.
#[clap(long)]
system: bool,
}

#[tokio::main]
Expand All @@ -44,7 +57,21 @@ async fn main() -> Result<()> {

let args = Args::parse();

let mut bus = bus::Bus::for_address(args.address.as_deref()).await?;
// TODO: when we have `Config` from #159, prefer `config.r#type` before `BusType::default()`
let bus_type = if args.system {
BusType::System
} else {
BusType::default()
};

// TODO: when we have `Config` from #159, prefer `config.listen` before `try_from(bus_type)`
let address = if let Some(address) = args.address {
Address::try_from(address.as_str())?
} else {
Address::try_from(bus_type)?
};

let mut bus = bus::Bus::for_address(Some(&format!("{address}"))).await?;

#[cfg(unix)]
if let Some(fd) = args.ready_fd {
Expand Down

0 comments on commit 008ab64

Please sign in to comment.