Skip to main content

Crate restart_manager

Crate restart_manager 

Source
Expand description

Safe blocking bindings to the Windows Restart Manager (rstrtmgr.dll).

A primary RestartSession owns shutdown, restart, filter, and cancellation capabilities. A secondary JoinedSession can only register and inspect resources, making a role violation impossible to express.

§Example

use restart_manager::{RestartSession, ShutdownOptions};

let mut session = RestartSession::new()?;
session.register_files([r"C:\some\locked\file.dll"])?;
let report = session.affected_applications()?;
for application in &report {
    println!("locked by: {:?}", application.display_name());
}
let pending = session.shutdown_with_options(ShutdownOptions::default());
let can_update = pending.shutdown_outcome().is_success();
if can_update {
    // Replace or update the registered files here.
}
let completion = pending.restart();
let outcome = completion.outcome().clone();
completion.end()?;
outcome.shutdown_outcome().clone().into_result()?;
outcome
    .restart_outcome()
    .expect("restart was attempted")
    .clone()
    .into_result()?;

Relative file and executable paths are made absolute, but this crate never checks existence or canonicalizes them. Restart Manager does not support registering directories. Forced shutdown is opt-in and can lose target application data. Restart is only possible for services and applications that registered for restart.

Progress callbacks use a process-global native callback slot because the Windows API supplies no context pointer. Concurrent callback-bearing calls fail immediately with ErrorKind::CallbackInUse. A callback panic is contained at the FFI boundary and resumed after Windows returns.

§Platform support

All domain and session types are available on every target. Pure input validation behaves identically everywhere; operations that require Windows return ErrorKind::UnsupportedPlatform.

§Typestate guarantees

A joined installer cannot query or control the primary workflow:

fn invalid(joined: &mut restart_manager::JoinedSession) {
    let _ = joined.affected_applications();
}

Restart is not available before a shutdown attempt:

fn invalid(session: restart_manager::RestartSession) {
    let _ = session.restart();
}

A pending recovery state cannot register resources, manipulate filters, or end the native session:

fn invalid(mut pending: restart_manager::RestartPending) {
    let batch = restart_manager::ResourceBatch::new();
    let _ = pending.register_resources(&batch);
    let _ = pending.end();
}

Consuming a state prevents a second operation on the same value:

fn invalid(session: restart_manager::RestartSession) {
    let _pending = session.shutdown();
    let _ = session.end();
}

Modules§

tokio
Tokio facade backed by one dedicated standard worker thread per session.

Structs§

AffectedApplication
One application or service using a registered resource.
AffectedApplications
A reusable affected-application report plus its reboot reasons.
ApplicationRestartOptions
Command-line arguments and positive restart policies for this application.
ApplicationRestartRegistration
An exclusive crate-managed lease for the current process registration.
ApplicationStatus
OR-able history bits from RM_APP_STATUS.
CancellationHandle
A weak, Send + Sync capability that can cancel a blocking native operation.
Error
An error returned by the safe Restart Manager API.
Filter
One filter returned by crate::RestartSession::filters.
FilterTarget
The executable, process, or service selected by a filter.
JoinedSession
A secondary-installer view of an existing session.
OperationNotStarted
A consuming operation that failed before native work began.
ParseSessionKeyError
Error returned when parsing a Restart Manager session key.
ProcessIdentity
A process identity made from its ID and creation time.
Progress
Progress reported by a blocking shutdown or restart operation.
RebootReasons
Reasons Windows says a reboot may be required.
RecoveryCompletion
Completed recovery state with retained results and post-operation reporting. This typestate is Send.
RecoveryOutcome
Results from the shutdown attempt and the optional restart attempt.
ResourceBatch
Files, processes, and services to register in one native call.
RestartPending
The state entered after any shutdown attempt.
RestartSession
A primary-installer Restart Manager session.
SessionKey
A validated, 32-character ASCII hexadecimal Restart Manager session key.
ShutdownOptions
Options accepted by crate::RestartSession::shutdown_with_options.

Enums§

ApplicationType
The kind of an affected application, corresponding to RM_APP_TYPE.
ErrorKind
A stable, non-exhaustive classification of failures.
FilterAction
The official RM_FILTER_ACTION behavior.
OperationOutcome
The retained result of one native shutdown or restart attempt.

Type Aliases§

Result
Specialised result alias used by this crate.