From 572bc3ba44f8ad33ab002a31fbe5bce732e238a9 Mon Sep 17 00:00:00 2001
From: devmobasa <4170275+devmobasa@users.noreply.github.com>
Date: Fri, 30 Oct 2026 19:32:16 +0100
Subject: [PATCH] refactor: take advisory locks through rustix
Add rustix as a direct dependency. It is already compiled through the
Wayland stack, so this adds no new crate.
Use its typed flock operations for the durable, daemon protocol, and
action journal locks, which removes their unsafe blocks. Deadline locks
still always retry without blocking.
---
Cargo.lock | 1 +
Cargo.toml | 2 ++
src/daemon/protocol_v2/action.rs | 22 +++++++--------
src/daemon/protocol_v2/action/tests.rs | 16 +++--------
src/daemon/protocol_v2/command/action_link.rs | 9 ++++---
src/daemon/protocol_v2/command/claimed.rs | 12 ++++++---
src/daemon/protocol_v2/command/client.rs | 21 ++++++++++++---
src/daemon/protocol_v2/command/layout.rs | 27 ++++++++++---------
src/daemon/protocol_v2/command/owner.rs | 19 ++++++++-----
src/daemon/protocol_v2/command/recovery.rs | 3 ++-
src/daemon/protocol_v2/command/staging.rs | 3 ++-
src/daemon/protocol_v2/command/tests.rs | 14 +++++-----
src/durable_io/lock.rs | 22 +++++----------
tools/csharp/Commands/ChecksCommand.cs | 1 +
14 files changed, 96 insertions(+), 76 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index 2449a5d8..8d11b397 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1894,6 +1894,7 @@ dependencies = [
"pango",
"pangocairo",
"png",
+ "rustix",
"schemars",
"serde",
"serde_ignored",
diff --git a/Cargo.toml b/Cargo.toml
index d871ff0d..f6b9622d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -93,6 +93,8 @@ serde = { version = "1.0", features = ["derive"] }
serde_ignored = "0.1"
schemars = { version = "1.2", features = ["derive"], optional = true }
libc = "0.2"
+# Safe wrappers for the kernel interfaces that the std library does not cover.
+rustix = { version = "1", features = ["event", "fs", "net", "pipe", "process", "stdio", "termios", "thread", "time"] }
# Kernel random bytes for portal handle tokens and daemon protocol identifiers.
getrandom = { version = "0.4", features = ["std"] }
# Securely created, self-deleting temporary files for the OCR engine handoff.
diff --git a/src/daemon/protocol_v2/action.rs b/src/daemon/protocol_v2/action.rs
index ee637e91..bb378674 100644
--- a/src/daemon/protocol_v2/action.rs
+++ b/src/daemon/protocol_v2/action.rs
@@ -2,7 +2,6 @@
use std::collections::BTreeMap;
use std::fs::{self, File, OpenOptions};
use std::io::{self, ErrorKind};
-use std::os::fd::AsRawFd;
use std::os::unix::fs::{MetadataExt, OpenOptionsExt};
use std::path::{Path, PathBuf};
#[cfg(test)]
@@ -11,6 +10,7 @@ use std::sync::LazyLock;
use std::sync::Mutex;
use anyhow::{Context, Result, anyhow, bail};
+use rustix::fs::{self as rustix_fs, FlockOperation};
use serde::de::DeserializeOwned;
use serde::{Deserialize, Serialize};
@@ -224,10 +224,13 @@ fn try_open_journal_lock(root: &Path, nonblocking: bool) -> Result