package b0

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Program exit.

Specifying exits

type t =
  1. | Code : int -> t
    (*

    exit with code.

    *)
  2. | Exec : (unit -> ('a, string) result) -> t
    (*

    exit with execv

    *)

The type for specifying program exits. Either an exit code or a function (should be) calling B00_std.Cmd.execv.

val code : int -> t

code c is Code c.

val exec : ?env:Env.assignments -> ?cwd:Fpath.t -> Fpath.t -> Cmd.t -> t

exec ?env ?cwd file argv is an Exec _. That has a call to Os.Cmd.execv with the corresponding arguments.

val get_code : t -> int

get_code e is the exit code of e. Raises Invalid_argument if e is Exec.

Exiting exits

val exit : t -> ('a, string) result

exit e exits according to e:

  • If e is Code c, Stdlib.exit c is called and the function never returns.
  • If e is Exec execv, execv is called. This can only return with an Error _. In that case log it and call the function again with an error code - this guarantees termination.

Signal exit hooks

val on_sigint : hook:(unit -> unit) -> (unit -> 'a) -> 'a

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.

OCaml

Innovation. Community. Security.