package b0
Install
dune-project
Dependency
Authors
Maintainers
Sources
sha512=e9aa779e66c08fc763019f16d4706f465d16c05d6400b58fbd0313317ef33ddea51952e2b058db28e65f7ddb7012f328c8bf02d8f1da17bb543348541a2587f0
doc/b0.std/B0_std/Os/Exit/index.html
Module Os.ExitSource
Program exit.
There are two ways for a program to exit: either by returning an exit code or by calling B0_std.Os.Cmd.execv. The type here allows to represent these two ways of exiting.
Program exits
The type for exit codes.
The type for execv calls.
The type for specifying program exits.
get_code e is the exit code of e. Raises Invalid_argument if e is Execv.
exit ~on_error e exits according to e:
- If
eisCode c,Stdlib.exitcis called and the function never returns. - If
eisExecv execv,execvis called. This can only return with anError _. In that case the error is logged andexitis called again withon_error(and the defaulton_error)
on_error defaults to some_error. Except if an asynchronous exception is raised this function never returns.
Exiting with codes
Note. The constants here match those established by Cmdliner with another one useful in cli tools. But we don't want a Cmdliner dependency on it here.
some_error is Code 123, it indicates an indiscriminate error reported on stdout.
internal_error is Code 125, it indicates an unexpected internal error (bug).
Exit with results
of_result v exits with ok if v is Ok () and logs the Error and exits with some_error if v is Error _.
of_result v exits with e if v is Ok e and logs the error and exits with some_error if v is Error _.
Exit by execv
exec ?env ?cwd ?argv0 cmd is an Exec _. That has a call to Os.Cmd.execv with the corresponding arguments.
execv_env exec is the environment of exec.
Signal exit hooks
on_sigint ~hook f calls f () and returns its value. If SIGINT is signalled during that time hook is called followed by exit 130 – that is the exit code a SIGINT would produce.
on_sigint replaces an existing signal handler for Sys.sigint during time of the function call. It is restored when the function returns.
Note. Since Stdlib.exit is called Stdlib.at_exit functions are called if a SIGINT occurs during the call to f. This is not the case on an unhandled SIGINT.