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.

In iOS and Android apps the system owns the process, so the termination, parent-exit and child-lifetime calls have no use there; files, clocks, memory and the version do.

Macros§

diagnostic
eprintln! through the process’s diagnostic sink (write_diagnostic).

Structs§

AwakeInstant
A point on a clock that stops while the system sleeps, so stall checks ignore suspend.
CgroupMemory
The lowest memory limit on this process’s cgroup path and what is charged against it.
CgroupMemoryWatch
Reads CgroupMemory repeatedly for a watch, finding the lowest limit’s level again after a failed read. Below Self::STAT_FROM_PERCENT of the limit the working set is the charge.
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_memory
CgroupMemory of this process, read now; None without a cgroup memory limit.
cgroup_memory_at
cgroup_memory with root standing in for /. Levels without a limit (max, or v1’s near-u64::MAX default) are skipped; v2 is read first.
claim_stdout
Takes standard output for a protocol stream.
create_private_directory
Creates path and its missing parents for files only this user may change.
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.
host_cache_directory
The host’s cache directory, as the Node and Python clients name it, or None without a home.
host_cache_directory_from
host_cache_directory with the environment read through variable.
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.
open_file_limit
The soft limit on open file descriptors; None on Windows or where unlimited or unknown.
open_handles
Handles the process holds open: file descriptors on Unix, kernel handles on Windows. None where unavailable.
os_version
The OS version, read once: 27.0.1 (26A434) on macOS and iOS, Ubuntu 22.04.5 LTS, kernel 6.8.0 on Linux, Android 16 (API 36), kernel 6.1.0 on Android, 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 Apple systems, 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.
set_diagnostic_sink
Sends every later diagnostic line of the process to sink, or with None back to standard error, or on Android, which discards an app’s standard error, to the system log as alpha2.
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 diagnostic line to the sink set_diagnostic_sink chose. The default output drops the line instead of panicking when standard error is closed, so a client closing the pipe cannot abort an export. Use diagnostic!.

Type Aliases§

DiagnosticSink
Receives each diagnostic line in place of the default output.