diff --git a/README.md b/README.md index 63f5958d..204df31c 100644 --- a/README.md +++ b/README.md @@ -133,12 +133,6 @@ configuration is the [default config crate][default]. 4. Build the crate with `cargo build`. 5. Move `target/debug/libmy_jay_config.so` to `$HOME/.config/jay/config.so`. -CAUTION: A common mistake is to use `cp` to copy the shared library to the -config location. By default, `cp` will overwrite the file instead of replacing -it with a new file. If you do this at runtime, `jay` will almost certainly -crash. Instead use `mv` to move the file or first delete the old file before -using `cp`. - When you start Jay, you will be able to make use of your useful change. At runtime you can repeat steps 3 to 5 and reload the configuration. By default, the shortcut to reload the configuration is `ALT-r`. diff --git a/src/config.rs b/src/config.rs index 5b48c42f..f85b668f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,8 +9,8 @@ use { ifs::wl_seat::SeatId, state::State, utils::{ - clonecell::CloneCell, numcell::NumCell, oserror::OsError, ptr_ext::PtrExt, - unlink_on_drop::UnlinkOnDrop, xrd::xrd, + clonecell::CloneCell, numcell::NumCell, ptr_ext::PtrExt, unlink_on_drop::UnlinkOnDrop, + xrd::xrd, }, }, bincode::Options, @@ -25,7 +25,7 @@ use { video::{Connector, DrmDevice}, }, libloading::Library, - std::{cell::Cell, mem, ptr, rc::Rc}, + std::{cell::Cell, io, mem, ptr, rc::Rc}, thiserror::Error, }; @@ -37,8 +37,8 @@ pub enum ConfigError { LibraryDoesNotContainEntry(#[source] libloading::Error), #[error("Could not determine the config directory")] ConfigDirNotSet, - #[error("Could not link the config file")] - LinkConfigFile(#[source] OsError), + #[error("Could not copy the config file")] + CopyConfigFile(#[source] io::Error), #[error("XDG_RUNTIME_DIR is not set")] XrdNotSet, } @@ -233,24 +233,24 @@ impl ConfigProxy { // glibc will still not reload the library if we try to load it from // the canonical location ~/.config/jay/config.so since it already has // a library with that path loaded. To work around this, create a - // temporary symlink with an incrementing number and load the library + // temporary copy with an incrementing number and load the library // from there. let xrd = match xrd() { Some(x) => x, _ => return Err(ConfigError::XrdNotSet), }; - let link = format!( + let copy = format!( "{}/.jay_config.so.{}.{}", xrd, uapi::getpid(), state.config_file_id.fetch_add(1) ); - let _ = uapi::unlink(link.as_str()); - if let Err(e) = uapi::symlink(path, link.as_str()) { - return Err(ConfigError::LinkConfigFile(e.into())); + let _ = uapi::unlink(copy.as_str()); + if let Err(e) = std::fs::copy(path, ©) { + return Err(ConfigError::CopyConfigFile(e)); } - let _unlink = UnlinkOnDrop(&link); - let lib = match Library::new(&link) { + let _unlink = UnlinkOnDrop(©); + let lib = match Library::new(©) { Ok(l) => l, Err(e) => return Err(ConfigError::CouldNotLoadLibrary(e)), };