Skip to main content

Crate alpha2_os

Crate alpha2_os 

Source
Expand description

Safe wrappers for the operating-system calls the native host needs that the standard library does not offer at the minimum Rust version: file locks, no-replace publishing, termination handling, parent and child lifetime, clocks, memory, and the OS version.

The rest of the workspace forbids unsafe; this crate and alpha2-ffmpeg-bridge hold the few calls that need it.

Macros§

diagnostic
eprintln! that drops the line instead of panicking (write_diagnostic).

Structs§

AwakeInstant
A point on a clock that stops while the system sleeps, so stall checks ignore suspend.
KillOnCloseJob
A Windows job that kills its processes when dropped or when this process ends, for probe children that may hang. A no-op elsewhere.
MemoryCapacity
The machine’s memory and this process’s limit. Unavailable figures are None.
NameLimit
The longest file name a directory takes.
ProcessMemory
The process’s memory, as the operating system counts it.
Published
A finished file moved into place.
RetryPolicy
How long a publish retries a step refused by another program’s open handle.
Termination
A request to end the process: an interrupt or termination signal on Unix, a console control event on Windows.

Enums§

NameUnit
What a NameLimit counts.
PublishMethod
How publish_no_replace or publish_replace moved a file into place.

Functions§

cgroup_v2_usage
The process’s cgroup v2 (working set, memory.max) when it has a limit. The working set excludes reclaimable inactive_file page cache, which the kernel drops at the limit instead of killing anything.
exit_without_handlers
Ends the process now with code, without running exit handlers. The caller must flush first.
file_version
The major.minor.build.revision from the Windows version resource of path; None elsewhere or without one.
is_retryable_publish_error
Whether a publish step failed because another program (antivirus, indexer, media player) briefly holds the file open: ERROR_ACCESS_DENIED, ERROR_SHARING_VIOLATION or ERROR_LOCK_VIOLATION on Windows. Always false on Unix, where open handles do not block a rename.
limit_heap_arenas
Caps glibc’s malloc arenas at arenas unless MALLOC_ARENA_MAX is set. Does nothing elsewhere.
memory_capacity
The machine’s memory and this process’s limit, read now.
memory_capacity_at
memory_capacity with root standing in for /.
name_limit
The longest file name dir accepts: pathconf(_PC_NAME_MAX) on Unix (255 bytes if unreported), 255 UTF-16 units on Windows.
on_termination
Calls handler on its own thread when the process is asked to terminate, instead of ending at once. watch_parent calls the same handler.
os_version
The OS version, read once: 27.0.1 (26A434) on macOS, Ubuntu 22.04.5 LTS, kernel 6.8.0 on Linux, 10.0.26300.9711 on Windows. Missing parts are omitted; unknown if all are.
prefer_fast_cores
Asks the scheduler to keep the calling thread on the fastest cores, so thread_cpu_work readings come from one kind of core: QOS_CLASS_USER_INTERACTIVE on macOS, no EcoQoS throttling on Windows, nothing elsewhere. Best effort; failures are silent.
process_cpu_time
User plus system CPU time of all the process’s threads so far; None where unavailable.
process_memory
The process’s memory now and at its peak; unavailable figures are None.
publish_no_replace
Moves the finished file from to to, never replacing an existing file at to.
publish_replace
Moves the finished file from to to, replacing any file there. Retryable errors are retried as retry allows.
quarantined
Whether path has the macOS com.apple.quarantine attribute, under which Gatekeeper refuses to load an unnotarized library. false on other systems and for unreadable files.
same_file
Whether path still names the file file is open on. false when the path is gone, names a recreated file, or names a removed file kept visible by an open handle (Windows and SMB keep such names until the last handle closes).
same_file_at
Whether a and b name one file (same device and inode, or volume serial and file index on Windows). Hard links and symlinks count as the same file. false when either path is missing.
stop_std_handle_inheritance
Stops children from implicitly inheriting this process’s standard handles (Windows only).
sync_directory
Makes renames into dir survive a power loss by fsyncing it on Unix. File systems that cannot sync a directory are not an error. No-op on Windows, where the rename writes through.
thread_cpu_work
The calling thread’s CPU work so far, comparable only with other readings on the same thread: CPU nanoseconds on Unix, cycles on Windows (QueryThreadCycleTime). Excludes time spent waiting for a CPU. None where unavailable.
try_lock_exclusive
Takes an exclusive advisory lock on file without waiting. Returns Ok(false) when another open handle, in this or another process, holds it.
utf8_arguments
The arguments as UTF-8 strings. Unlike std::env::args, a non-UTF-8 argument is an error, not a panic.
watch_parent
Calls the crate::on_termination handler with a PARENT_EXITED termination (status 143) when the parent process exits, or at once if it already has.
with_publish_retries
Runs step until it succeeds, fails with a non-retryable error, or retry stops it. Waits 50 ms before the first retry, doubling up to 1 s. Returns the value and the retry count.
write_diagnostic
Writes one line to standard error like eprintln!, but drops it instead of panicking when the stream is closed, so a client closing the pipe cannot abort an export. Use diagnostic!.