Skip to content

Commit

Permalink
Add --print-address
Browse files Browse the repository at this point in the history
Signed-off-by: Marc-André Lureau <[email protected]>
  • Loading branch information
elmarco committed Jun 26, 2023
1 parent 335a320 commit f85e204
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/bin/busd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ struct BusdArgs {
#[clap(short = 'a', long, value_parser)]
address: Option<String>,

/// The file descriptor to print the bus address to.
#[clap(long, value_parser)]
print_address: Option<Option<i32>>,

/// The authentication mechanism to use.
#[clap(long)]
#[arg(value_enum, default_value_t = AuthMechanism::External)]
Expand Down Expand Up @@ -109,6 +113,16 @@ async fn main() -> Result<()> {

let mut bus = bus::Bus::for_address(address, args.auth_mechanism.into()).await?;

if let Some(fd) = args.print_address {
use std::io::Write;
use std::os::fd::FromRawFd;

let mut file = unsafe { std::fs::File::from_raw_fd(fd.unwrap_or(1)) };
// make a single string, busd test code doesn't handle multiple IO!
let addr = format!("{},guid={}\n", bus.address().to_string(), bus.guid());
write!(file, "{}", addr)?;
file.flush()?;
}

// FIXME: How to handle this gracefully on Windows?
#[cfg(unix)]
Expand Down

0 comments on commit f85e204

Please sign in to comment.