Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse XML configuration files #159

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ console-subscriber = { version = "0.4.0", optional = true }
xdg-home = "1.1.0"
event-listener = "5.3.0"
fastrand = "2.2.0"
quick-xml = { version = "0.36.2", features = ["serialize"] }

[target.'cfg(unix)'.dependencies]
nix = { version = "0.29.0", features = ["user"] }
Expand Down
39 changes: 35 additions & 4 deletions src/bin/busd.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
extern crate busd;

use std::path::PathBuf;
#[cfg(unix)]
use std::{fs::File, io::Write, os::fd::FromRawFd};

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

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

/// 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>,

/// Use the given configuration file.
#[clap(long)]
config: Option<PathBuf>,

/// Print the address of the message bus to standard output.
#[clap(long)]
print_address: bool,
Expand All @@ -36,6 +42,15 @@ struct Args {
#[cfg(unix)]
#[clap(long)]
ready_fd: Option<i32>,

/// Equivalent to `--config /usr/share/dbus-1/session.conf`.
/// This is the default if `--config` and `--system` are unspecified.
#[clap(long)]
session: bool,

/// Equivalent to `--config /usr/share/dbus-1/system.conf`.
#[clap(long)]
system: bool,
}

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

let args = Args::parse();

let mut bus = bus::Bus::for_address(args.address.as_deref()).await?;
let config_path = if args.system {
PathBuf::from("/usr/share/dbus-1/system.conf")
} else if let Some(config_path) = args.config {
config_path
} else {
PathBuf::from("/usr/share/dbus-1/session.conf")
};
info!("reading configuration file {} ...", config_path.display());
let config = Config::read_file(&config_path)?;

let address = if let Some(address) = args.address {
Some(address)
} else {
config.listen.map(|address| format!("{address}"))
};

let mut bus = bus::Bus::for_address(address.as_deref()).await?;

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