Os.Exit
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.
The type for specifying program exits.
exit ~on_error e
exits according to e
:
e
is Code c
, Stdlib.exit
c
is called and the function never returns.e
is Execv execv
, execv
is called. This can only return with an Error _
. In that case the error is logged and exit
is called again with on_error
(and the default on_error
)on_error
defaults to some_error
. Except if an asynchronous exception is raised this function never returns.
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.
val ok : t
ok
is Code 0
.
val no_such_name : t
no_such_name
is Code 122
, it indicates a named entity was not found.
val some_error : t
some_error
is Code 123
, it indicates an indiscriminate error reported on stdout.
val cli_error : t
cli_error
is Code 124
, it indicates a command line parsing error.
val internal_error : t
internal_error
is Code 125
, it indicates an unexpected internal error (bug).
results
val of_result : (unit, string) Stdlib.result -> t
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 _
.
execv
val execv : ?env:Env.assignments -> ?cwd:Fpath.t -> ?argv0:string -> Cmd.t -> t
exec ?env ?cwd ?argv0 cmd
is an Exec _
. That has a call to Os.Cmd.execv
with the corresponding arguments.
val execv_env : execv -> Env.assignments option
execv_env exec
is the environment of exec
.
val execv_argv0 : execv -> string option
execv_env exec
is the environment of exec
.
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
.