Skip to content

Commit

Permalink
Allow lock mechanism to be bypassed via force
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Jan 25, 2021
1 parent bae4579 commit f758bd4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ fn default_display() -> u32 {
pub struct X11Config {
#[serde(default = "default_display")]
pub display: u32,

#[serde(default)]
pub force: bool,
}

impl Default for X11Config {
fn default() -> Self {
X11Config {
display: default_display(),
force: false,
}
}
}
2 changes: 1 addition & 1 deletion client/src/x11.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ async fn handle_stream(stream: UnixStream) -> std::io::Result<()> {
}

pub async fn x11_forward(config: &'static X11Config) -> std::io::Result<()> {
let lock = X11Lock::acquire(config.display)?;
let lock = X11Lock::acquire(config.display, config.force)?;
let listener = lock.bind()?;

loop {
Expand Down
4 changes: 2 additions & 2 deletions client/src/x11socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl Drop for X11Lock {
}

impl X11Lock {
pub fn acquire(display: u32) -> Result<Self> {
pub fn acquire(display: u32, force: bool) -> Result<Self> {
let name = format!("/tmp/.X{}-lock", display);

loop {
Expand Down Expand Up @@ -49,7 +49,7 @@ impl X11Lock {
!= libc::ESRCH;

// The process is still alive
if alive {
if alive && !force {
return Err(Error::new(
std::io::ErrorKind::AddrInUse,
format!("X{} is current in use", display),
Expand Down

0 comments on commit f758bd4

Please sign in to comment.