
louise
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#1197 · main · 10 min 35 s
1Étoiles
0Forks
0Issues
| 1 | /// The operating system around the program. |
| 2 | |
| 3 | import std/process.{type Subject, type proc} |
| 4 | |
| 5 | /// The value of environment variable `name`, if it is set (and valid |
| 6 | /// UTF-8). |
| 7 | pub fn env :: name: String -> Option<String> / <io> |
| 8 | { |
| 9 | let found = env_raw name |
| 10 | if found.0 |
| 11 | { |
| 12 | Some(found.1) |
| 13 | } |
| 14 | else |
| 15 | { |
| 16 | None |
| 17 | } |
| 18 | } |
| 19 | |
| 20 | @extern c "tl_os_env" |
| 21 | fn env_raw :: name: String -> (Bool, String) / <io> |
| 22 | |
| 23 | /// The process's command-line arguments, the program's name (as invoked, |
| 24 | /// not necessarily a path) first. |
| 25 | @extern c "tl_os_args" |
| 26 | pub fn args :: -> List<String> / <io> |
| 27 | |
| 28 | /// End the process with exit `code` (0 is success), after everything |
| 29 | /// printed so far is written. Never returns. |
| 30 | @extern c "tl_os_exit" |
| 31 | pub fn exit :: code: Int -> Never / <io> |
| 32 | |
| 33 | /// A signal the operating system sends the program (ADR 0060). |
| 34 | pub type Signal |
| 35 | { /// SIGTERM: stop (`kill`, `podman stop`, Kubernetes). |
| 36 | Term |
| 37 | /// SIGINT: stop, from the terminal (Ctrl-C). |
| 38 | , Interrupt |
| 39 | /// SIGHUP: the terminal went away; daemons often take it as "reload". |
| 40 | , Hangup |
| 41 | } |
| 42 | |
| 43 | /// From now on, the signals of `which` arrive as messages on the returned |
| 44 | /// subject, owned by the calling actor, instead of ending the program: |
| 45 | /// receive `Term` to clean up and stop. Without a subscription, a signal |
| 46 | /// ends the program at once with status 128 + its number (143 for |
| 47 | /// SIGTERM), even as PID 1 in a container. Several actors may subscribe; |
| 48 | /// each gets every signal it asked for. The interpreter accepts the |
| 49 | /// subscription but delivers nothing: signals need `--native`. |
| 50 | pub fn signals :: which: List<Signal> -> Subject<Signal> / <proc, io> |
| 51 | { |
| 52 | let to = process.subject () |
| 53 | subscribe (process.tag to) which |
| 54 | to |
| 55 | } |
| 56 | |
| 57 | @extern c "tl_os_signals" |
| 58 | fn subscribe :: tag: Int which: List<Signal> -> () / <io> |