save history when receving a sighup

Ignore-this: 219e88bce2dafc999b6f2f73a16274bf

darcs-hash:20120215154929-c41ad-6377472357c9ff2e29abfc794ec23e988872f9d9
This commit is contained in:
Jeremie Dimino 2012-02-15 16:49:29 +01:00
parent 6aeb61432a
commit d2e0e79dd4
2 changed files with 22 additions and 1 deletions

View File

@ -18,6 +18,8 @@ open UTop_private
module String_set = Set.Make(String) module String_set = Set.Make(String)
exception Term of int
(* +-----------------------------------------------------------------+ (* +-----------------------------------------------------------------+
| History | | History |
+-----------------------------------------------------------------+ *) +-----------------------------------------------------------------+ *)
@ -688,7 +690,20 @@ let common_init () =
ignore (Toploop.use_silently Format.err_formatter fn)); ignore (Toploop.use_silently Format.err_formatter fn));
(* Load history after the initialization file so the user can change (* Load history after the initialization file so the user can change
the history file name. *) the history file name. *)
Lwt_main.run (init_history ()) Lwt_main.run (init_history ());
(* Install signal handlers. *)
let behavior = Sys.Signal_handle (fun signo -> raise (Term signo)) in
let catch signo =
try
Sys.set_signal signo behavior
with _ ->
(* All signals may not be supported on some OS. *)
()
in
(* We lost the terminal. *)
catch Sys.sighup;
(* Termination request. *)
catch Sys.sigterm
let load_inputrc () = let load_inputrc () =
try_lwt try_lwt

View File

@ -9,3 +9,9 @@
val main : unit -> unit val main : unit -> unit
(** Start utop. *) (** Start utop. *)
exception Term of int
(** Exception raised when a signal that should terminate the process
is received. The argument is the signal number.
utop raises this exception for SIGHUP and SIGTERM by default. *)