windows: a failed check of the state root is made again (0.1.0-pre.2)
The once-per-process guard recorded the root before ensure_root ran. A first check that failed (the service log's create_all ignores its error) left the root marked as checked, so run()'s create_all skipped the check and the service went on with a root it could not secure, and runs what is under its bin\ as SYSTEM. Now only a check that passed is recorded, under the lock, and a failed one fails again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e84d42a10c
commit
363caf912a
3 files changed
+34
-18
No files matched your search
Generated
+4
-4
@@ -879,7 +879,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ps-core"
|
||||
version = "0.1.0-pre.1"
|
||||
version = "0.1.0-pre.2"
|
||||
dependencies = [
|
||||
"base64 0.22.1",
|
||||
"indexmap",
|
||||
@@ -893,7 +893,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ps-ctl"
|
||||
version = "0.1.0-pre.1"
|
||||
version = "0.1.0-pre.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
@@ -905,7 +905,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ps-ipc"
|
||||
version = "0.1.0-pre.1"
|
||||
version = "0.1.0-pre.2"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"serde_json",
|
||||
@@ -916,7 +916,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "ps-service"
|
||||
version = "0.1.0-pre.1"
|
||||
version = "0.1.0-pre.2"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"clap",
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ resolver = "2"
|
||||
members = ["crates/ps-core", "crates/ps-ipc", "crates/ps-service", "crates/ps-ctl"]
|
||||
|
||||
[workspace.package]
|
||||
version = "0.1.0-pre.1"
|
||||
version = "0.1.0-pre.2"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
repository = "https://git.faumaray.com/faumaray/proxy-suite-flake"
|
||||
|
||||
@@ -73,23 +73,18 @@ impl Paths {
|
||||
pub fn create_all(&self) -> std::io::Result<()> {
|
||||
// Once per process: a second check of a root this process made (and may be writing
|
||||
// its log into) has nothing to learn, and moving it aside then would lose the log.
|
||||
// Only a check that passed counts: a failed one is made again, and fails again.
|
||||
static CHECKED: std::sync::Mutex<Vec<PathBuf>> = std::sync::Mutex::new(Vec::new());
|
||||
let first = {
|
||||
let mut checked = CHECKED.lock().unwrap();
|
||||
let first = !checked.contains(&self.root);
|
||||
if first {
|
||||
{
|
||||
let mut checked = CHECKED.lock().unwrap_or_else(|e| e.into_inner());
|
||||
if !checked.contains(&self.root) {
|
||||
#[cfg(windows)]
|
||||
secure::ensure_root(&self.root)?;
|
||||
#[cfg(not(windows))]
|
||||
std::fs::create_dir_all(&self.root)?;
|
||||
checked.push(self.root.clone());
|
||||
}
|
||||
first
|
||||
};
|
||||
#[cfg(windows)]
|
||||
if first {
|
||||
secure::ensure_root(&self.root)?;
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
let _ = first;
|
||||
#[cfg(not(windows))]
|
||||
std::fs::create_dir_all(&self.root)?;
|
||||
for dir in [self.subscriptions(), self.rule_sets(), self.cache(), self.run(), self.logs(), self.bin()] {
|
||||
std::fs::create_dir_all(dir)?;
|
||||
}
|
||||
@@ -359,3 +354,24 @@ mod secure {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_failed_check_is_made_again() {
|
||||
let dir = std::env::temp_dir().join(format!("ps-paths-test-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
// A root that cannot be made: the first call fails, and so must every later one.
|
||||
let root = dir.join("root");
|
||||
std::fs::write(&root, b"").unwrap();
|
||||
let paths = Paths::new(&root);
|
||||
assert!(paths.create_all().is_err());
|
||||
assert!(paths.create_all().is_err());
|
||||
std::fs::remove_file(&root).unwrap();
|
||||
paths.create_all().unwrap();
|
||||
assert!(paths.bin().is_dir());
|
||||
std::fs::remove_dir_all(&dir).unwrap();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user