/// The operating system around the program. import std/process.{type Subject, type proc} /// The value of environment variable `name`, if it is set (and valid /// UTF-8). pub fn env :: name: String -> Option / { let found = env_raw name if found.0 { Some(found.1) } else { None } } @extern c "tl_os_env" fn env_raw :: name: String -> (Bool, String) / /// The process's command-line arguments, the program's name (as invoked, /// not necessarily a path) first. @extern c "tl_os_args" pub fn args :: -> List / /// End the process with exit `code` (0 is success), after everything /// printed so far is written. Never returns. @extern c "tl_os_exit" pub fn exit :: code: Int -> Never / /// A signal the operating system sends the program (ADR 0060). pub type Signal { /// SIGTERM: stop (`kill`, `podman stop`, Kubernetes). Term /// SIGINT: stop, from the terminal (Ctrl-C). , Interrupt /// SIGHUP: the terminal went away; daemons often take it as "reload". , Hangup } /// From now on, the signals of `which` arrive as messages on the returned /// subject, owned by the calling actor, instead of ending the program: /// receive `Term` to clean up and stop. Without a subscription, a signal /// ends the program at once with status 128 + its number (143 for /// SIGTERM), even as PID 1 in a container. Several actors may subscribe; /// each gets every signal it asked for. The interpreter accepts the /// subscription but delivers nothing: signals need `--native`. pub fn signals :: which: List -> Subject / { let to = process.subject () subscribe (process.tag to) which to } @extern c "tl_os_signals" fn subscribe :: tag: Int which: List -> () /