pub struct DaemonState {
pub config: DaemonConfig,
pub audit: Arc<dyn AuditStore>,
pub request_hash_key: Arc<RequestHashKey>,
pub policy: PolicyTable,
pub host_distro: Option<DistroId>,
pub forwarder: Option<AuditForwarder>,
pub running_exclusive: Arc<Mutex<HashMap<ExclusiveResource, String>>>,
}Fields§
§config: DaemonConfig§audit: Arc<dyn AuditStore>Polymorphic audit store. Concrete impls: SqliteStore (default) and
PostgresStore (selected via [storage] backend = "postgres").
Both implement AuditStore async trait.
request_hash_key: Arc<RequestHashKey>HMAC key for the request_hash column, derived from the same audit key
material that signs the chain (#268). Preview hashes and execute-time
re-hashes both go through it, so the binding check needs the key and an
exported row is no longer offline-crackable without it.
policy: PolicyTable§host_distro: Option<DistroId>Strict host identity used to enforce the documented support matrix at preview and execution boundaries.
forwarder: Option<AuditForwarder>Optional external audit-log forwarder. None when no [audit.forward]
sink is configured; events recorded by the dispatcher are then only
written to the local hash-chained store.
running_exclusive: Arc<Mutex<HashMap<ExclusiveResource, String>>>Concurrency guard keyed by the system lock each in-flight mutating action holds (ME4).
Maps an ExclusiveResource to the request_hash of the action
currently holding it. A mutating action is rejected with a
ConflictResponse when either
ExclusiveResource::Systemis held — a reboot-required action (release upgrade, rebase, layered install) is in flight and conflicts with everything mutating; or- its own resource is held — e.g. a second
AptUpgradewhile the first still ownsExclusiveResource::Dpkg.
This replaced a single Option<String> slot that only High-risk
reboot-required actions ever claimed. Under that rule AptUpgrade
(High risk, reboot_required: false) claimed nothing, so two
concurrent apt-get dist-upgrade runs both passed the gate and then
collided on /var/lib/dpkg/lock-frontend — the exact contention the
gate exists to prevent, and one that can leave dpkg needing
--configure -a.
Actions with no shared lock (exclusive_resource returns None, e.g.
StartService) still respect a held System but never block each
other, so unrelated work is not serialised behind a long apt run.
The map is Arc<Mutex<…>> so cloned DaemonState values — one per IPC
connection — all share the same guard. Mutex::lock is held for at
most a few microseconds; read-only actions skip the check entirely.
On daemon crash the in-memory guard is lost. That is correct: the
daemon’s SQLite store will show the orphaned Running row; the
operator can inspect it via ListJobHistory.
Implementations§
Source§impl DaemonState
impl DaemonState
Sourcepub fn open(config: DaemonConfig) -> Result<Self, DaemonStateError>
pub fn open(config: DaemonConfig) -> Result<Self, DaemonStateError>
Open the daemon state with no policy overrides and no forwarding. Suitable for tests and dev runs.
Sourcepub fn open_with_policy(
config: DaemonConfig,
policy: PolicyTable,
) -> Result<Self, DaemonStateError>
pub fn open_with_policy( config: DaemonConfig, policy: PolicyTable, ) -> Result<Self, DaemonStateError>
Open the daemon state with an explicit policy table and no forwarding.
Sourcepub fn open_full(
config: DaemonConfig,
policy: PolicyTable,
forwarder: Option<AuditForwarder>,
) -> Result<Self, DaemonStateError>
pub fn open_full( config: DaemonConfig, policy: PolicyTable, forwarder: Option<AuditForwarder>, ) -> Result<Self, DaemonStateError>
Open the daemon state with full configuration. Production callers
(main.rs) build the policy table from [policy.risk_overrides] and
the forwarder from [audit.forward]. The audit store defaults to
SQLite at config.database_path; pass an explicit audit to use
Postgres or any other AuditStore impl.
Sourcepub fn open_with_audit(
config: DaemonConfig,
policy: PolicyTable,
forwarder: Option<AuditForwarder>,
audit: Arc<dyn AuditStore>,
audit_key: &AuditKey,
) -> Self
pub fn open_with_audit( config: DaemonConfig, policy: PolicyTable, forwarder: Option<AuditForwarder>, audit: Arc<dyn AuditStore>, audit_key: &AuditKey, ) -> Self
Open the daemon state with an explicit audit store. Used by main.rs
when [storage] backend = "postgres" is configured: the Postgres
AuditStore is constructed via PostgresStore::connect and passed
here as the audit argument, together with the AuditKey it was
connected with — the request_hash HMAC key is derived from that same
key, so the two backends cannot drift.
pub fn bootstrap( config: DaemonConfig, ) -> Result<DaemonRuntime, DaemonStateError>
Trait Implementations§
Source§impl Clone for DaemonState
impl Clone for DaemonState
Auto Trait Implementations§
impl !RefUnwindSafe for DaemonState
impl !UnwindSafe for DaemonState
impl Freeze for DaemonState
impl Send for DaemonState
impl Sync for DaemonState
impl Unpin for DaemonState
impl UnsafeUnpin for DaemonState
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more