1
0
Fork 0
forked from wry/wry

Merge pull request #107 from mahkoh/jorth/config-copy

config: copy config instead of symlinking it
This commit is contained in:
mahkoh 2024-02-23 17:48:14 +01:00 committed by GitHub
commit b078329a50
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 18 deletions

View file

@ -133,12 +133,6 @@ configuration is the [default config crate][default].
4. Build the crate with `cargo build`. 4. Build the crate with `cargo build`.
5. Move `target/debug/libmy_jay_config.so` to `$HOME/.config/jay/config.so`. 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 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, runtime you can repeat steps 3 to 5 and reload the configuration. By default,
the shortcut to reload the configuration is `ALT-r`. the shortcut to reload the configuration is `ALT-r`.

View file

@ -9,8 +9,8 @@ use {
ifs::wl_seat::SeatId, ifs::wl_seat::SeatId,
state::State, state::State,
utils::{ utils::{
clonecell::CloneCell, numcell::NumCell, oserror::OsError, ptr_ext::PtrExt, clonecell::CloneCell, numcell::NumCell, ptr_ext::PtrExt, unlink_on_drop::UnlinkOnDrop,
unlink_on_drop::UnlinkOnDrop, xrd::xrd, xrd::xrd,
}, },
}, },
bincode::Options, bincode::Options,
@ -25,7 +25,7 @@ use {
video::{Connector, DrmDevice}, video::{Connector, DrmDevice},
}, },
libloading::Library, libloading::Library,
std::{cell::Cell, mem, ptr, rc::Rc}, std::{cell::Cell, io, mem, ptr, rc::Rc},
thiserror::Error, thiserror::Error,
}; };
@ -37,8 +37,8 @@ pub enum ConfigError {
LibraryDoesNotContainEntry(#[source] libloading::Error), LibraryDoesNotContainEntry(#[source] libloading::Error),
#[error("Could not determine the config directory")] #[error("Could not determine the config directory")]
ConfigDirNotSet, ConfigDirNotSet,
#[error("Could not link the config file")] #[error("Could not copy the config file")]
LinkConfigFile(#[source] OsError), CopyConfigFile(#[source] io::Error),
#[error("XDG_RUNTIME_DIR is not set")] #[error("XDG_RUNTIME_DIR is not set")]
XrdNotSet, XrdNotSet,
} }
@ -233,24 +233,24 @@ impl ConfigProxy {
// glibc will still not reload the library if we try to load it from // 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 // the canonical location ~/.config/jay/config.so since it already has
// a library with that path loaded. To work around this, create a // 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. // from there.
let xrd = match xrd() { let xrd = match xrd() {
Some(x) => x, Some(x) => x,
_ => return Err(ConfigError::XrdNotSet), _ => return Err(ConfigError::XrdNotSet),
}; };
let link = format!( let copy = format!(
"{}/.jay_config.so.{}.{}", "{}/.jay_config.so.{}.{}",
xrd, xrd,
uapi::getpid(), uapi::getpid(),
state.config_file_id.fetch_add(1) state.config_file_id.fetch_add(1)
); );
let _ = uapi::unlink(link.as_str()); let _ = uapi::unlink(copy.as_str());
if let Err(e) = uapi::symlink(path, link.as_str()) { if let Err(e) = std::fs::copy(path, &copy) {
return Err(ConfigError::LinkConfigFile(e.into())); return Err(ConfigError::CopyConfigFile(e));
} }
let _unlink = UnlinkOnDrop(&link); let _unlink = UnlinkOnDrop(&copy);
let lib = match Library::new(&link) { let lib = match Library::new(&copy) {
Ok(l) => l, Ok(l) => l,
Err(e) => return Err(ConfigError::CouldNotLoadLibrary(e)), Err(e) => return Err(ConfigError::CouldNotLoadLibrary(e)),
}; };