default to /tmp/rss/ for shared multi-user access
- runtime_dir() defaults to /tmp/rss (no user-specific fallback) - socket_path() defaults to /tmp/rss/rss.sock (overridable via RSS_SOCKET) - enabled markers in runtime_dir, not config_dir (shared state) - daemon creates /tmp/rss/ with explicit 770 permissions
This commit is contained in:
parent
7383445ea5
commit
38882b70c3
3 changed files with 10 additions and 26 deletions
|
|
@ -7,8 +7,6 @@ Type=simple
|
||||||
ExecStart=%h/.cargo/bin/rss daemon
|
ExecStart=%h/.cargo/bin/rss daemon
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=5
|
RestartSec=5
|
||||||
Environment=RSS_CONFIG=%h/.config/rss/config.toml
|
|
||||||
Environment=RSS_STATE_DIR=%h/.local/share/rss
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=default.target
|
WantedBy=default.target
|
||||||
|
|
|
||||||
|
|
@ -47,14 +47,7 @@ pub fn run(config_path: String) {
|
||||||
}
|
}
|
||||||
if let Some(parent) = sock_path.parent() {
|
if let Some(parent) = sock_path.parent() {
|
||||||
fs::create_dir_all(parent).ok();
|
fs::create_dir_all(parent).ok();
|
||||||
// Make directory group-accessible (rwxrwx---)
|
let _ = fs::set_permissions(parent, fs::Permissions::from_mode(0o770));
|
||||||
if let Ok(dir) = fs::metadata(parent) {
|
|
||||||
let perm = dir.permissions();
|
|
||||||
let mode = perm.mode();
|
|
||||||
// set group rwx if owner has it
|
|
||||||
let group = (mode & 0o700) >> 3;
|
|
||||||
let _ = fs::set_permissions(parent, fs::Permissions::from_mode(mode | group));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load config
|
// Load config
|
||||||
|
|
|
||||||
25
src/state.rs
25
src/state.rs
|
|
@ -4,14 +4,14 @@ pub fn runtime_dir() -> PathBuf {
|
||||||
if let Ok(dir) = std::env::var("RSS_STATE_DIR") {
|
if let Ok(dir) = std::env::var("RSS_STATE_DIR") {
|
||||||
return PathBuf::from(dir);
|
return PathBuf::from(dir);
|
||||||
}
|
}
|
||||||
if let Ok(dir) = std::env::var("XDG_RUNTIME_DIR") {
|
PathBuf::from("/tmp/rss")
|
||||||
return PathBuf::from(dir).join("rss");
|
}
|
||||||
|
|
||||||
|
pub fn socket_path() -> PathBuf {
|
||||||
|
if let Ok(p) = std::env::var("RSS_SOCKET") {
|
||||||
|
return PathBuf::from(p);
|
||||||
}
|
}
|
||||||
if let Ok(home) = std::env::var("HOME") {
|
PathBuf::from("/tmp/rss/rss.sock")
|
||||||
return PathBuf::from(home).join(".local/share/rss");
|
|
||||||
}
|
|
||||||
let user = std::env::var("USER").unwrap_or_else(|_| "unknown".into());
|
|
||||||
PathBuf::from(format!("/tmp/rss-{}", user))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn config_dir() -> PathBuf {
|
pub fn config_dir() -> PathBuf {
|
||||||
|
|
@ -24,13 +24,6 @@ pub fn config_dir() -> PathBuf {
|
||||||
PathBuf::from("/etc/rss")
|
PathBuf::from("/etc/rss")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn socket_path() -> PathBuf {
|
|
||||||
if let Ok(p) = std::env::var("RSS_SOCKET") {
|
|
||||||
return PathBuf::from(p);
|
|
||||||
}
|
|
||||||
runtime_dir().join("rss.sock")
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn daemon_pid_path() -> PathBuf {
|
pub fn daemon_pid_path() -> PathBuf {
|
||||||
runtime_dir().join("daemon.pid")
|
runtime_dir().join("daemon.pid")
|
||||||
}
|
}
|
||||||
|
|
@ -40,7 +33,7 @@ pub fn log_path(name: &str) -> PathBuf {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn enabled_path(name: &str) -> PathBuf {
|
pub fn enabled_path(name: &str) -> PathBuf {
|
||||||
config_dir().join("enabled").join(name)
|
runtime_dir().join("enabled").join(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_pid(path: &PathBuf) -> std::io::Result<()> {
|
pub fn write_pid(path: &PathBuf) -> std::io::Result<()> {
|
||||||
|
|
@ -68,7 +61,7 @@ pub fn disable(name: &str) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_enabled() -> std::io::Result<Vec<String>> {
|
pub fn list_enabled() -> std::io::Result<Vec<String>> {
|
||||||
let dir = config_dir().join("enabled");
|
let dir = runtime_dir().join("enabled");
|
||||||
if !dir.exists() {
|
if !dir.exists() {
|
||||||
return Ok(Vec::new());
|
return Ok(Vec::new());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue