Skip to content

Commit

Permalink
Merge pull request #44 from jamesmcm/pulseaudio
Browse files Browse the repository at this point in the history
Add PulseAudio support
  • Loading branch information
jamesmcm authored Nov 15, 2020
2 parents 1c52e58 + 95dbeaf commit 5c41a4f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "vopono"
description = "Launch applications via VPN tunnels using temporary network namespaces"
version = "0.5.3"
version = "0.6.0"
authors = ["James McMurray <[email protected]>"]
edition = "2018"
license = "GPL-3.0-or-later"
Expand Down
11 changes: 9 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ mod network_interface;
mod openconnect;
mod openvpn;
mod providers;
mod pulseaudio;
mod shadowsocks;
mod sync;
mod sysctl;
Expand All @@ -21,13 +22,14 @@ mod wireguard;

use list::output_list;
use list_configs::print_configs;
use log::LevelFilter;
use log::{debug, LevelFilter};
use netns::NetworkNamespace;
use structopt::StructOpt;
use sync::{sync_menu, synch};
use util::clean_dead_locks;
use util::clean_dead_namespaces;
use util::elevate_privileges;
use which::which;

// TODO:
// - Allow for not saving OpenVPN creds to config
Expand All @@ -49,7 +51,12 @@ fn main() -> anyhow::Result<()> {
match app.cmd {
args::Command::Exec(cmd) => {
clean_dead_locks()?;

if which("pactl").is_ok() {
let pa = pulseaudio::get_pulseaudio_server()?;
std::env::set_var("PULSE_SERVER", pa);
} else {
debug!("pactl not found, will not set PULSE_SERVER");
}
elevate_privileges()?;
clean_dead_namespaces()?;
exec::exec(cmd)?
Expand Down
4 changes: 2 additions & 2 deletions src/netns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ impl NetworkNamespace {
handle.current_dir(cdir);
}
let sudo_string = if user.is_some() {
handle.args(&["sudo", "-u", user.as_ref().unwrap()]);
Some(format!(" sudo -u {}", user.as_ref().unwrap()))
handle.args(&["sudo", "-Eu", user.as_ref().unwrap()]);
Some(format!(" sudo -Eu {}", user.as_ref().unwrap()))
} else {
None
};
Expand Down
23 changes: 23 additions & 0 deletions src/pulseaudio.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use anyhow::anyhow;
use log::debug;
use regex::Regex;
use std::process::Command;

pub fn get_pulseaudio_server() -> anyhow::Result<String> {
let output = Command::new("pactl").args(&["info"]).output()?.stdout;
let re = Regex::new(r"Server String: ([^\n]+)").unwrap();
let output = std::str::from_utf8(&output)?;

let caps = re.captures(output);
if caps.is_none() {
return Err(anyhow!("Could not parse pactl output!"));
}
let caps = caps.unwrap().get(1);
if caps.is_none() {
return Err(anyhow!("Could not parse pactl output!"));
}

let out = caps.unwrap().as_str().to_string();
debug!("Setting PULSE_SERVER to {}", out);
Ok(out)
}

0 comments on commit 5c41a4f

Please sign in to comment.