Skip to main content

DaemonState

Struct DaemonState 

Source
pub struct DaemonState {
    pub config: DaemonConfig,
    pub audit: Arc<dyn AuditStore>,
    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.

§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::System is 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 AptUpgrade while the first still owns ExclusiveResource::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

Source

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.

Source

pub fn open_with_policy( config: DaemonConfig, policy: PolicyTable, ) -> Result<Self, DaemonStateError>

Open the daemon state with an explicit policy table and no forwarding.

Source

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.

Source

pub fn open_with_audit( config: DaemonConfig, policy: PolicyTable, forwarder: Option<AuditForwarder>, audit: Arc<dyn AuditStore>, ) -> 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.

Source

pub fn bootstrap( config: DaemonConfig, ) -> Result<DaemonRuntime, DaemonStateError>

Trait Implementations§

Source§

impl Clone for DaemonState

Source§

fn clone(&self) -> DaemonState

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for DaemonState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more