Skip to content

Commit

Permalink
config: copy config instead of symlinking it
Browse files Browse the repository at this point in the history
  • Loading branch information
mahkoh committed Feb 23, 2024
1 parent 28a3b39 commit 817fdac
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
24 changes: 12 additions & 12 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
};

Expand All @@ -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,
}
Expand Down Expand Up @@ -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, &copy) {
return Err(ConfigError::CopyConfigFile(e));
}
let _unlink = UnlinkOnDrop(&link);
let lib = match Library::new(&link) {
let _unlink = UnlinkOnDrop(&copy);
let lib = match Library::new(&copy) {
Ok(l) => l,
Err(e) => return Err(ConfigError::CouldNotLoadLibrary(e)),
};
Expand Down

0 comments on commit 817fdac

Please sign in to comment.